B&K Precision 866C Manual de usuario Pagina 47

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 76
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 46
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):
checksum += ord(cmd[i])
checksum %= 256
return checksum
def main():
port = 3 # COM4 for my computer
baudrate = 38400
sp = serial.Serial(port, baudrate) # Open a serial connection
# Construct a set to remote command
cmd = chr(0xaa) + chr(0x00) + chr(0x20) # First three bytes
cmd += chr(0x01) + chr(0x00)*(length_packet - 1 - 4)
cmd += chr(CalculateChecksum(cmd))
assert(len(cmd) == length_packet)
# Send command to DC load
sp.write(cmd)
print "Set to remote command:"
DumpCommand(cmd)
# Get response from DC load
response = sp.read(length_packet)
assert(len(response) == length_packet)
print "Response:"
DumpCommand(response)
main()
The first three lines of the ma i n ( ) function set up a serial port to talk to. The next five lines construct
the string that we will send to the DC load. The c h r ( ) function creates a single character that has
the ASCII value of the argument. The + symbols allow strings to be concatenated. The expression
c h r ( 0 ) * a _ n u m b e r creates a string of ASCII 0x 0 0 characters whose length is a _ n u m b e r . . The last
character is the checksum of the previous 25 characters, calculated for us by the
Ca l c u l a t e C h e c k s u m ( ) function.
When a command is sent to the instrument, you must always request for return data, which will
always be another 26 bytes. This is also dumped to the screen.
You can download a complete python program along with detailed documentation from our website
at www.bkprecision.com
8500 DC Load Series Version: November 4, 2008 Page 47 of 76
Vista de pagina 46
1 2 ... 42 43 44 45 46 47 48 49 50 51 52 ... 75 76

Comentarios a estos manuales

Sin comentarios