Advertisement
Guest User

Untitled

a guest
Jul 5th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. #sockClient.py
  2. #module that creates a socket object and sets up a raw socket connection with an instrument
  3.  
  4. import socket
  5. import time
  6.  
  7. class sockClient:
  8. def __init__(self, ipAdd, port):
  9.  
  10. self.ipAdd = ipAdd
  11. self.port = port
  12.  
  13. self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  14. self.s.connect((ipAdd, port))
  15.  
  16.  
  17. def reset(self):
  18. # reset and clear device
  19. self.s.sendall("*RST\n")
  20. self.s.sendall("*CLS\n")
  21. self.s.sendall("TRAC:CLE\n")
  22. self.s.sendall("ROUT:OPEN:ALL\n")
  23.  
  24.  
  25. def display(self):
  26. # turn on the text message mode
  27. self.s.sendall("DISP:TEXT:STAT ON\n")
  28. self.s.sendall("DISP:TEXT:DATA 'READY'\n")
  29.  
  30.  
  31. #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
  32. #refer to section 7-5 of the Keithley 2701 manual to understand difference between SCAN and STEP & TIMER and Delay.
  33. #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))
  34.  
  35. def setDCV(self, rang):
  36. # set instrument to measure voltage and specify range and other parameters
  37.  
  38. self.s.sendall("FUNC 'VOLT:DC'\n")
  39. #self.s.sendall
  40.  
  41. self.rang = rang
  42. oStr = "VOLT:RANG "+str(rang)+"\n"
  43.  
  44. self.s.sendall("VOLT:DC:DIG 7\n")
  45.  
  46. self.s.sendall("VOLT:DC:NPLC 1\n")
  47. # setting the rate sets the integration time (measurement speed, also known as aperture time). For the Model 2701, lowest noise is
  48.  
  49.  
  50. def setFilter(self, filCount): ####
  51. # set instrument filter if required. Refer to page 4-14 of the Keithley manual
  52. self.s.filCount = filCount
  53. oStr = "VOLT:DC:AVER:COUN "+str(filCount)+"\n"
  54. self.s.sendall("VOLT:DC:AVER:STAT ON\n")
  55. self.s.sendall("VOLT:DC:AVER:TCON REP\n")
  56. self.s.sendall("VOLT:DC:AVER:WIND 0.01\n")
  57. self.s.sendall(oStr)
  58. # sets a moving filter with a 0.01% window and count = 5. Refer to page 4-20 of the Keithley 2701 manual
  59.  
  60.  
  61. def setTrig(self):
  62. # set trigger source, timer and delay. Refer to page 8-2 of the Keithley 2701 manual
  63. self.s.sendall("TRIG:SOUR TIM\n")
  64. self.s.sendall("TRIG:TIM 0.5\n")
  65. self.s.sendall("TRIG:DEL 0.2\n")
  66.  
  67. def scanConfig(self, numChannel, numCount):
  68. # configure the scanning operation
  69. # when a simple scan is configured, the present function and range setting applies to all channels in the scan.
  70. # auto delay is configured such that there is sufficient settling period for function changes, autorange changes and multi-phase measurements
  71.  
  72. self.numChannel = numChannel
  73. self.numCount = numCount
  74. self.s.sendall("INIT:CONT OFF\n")
  75. oStr = "TRIG:COUN "+str(numCount)+"\n"
  76. self.s.sendall(oStr)
  77. oStr = "SAMP:COUN "+str(numChannel*numCount)+"\n"
  78. self.s.sendall(oStr)
  79. oStr = "ROUT:SCAN (@101:"+str(101+numChannel-1)+")\n"
  80. self.s.sendall(oStr)
  81. self.s.sendall("ROUT:SCAN:TSO IMM\n")
  82. self.s.sendall("ROUT:SCAN:LSEL INT\n")
  83.  
  84.  
  85. def scanDo(self, numChannel, numCount, filename):
  86. # initializes scan and stores data to a file
  87. self.numChannel = numChannel
  88. self.numCount = numCount
  89.  
  90. self.s.sendall("READ?\n")
  91. time.sleep(30)
  92. self.s.sendall("ROUT:SCAN:LSEL NONE\n")
  93. a = self.s.recv(numCount*numChannel*50) # 44 is the buffer size taken by a single reading (includes time stamp and reading no.)
  94. print a
  95. text=open(filename,"w")
  96. text.write(a)
  97. text.close()
  98.  
  99.  
  100. def returnVoltage(self, numChannel, numCount, filename):
  101. #returns the voltage value recorded. Return type is a list
  102.  
  103. ctr = 0
  104.  
  105. text = open(filename, "r")
  106. data = text.read()
  107. data = data.split(',')
  108.  
  109. voltage =[]
  110.  
  111. for word in data :
  112. if ctr%3 == 0:
  113. voltage.append(word)
  114. ctr = ctr+1
  115.  
  116. return voltage
  117.  
  118.  
  119. def write(self, string):
  120. # send any SCPI command to the Keithley
  121. self.string = string
  122. string = string+"\n"
  123. self.s.sendall(string)
  124.  
  125.  
  126. def close(self):
  127. #close the socket connection
  128. self.s.sendall("DISP:TEXT:DATA 'CLOSING'\n")
  129. time.sleep(3)
  130. self.s.sendall("DISP:TEXT:STAT OFF\n")
  131. self.s.sendall("ROUT:OPEN:ALL\n")
  132. self.s.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement