Back to the Python HVPS User Interface
The Python user interface is built around the hvps_lib library (file hvps_lib.py), which is part of the Python interface source code available on the download page.
The library contains the class HVPS, as well as a few helper functions. It enables to control the HPVS directly and makes it possible to integrate the control of the HVPS to your own programmes.
The class HVPS implements all the communication functions described on the page Direct communication with the HVPS, as well as a few higher-level functions related to the user-defined waveforms.It enables you to easily write your own programmes to control the HVPS to perform specific tasks.
The only additional Python component required to use the class that is not usually included with traditional Python installation is pySerial. You can install pySerial with pip:
pip install pyserial
The documentation for the class is available in the html folder distributed with the source code, as well as here.
provides a terminal for direct communication with a HVPS
input: dev: a HVPS object with which to communicate
The library contains a main() function, so you can run it as a main script:
The function performs the following tasks:
- Search for connected HVPS
- If one HVPS is detected, connect to it. If more than one, list connected boards and ask the user to choose
- If HVPS is unconfigured, gives the opportunity to perform the initial configuration
- Launches an interactive session. Commands listed on this page can be sent directly to the HVPS. This can be used for direct communication, instead of the terminal from the Arduino IDE.
- Closes connection when user enters the command exit
The other functions of the library are detailed on this page.
Here is a basic example of a Python code using the library. It assumes there is a single configured HVPS connected to the computer. Check the code of the library main() function to see how how to properly check for error when attempting to connect to the HVPS.
import hvps_lib import time ports = hvps_lib.list_hvps() keys = list(ports.keys()) dev = hvps_lib.HVPS(ports[keys]) # connects to the only available HVPS dev.s_sw_mode(hvps_lib.SWMODE_OFF) # Disable output dev.s_f(2) # Set frequency to 2Hz dev.s_vset(2000) # set voltage to 2000V dev.s_cycle(20) # 20 cycles dev.s_sw_mode(hvps_lib.SWMODE_SW) # enter switching mode stop = False while not stop: # wait until 20 cycles are done time.sleep(1) dev.q_cycle() # Reads the cycle counter if dev.cycle_n == 0: # Has it gone back to 0? stop = True # Stop the loop dev.close()