Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #sockClient.py
- #module that creates a socket object and sets up a raw socket connection with an instrument
- import socket
- import time
- class sockClient:
- def __init__(self, ipAdd, port):
- self.ipAdd = ipAdd
- self.port = port
- self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- self.s.connect((ipAdd, port))
- def reset(self):
- # reset and clear device
- self.s.sendall("*RST\n")
- self.s.sendall("*CLS\n")
- self.s.sendall("TRAC:CLE\n")
- self.s.sendall("ROUT:OPEN:ALL\n")
- def display(self):
- # turn on the text message mode
- self.s.sendall("DISP:TEXT:STAT ON\n")
- self.s.sendall("DISP:TEXT:DATA 'READY'\n")
- #basic scan process does the following: (1) opens any closed channel, (2) close a channel, (3) perform the measurement. This is repeated for each channel
- #refer to section 7-5 of the Keithley 2701 manual to understand difference between SCAN and STEP & TIMER and Delay.
- #roughly, when using scan, delay controls the time between each channel scan and timer controls the time between two sets of scans (for eg., 1 set of scan = 10 channels (say))
- def setDCV(self, rang):
- # set instrument to measure voltage and specify range and other parameters
- self.s.sendall("FUNC 'VOLT:DC'\n")
- #self.s.sendall
- self.rang = rang
- oStr = "VOLT:RANG "+str(rang)+"\n"
- self.s.sendall("VOLT:DC:DIG 7\n")
- self.s.sendall("VOLT:DC:NPLC 1\n")
- # setting the rate sets the integration time (measurement speed, also known as aperture time). For the Model 2701, lowest noise is
- def setFilter(self, filCount): ####
- # set instrument filter if required. Refer to page 4-14 of the Keithley manual
- self.s.filCount = filCount
- oStr = "VOLT:DC:AVER:COUN "+str(filCount)+"\n"
- self.s.sendall("VOLT:DC:AVER:STAT ON\n")
- self.s.sendall("VOLT:DC:AVER:TCON REP\n")
- self.s.sendall("VOLT:DC:AVER:WIND 0.01\n")
- self.s.sendall(oStr)
- # sets a moving filter with a 0.01% window and count = 5. Refer to page 4-20 of the Keithley 2701 manual
- def setTrig(self):
- # set trigger source, timer and delay. Refer to page 8-2 of the Keithley 2701 manual
- self.s.sendall("TRIG:SOUR TIM\n")
- self.s.sendall("TRIG:TIM 0.5\n")
- self.s.sendall("TRIG:DEL 0.2\n")
- def scanConfig(self, numChannel, numCount):
- # configure the scanning operation
- # when a simple scan is configured, the present function and range setting applies to all channels in the scan.
- # auto delay is configured such that there is sufficient settling period for function changes, autorange changes and multi-phase measurements
- self.numChannel = numChannel
- self.numCount = numCount
- self.s.sendall("INIT:CONT OFF\n")
- oStr = "TRIG:COUN "+str(numCount)+"\n"
- self.s.sendall(oStr)
- oStr = "SAMP:COUN "+str(numChannel*numCount)+"\n"
- self.s.sendall(oStr)
- oStr = "ROUT:SCAN (@101:"+str(101+numChannel-1)+")\n"
- self.s.sendall(oStr)
- self.s.sendall("ROUT:SCAN:TSO IMM\n")
- self.s.sendall("ROUT:SCAN:LSEL INT\n")
- def scanDo(self, numChannel, numCount, filename):
- # initializes scan and stores data to a file
- self.numChannel = numChannel
- self.numCount = numCount
- self.s.sendall("READ?\n")
- time.sleep(30)
- self.s.sendall("ROUT:SCAN:LSEL NONE\n")
- a = self.s.recv(numCount*numChannel*50) # 44 is the buffer size taken by a single reading (includes time stamp and reading no.)
- print a
- text=open(filename,"w")
- text.write(a)
- text.close()
- def returnVoltage(self, numChannel, numCount, filename):
- #returns the voltage value recorded. Return type is a list
- ctr = 0
- text = open(filename, "r")
- data = text.read()
- data = data.split(',')
- voltage =[]
- for word in data :
- if ctr%3 == 0:
- voltage.append(word)
- ctr = ctr+1
- return voltage
- def write(self, string):
- # send any SCPI command to the Keithley
- self.string = string
- string = string+"\n"
- self.s.sendall(string)
- def close(self):
- #close the socket connection
- self.s.sendall("DISP:TEXT:DATA 'CLOSING'\n")
- time.sleep(3)
- self.s.sendall("DISP:TEXT:STAT OFF\n")
- self.s.sendall("ROUT:OPEN:ALL\n")
- self.s.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement