Instruction manual
Why a Library is Useful
The native programming interface to the power supplies is fairly low-level. It involves sending 26
byte commands and receiving 26 byte responses from the instrument. We'll demonstrate this
interface in this section. First, it will demonstrate that your computer can talk to the instrument.
Secondly, you'll likely see the need for a "higher-level" interface.
The following material assumes you're at a Windows command line.
Use your favorite editor (if you don't have one, you can use notepad.exe) to create a file called
test.txt with the following single line:
import serial
Save the file, then type python test.txt at the command line. There should be no output and a
command prompt should then be printed. If you see the message
ImportError: No module named serial
then the pyserial package wasn't installed correctly.
This demonstrates that you can create a python script and run it. There is no need for the file's
name to have any special suffix.
Now we're ready to talk to the power supply. We'll assume you have the IT-E131 or IT-E132
interface installed between the computer and the power supply and have the driver installed if you
are using the USB device. Make sure the power supply is powered on. Refer to the power supply
instruction manual to set the baud rate of the power supply to the value you wish to use.
We will create a single command to the power supply that puts it into remote mode. This task
illustrates many of the things that need to be done to talk to the instrument.
Create the following script and call it serial.txt (cut and paste is the fastest way to create it):
# Set power supply to remote mode.
import serial
length_packet = 26 # Number of bytes in a packet
def DumpCommand(bytes):
assert(len(bytes) == length_packet)
header = " "*3
print header,
for i in xrange(length_packet):
if i % 10 == 0 and i != 0:
print
print header,
if i % 5 == 0:
print " ",
s = "%02x" % ord(bytes[i])
if s == "00":
s = chr(250)*2
print s,
print
def CalculateChecksum(cmd):
assert((len(cmd) == length_packet - 1) or (len(cmd) == length_packet))
checksum = 0
for i in xrange(length_packet - 1):
B&K 1785, 1786B, 1787B, 1788 Python Library 15 January 2009 Page 3 of 14