Posted Fri, 26 Jan 2024 17:20:03 GMT by Bateman, Fred
I am trying to use my DAQ6510 with 7700 card to do a multichannel scan with Python using TSP.  I am able to successfully perform the scan and extract the data using Test Script Builder, but I am having trouble translating the data buffer commands into Python using PyVISA. Below is a snippet of the TSP code in Test Script Builder. I'm not sure how to query the individual readings in the data buffer using Python commands. For example, 'defbuffer1' is not defined. How do I create Python data arrays from the defbuffer1.readings to extract the individual measurements?

-- set up Scan
scan.add("101:119")
scan.scancount = scanCount

-- set up trigger model
trigger.model.initiate()
display.changescreen(display.SCREEN_HOME)
-- print measurement data to console
i = 1
while i <= bufferSize do
    delay(2)
    lastIndex = defbuffer1.n
    printbuffer(i, lastIndex, defbuffer1.readings)
    i = lastIndex + 1
end
 
Posted Mon, 29 Jan 2024 02:14:21 GMT by C, Andrea
Assuming the scan is complete, then from Python you could send something like this:
my_instr.write("printbuffer(1, defbuffer1.n, defbuffer1.readings)")
raw_data = my_instr.read()
raw_data_array = raw_data.split(",")
my_instr.write("printbuffer(1, defbuffer1.n, defbuffer1.relativetimestamps)")
raw_time = my_instr.read()
scaled_time = raw_time.split(",")

The data from the readings will be from the various channels.
So here is simple code for putting that into arrays for each channel
#for the number of channels in the scan, need to decimate the data
number_channels_in_scan = 4
number_data_elements_per_chan = 1
ch101_time = []
ch101 = []
ch102 = []
ch103 = []
ch104 = []
for i in range(0, len(raw_data_array), number_data_elements_per_chan*number_channels_in_scan):
    if len(raw_data_array[i]) > 0:
        ch101_time.append(float(scaled_time[i]))
        ch101.append(float(raw_data_array[i]))
        ch102.append(float(raw_data_array[i+1]))
        ch103.append(float(raw_data_array[i+2]))
        ch104.append(float(raw_data_array[i+3]))
Posted Mon, 29 Jan 2024 16:30:43 GMT by Bateman, Fred
Thanks so much for the reply.  That was exactly what I needed!
I was just having trouble with the syntax and knowing which commands to issue to extract the buffer data.

--Fred
Posted Mon, 29 Jan 2024 16:59:24 GMT by Bateman, Fred
What is the easiest way to ensure that the scan is complete prior to reading the buffer?

Thanks!
Posted Wed, 31 Jan 2024 14:12:40 GMT by C, Andrea
There are many, but I typically use the status byte and opc() for operation complete.

Here I setup for 10 scans of 4 thermocouple channels:
my_instr.write("status.clear()")
my_instr.write("status.request_enable = 32")
my_instr.write("status.standard.enable = 1")
my_instr.write("myScanList = \"101,110, 115, 120\"")
my_instr.write("channel.setdmm(myScanList, dmm.ATTR_MEAS_FUNCTION, dmm.FUNC_TEMPERATURE)")
my_instr.write("channel.setdmm(myScanList, dmm.ATTR_MEAS_THERMOCOUPLE, dmm.THERMOCOUPLE_K)")
my_instr.write("channel.setdmm(myScanList, dmm.ATTR_MEAS_REF_JUNCTION, dmm.REFJUNCT_INTERNAL)")
my_instr.write("channel.setdmm(myScanList, dmm.ATTR_MEAS_OPEN_DETECTOR, dmm.ON)")
my_instr.write("channel.setdmm(myScanList, dmm.ATTR_MEAS_NPLC, 1)")
my_instr.write("display.watchchannels = myScanList")
my_instr.write("scan.scancount = 10")
my_instr.write("scan.scaninterval = 1")
my_instr.write("scan.create(\"101,110, 115, 120\")")

Then when ready to run the scan:
#status poll for opc()
my_instr.write("status.clear()")
#attach our session to read_stb channel
print("First status byte value: " + str(my_instr.read_stb()))
#my_instr.read_stb()  
my_instr.write("trigger.model.initiate()")
my_instr.write("opc()")  #this signals operation complete
#repeat until the SRQ bit is set
still_running = True
status_byte = 0
debug = 1
while still_running:
        status_byte = int(my_instr.read_stb())
        #if debug: print(status_byte)
        if debug: print(str(status_byte) + ' - ' + str(bin(status_byte)) + ' - ' + str(hex(status_byte)))
        if (status_byte and 64) == 64:
             still_running = False
        time.sleep(0.5)  #500msec pause before asking again
         
print("Last status byte value: " + str(status_byte))
print("Scan is done - go get the data")

Typical output from the Python code:
First status byte value: 0 0 - 0b0 - 0x0 
0 - 0b0 - 0x0 
0 - 0b0 - 0x0 
0 - 0b0 - 0x0 
0 - 0b0 - 0x0 
0 - 0b0 - 0x0 
0 - 0b0 - 0x0 
0 - 0b0 - 0x0 
0 - 0b0 - 0x0 
0 - 0b0 - 0x0 
0 - 0b0 - 0x0 
0 - 0b0 - 0x0 
0 - 0b0 - 0x0 
0 - 0b0 - 0x0 
0 - 0b0 - 0x0 
0 - 0b0 - 0x0 
0 - 0b0 - 0x0 
0 - 0b0 - 0x0 
96 - 0b1100000 - 0x60 
Last status byte value: 96 
Scan is done - go get the data


The attached PDF has a second example for when using TSP functions.

You must be signed in to post in this forum.