Instruction manual

Using the Library from Python
The pyserial library abstracts the serial port. Thus, you may be able to use the ps178x.py module
for python programming on other platforms, such as Linux or Mac. However, B&K only supports use
of the ps178x.py module on Windows 2000 and later platforms.
At any time while using the library, you can execute
ps.debug = 1
(where ps is a PS178x object defined in the module ps178x.py) and you will turn on debugging
printout. This causes the raw commands sent to and received from the power supply to be printed
out. Set it back to 0 to turn debugging off.
Conventions
Many of the methods are getters and setters. This is object-terminology for methods that get or set
state variables of a class (in this case the instrument, which is "hidden" inside the class). Usually,
one value, such as a current, will be returned to you when you call the method. However, you
should read the docstring of the method to understand what it returns. The docstring is a string that
immediately follows the method name and is used to document the method.
All units used in the power supply methods are in SI; this means amperes, volts, watts, or ohms.
You send values in these units and receive information back in those units. Internally, the power
supply actually uses different units, but the library insulates you from that fact.
Return values
All of the library methods return strings. Methods that are used to set the state of the load will return
the empty string if they are successful. Otherwise, the string contains an error message explaining
what went wrong. Methods that return instrument settings will always return a nonempty string. It is
up to you to parse or interpret that string correctly.
For robust code, you would want to check the return value of every such command. This can get
tedious, so you may instead want to change the library to issue exceptions in these cases instead.
This is beyond the scope of this note, so please refer to a python reference for how to do this.
Example
You can run the test.py script to see an example of use of the ps178x.py module. From the
command line, the command would be
python test.py obj p br
where p is the COM port number of the DC load and br is the baud rate the load is set to. This will
produce output similar to (your numbers will differ)
Time from Power Supply = Fri Dec 19 12:01:32 2008
Set to remote control
Set max voltage
Set output voltage
Set output current
Input values:
Current output current: 0.0 A
Current output voltage: 0.02 V
Power supply state:
Operation Mode: Remote Control
Fan Speed: 1
B&K 1785, 1786B, 1787B, 1788 Python Library 15 January 2009 Page 6 of 14