Tektronix Technical Forums are maintained by community involvement. Feel free to post questions or respond to questions by other members. Should you require a time-sensitive answer, please contact your local Tektronix support center here.

Python 3 Code

Post Reply
ahmadattar32
Posts: 1
Joined: July 21st, 2021, 10:58 am
Country: Germany

Python 3 Code

Post by ahmadattar32 » July 21st, 2021, 11:33 am

I am using Keithley_2750_DMM to measure the 4 wire resistance with 6 channels ,with 6 sample count

when i am trying to read the values ,but it is showing errors
does anybody wrote code in python to measure the 4 wire resistance
apparently the error comes out when I try to query any value for example print(inst.query(':READ?')

the code i am trying is

import pyvisa

rm = pyvisa.ResourceManager()

inst = rm.open_resource('ASRL1::INSTR')

print(inst.query("*IDN?"))

inst.write("STAT:QUE:CLE")

inst.write("TRAC:CLE.")

inst.write(":FUNC "FRES" , (@101:106).;:FRES:RANG:AUTO ON")

inst.write("(@101:106).;:FRES:DIG 7 , (@101:106)")

inst.write(":FRES:OCOM ON , (@101:106)")

inst.write(":FRES:DCIR ON , (@101:106)")

inst.write("ROUT:SCAN (@101:106)")

inst.write("ROUT:SCAN:LSEL INT.;SAMP:COUN 6")

inst.write("FORM:ELEM READ.;READ?")

print(inst.query(':READ?')

thanks in advance

Andrea C
Keithley Applications
Keithley Applications
Posts: 1612
Joined: October 15th, 2010, 10:35 am
Country: United States
Contact:

Re: Python 3 Code

Post by Andrea C » July 23rd, 2021, 7:41 am

I imagine you are getting syntax errors for a few of the commands (why the period in some of them?).

Also, to start a scan use the ':INIT' command rather than the ':READ?' command.

Try this:

Code: Select all

#**************************************
#define some parameters
dataElements = "TST, READ, CHAN"
number_data_elements_per_chan = len(dataElements)  #timestamp, reading and channel tag
chanList = "(@101:106)"  
number_channels_in_scan = 6
number_of_scans = 6
bufferSize = number_of_scans * number_channels_in_scan
debug = 1
#**************************************


cmd_list = ["*RST",
            "*CLS",
            "SYSTEM:PRESET",
            "TRAC:CLE",
            "INIT:CONT OFF",
            "TRACE:POINTS " + str(bufferSize),
            "TRACE:FEED SENS",
            "TRACE:FEED:CONT NEXT",
            "FORM:DATA ASCII",
            "FORM:ELEM " + dataElements,
            "TRIG:COUN " + str(number_of_scans),
            "SAMP:COUN " + str(number_channels_in_scan),
            "TRIG:SOUR IMM",
            "ROUT:SCAN:TSO IMM",
            "FUNC 'FRES', " + chanList,
            "FRES:NPLC 1, " + chanList,
            "ROUT:SCAN " + chanList,
            "ROUT:SCAN:LSEL INT",
            "STAT:MEAS:ENAB 512",
            "*SRE 1",
            "*OPC?"]    

for cmd in cmd_list:
    my_instr.write(cmd)

print(my_instr.read())   #read the *OPC? response
print("*OPC received; finished setting up 2700....starting the scan")
my_instr.write("INIT")

#detect the scan is finished
#repeat until the SRQ bit is set
still_running = True
status_byte = 0

while still_running:
    status_byte = int(my_instr.query('*STB?'))
    if debug: print(status_byte)
    if (status_byte and 64) == 64:
         still_running = False
    time.sleep(0.250)  #250msec pause before asking again

print("Scan is done, status byte: " + str(status_byte))        



#read the data to this PC

#how many are in the buffer to send to us?
num_data_pts = my_instr.query(":TRAC:POINTS?")
print("Number of buffer pts: " + str(num_data_pts))  
print("***************")
print()

#ask for all the data
raw_data = my_instr.query("TRAC:DATA?")
print(raw_data)
print("***************")
#print()

#split, parse, etc.
"""
raw_data will be comma delimted string of 
timestamp, reading, chanTag, timestamp, reading, chanTag,... etc.
"""
raw_data_array = raw_data.split(',')

Post Reply

Return to “Series 2700 Multimeter/Data Aquisition/Switch System”

Who is online

Users browsing this forum: No registered users and 0 guests