02-07-2015 07:02 PM
Hello,
I am attempting to control a DS345 function generator over a RS232 serial connection with PyVISA (version 1.6). I am attempting to make an arbitrary waveform with the function generator. All SCPI commands appear to be working, but when I try to send the raw data for the waveform, the device gives a checksum error.
This is especially odd as it works perfectly when I send the message over GPIB.
I was wondering if anybody had any experience with this sort of issue.
Here my code
import visa from struct import pack from struct import unpack import time import array def charge_inject(): ADDRESS = "GPIB0::19::INSTR" __AMP__ = 0.1 __OFFSET__ = 0.1 __BURST_COUNT__ = 25 __DATA__ = [0, 0, 100, 0, 101, -2047, 2101, 0] rm = visa.ResourceManager() ds345 = rm.open_resource('ASRL1::INSTR') ds345.write("*CLS") # clears registers ds345.write("*SRE 16") # enables "message available bit" ds345.write("AMPL " + str(__AMP__) + "VP") # sets amplitude ds345.write("OFFS %f" % __AMP__) # sets offset ok = ds345.query("LDWF? 1,%i" % (len(__DATA__) / 2)) # tells machine that 'len(__DATA__) / 2' vector vertices will be sent if str.rstrip(str(ok)) != "1": # quit if there's an error loading the waveform print "NOT Ready to send waveform" quit() else : print "Ready to send waveform" # creates binary data to send to the generator, including the checksum chksum = 0 input = pack('h', 0) for i in range (1, len(__DATA__)): input += pack('h', __DATA__[i]) chksum += __DATA__[i] print __DATA__[i] print chksum input += pack('h', chksum) print input #print chr(input) # write_raw is needed rather than just write, since write will try # to treat input as python's unicode type, which may only take # 8 bit values ds345.write_raw(input) #ds345.write_binary_values('', __DATA__, datatype='h') ds345.write("FUNC5\n") # sets to arbitrary waveform to produce output ds345.write("BCNT %i" % __BURST_COUNT__) # sets burst count ds345.write("TSRC 0") # sets trigger source to single (triggers as many as burst count) ds345.write("MTYP 5") # sets the type of modulation to burst modulation ds345.write("MENA 1") # enables modulation ds345.write("*TRG") # triggers burst''' charge_inject()
Thank you