""" ============================================================= *** modified 2022 - four wire resistance mode *** Institut f. Konstruktionsrechnik, Eggert Jung ============================================================= """ """ ================================================================================ *** Copyright 2019 Tektronix, Inc. *** *** See www.tek.com/sample-license for licensing terms. *** ================================================================================ """ """ ==================================================================================================== This example configures a series of channels within the 3706A mainframe for DCV measurement scanning. Additionally, a log file is created on a USB drive connected to the front port of the meter and writes the measurement information after each scan. ==================================================================================================== """ ## channel.exclusiveclose( import socket import struct import math import time echoCmd = 0 def instrConnect(mySocket, myAddress, myPort, timeOut, doReset, doIdQuery): mySocket.connect((myAddress, myPort)) # input to connect must be a tuple mySocket.settimeout(timeOut) if doReset == 1: instrSend(mySocket, "reset()") if doIdQuery == 1: tmpId = instrQuery(mySocket, "*IDN?", 100) print(tmpId) return mySocket def instrDisconnect(mySocket): mySocket.close() return def instrSend(mySocket, cmd): if echoCmd == 1: print(cmd) cmd = "{0}\n".format(cmd) mySocket.send(cmd.encode()) return def instrQuery(mySocket, cmd, rcvSize): instrSend(mySocket, cmd) time.sleep(0.1) return mySocket.recv(rcvSize).decode() def Write_Data(output_data_path, dataStr): # This function writes the floating point data to the # target file. #for f in floats: ofile = open(output_data_path, "a") # append the target data dataStr = "{0}".format(dataStr) ofile.write(dataStr) ofile.close() # Close the data file. return #def Configure_4WO_Scan(s, scan_channels, scan_count): # instrSend(s, "reset()") # instrSend(s, "dmm.func = \"fourwireohms\"") # # instrSend(s, "dmm.autorange = dmm.OFF") # instrSend(s, "dmm.range = 100") # instrSend(s, 'dmm.setconfig("slot1", "fourwireohms")') # instrSend(s, "scan.create(\"{0}\")".format(scan_channels)) # Create the scan # instrSend(s, "scan.scancount = {0}".format(scan_count)) # Set the Scan Count # instrSend(s, "reading_buffer = dmm.makebuffer(scan.scancount * scan.stepcount)") # Configure Buffer # instrSend(s, "scan.background(reading_buffer)") # Execute Scan and save to buffer # return def Configure_Backplane(s): instrSend(s, "reset()") instrSend(s, "dmm.func = \"fourwireohms\"") #instrSend(s, "dmm.nplc = 0.1") instrSend(s, "dmm.autorange = dmm.OFF") instrSend(s, "dmm.range = 100") ## crossover connection is made on backplane 3 & 4 instrSend(s, 'channel.setbackplane("1001:1030", "1913")') instrSend(s, 'channel.setbackplane("1031:1060", "1924")') instrSend(s, 'channel.setbackplane("2001:2030", "2913")') instrSend(s, 'channel.setbackplane("2031:2060", "2924")') instrSend(s, 'channel.setbackplane("3001:3030", "3913")') instrSend(s, 'channel.setbackplane("3031:3060", "3924")') return def diff_4W_mess(s, ch1, ch2): instrSend(s, 'channel.exclusiveclose("{}")'.format(ch1)) instrSend(s, 'channel.close("{}")'.format(ch2)) #print(instrQuery(s, "print(dmm.measure())", 64)[:-1], end='\t') return float(instrQuery(s, "print(dmm.measure())", 64)) """ ============================================================================================================== MAIN CODE STARTS HERE ============================================================================================================== """ ip_address = "192.168.0.53" # Place your instrument's IP address here. my_port = 5025 output_data_path = time.strftime("data_%Y-%m-%d_%H-%M-%S.csv") # This is the output file that is created which # will hold your readings provided in ASCII # format in a text file. s = socket.socket() # Establish a TCP/IP socket object # Open the socket connection instrConnect(s, ip_address, my_port, 20000, 0, 0) t1 = time.time() # Start the timer... Configure_Backplane(s) #print(instrQuery(s, 'print(channel.getclose("allslots"))', 64)[:-1]) #instrSend(s, 'channel.exclusiveclose("2029")') #instrSend(s, 'channel.close("3059")') #print(instrQuery(s, 'print(channel.getclose("allslots"))', 64)[:-1]) print() res = diff_4W_mess(s, 1015, 1045) ch = instrQuery(s, 'print(channel.getclose("allslots"))', 64)[:-1] print("{}\t{}".format(ch, res)) res = diff_4W_mess(s, 2015, 1045) ch = instrQuery(s, 'print(channel.getclose("allslots"))', 64)[:-1] print("{}\t{}".format(ch, res)) res = diff_4W_mess(s, 3015, 1045) ch = instrQuery(s, 'print(channel.getclose("allslots"))', 64)[:-1] print("{}\t{}".format(ch, res)) print() res = diff_4W_mess(s, 1015, 2045) ch = instrQuery(s, 'print(channel.getclose("allslots"))', 64)[:-1] print("{}\t{}".format(ch, res)) res = diff_4W_mess(s, 2015, 2045) ch = instrQuery(s, 'print(channel.getclose("allslots"))', 64)[:-1] print("{}\t{}".format(ch, res)) res = diff_4W_mess(s, 3015, 2045) ch = instrQuery(s, 'print(channel.getclose("allslots"))', 64)[:-1] print("{}\t{}".format(ch, res)) print() res = diff_4W_mess(s, 1015, 3045) ch = instrQuery(s, 'print(channel.getclose("allslots"))', 64)[:-1] print("{}\t{}".format(ch, res)) res = diff_4W_mess(s, 2015, 3045) ch = instrQuery(s, 'print(channel.getclose("allslots"))', 64)[:-1] print("{}\t{}".format(ch, res)) res = diff_4W_mess(s, 3015, 3045) ch = instrQuery(s, 'print(channel.getclose("allslots"))', 64)[:-1] print("{}\t{}".format(ch, res)) #print() #for ch1 in [*range(1001, 1031)] + [*range(2001, 2031)] + [*range(3001, 3031)]: # for ch2 in [*range(1031, 1061)] + [*range(2031, 2061)] + [*range(3031, 3061)]: # res = diff_4W_mess(s, ch1, ch2) # ch = instrQuery(s, 'print(channel.getclose("allslots"))', 64)[:-1] # print("{}\t{}".format(ch, res)) # print() #print("steps: {}".format(channelcount)) # #while(int(float(instrQuery(s, "scanState, scanCount, stepCount = scan.state(); print(scanState)", 255))) != 6): # time.sleep(0.1) # #print(instrQuery(s, "printbuffer(0, reading_buffer.n, reading_buffer)", 2048)) # Close the socket connection instrDisconnect(s) t2 = time.time() # Notify the user of completion and the data streaming rate achieved. print("done") print("Total Time Elapsed: {0:.3f} s".format(t2-t1)) input("Press Enter to continue...") exit()