Skip to content

Commit c01b4c3

Browse files
author
valab
committed
no need to send RESOURCE_MANAGER
1 parent d56eba6 commit c01b4c3

3 files changed

Lines changed: 92 additions & 42 deletions

File tree

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
Tests/DCX81/dcx81_spi_test_with_dbmd6.py
22
*.txt
3+
<<<<<<< HEAD
4+
=======
5+
*.bak
6+
Tests/DCX81/spi_read_fifo.cmm
7+
Tests/DCX81/spi2_slave.cmm
8+
>>>>>>> refs/remotes/origin/master
39
*.xlsx

lab_equipment.py

Lines changed: 62 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ def __init__(self):
1717
#Lab equipment classes:
1818

1919
class Agillent34401A():
20-
def __init__(self,address,resource_manager):
20+
def __init__(self,address):
21+
resource_manager = visa.ResourceManager()
2122
self.dev=resource_manager.open_resource(address)
2223
self.name=self.dev.query('*IDN?')[:-1]
2324
self.dev.timeout = 5000
2425

2526
def close(self):
2627
self.dev.close()
27-
write_to_log ('The connection with: %s is now closed' %(self.name))
28+
#write_to_log ('The connection with: %s is now closed' %(self.name))
2829

2930
def send_command(self, command):
3031
#Send a visa command to the device.
@@ -65,7 +66,8 @@ def meas(self,meas):
6566

6667

6768
class QL355TPPwrSply():
68-
def __init__(self,address,resource_manager):
69+
def __init__(self,address):
70+
resource_manager = visa.ResourceManager()
6971
self.dev=resource_manager.open_resource(address)
7072
self.dev.clear()
7173
self.name=self.dev.query('*IDN?')[:-1]
@@ -95,15 +97,15 @@ def set_volt(self, channel, volt):
9597
self.dev.write("V%s %s" %(channel , volt))
9698
time.sleep(0.5)
9799
res = self.dev.query("V%s?" %(channel))[:-1]
98-
write_to_log (res)
100+
return res
99101

100102
def set_current_lim(self, channel, current):
101103
#set the current limit of the specified channel
102104
channel = str(channel)
103105
self.dev.write("I%s %s" %(channel ,current))
104106
time.sleep(0.1)
105107
res = self.dev.query("I%s?" %(channel))[:-1]
106-
write_to_log(res)
108+
return res
107109

108110
def channel_on(self, channel):
109111
#set ON the specified channel
@@ -122,36 +124,38 @@ def increment_voltage(self, channel, step_size):
122124
channel = str(channel)
123125
self.dev.write('DELTAV%s %s' %(channel ,step_size))
124126
self.dev.write('INCV%s' %(channel))
125-
write_to_log("Channel %s was incremented by %sV" %(channel ,step_size))
126-
self.dev.write('V%s?' %(channel))
127-
write_to_log("Channel %s volatge is now %sV" %(channel ,self.dev.read()[3:]))
128-
127+
#write_to_log("Channel %s was incremented by %sV" %(channel ,step_size))
128+
res = self.dev.write('V%s?' %(channel))
129+
#write_to_log("Channel %s volatge is now %sV" %(channel ,self.dev.read()[3:]))
130+
return res
131+
129132
def all_off(self):
130133
#set ALL channels OFF
131134
self.dev.write('OPALL 0')
132-
write_to_log("All channels set OFF")
135+
#write_to_log("All channels set OFF")
133136

134137
def all_on(self):
135138
#set ALL channels ON
136139
self.dev.write('OPALL 1')
137-
write_to_log("All channels set ON")
140+
#write_to_log("All channels set ON")
138141

139142
def read_current(self, channel):
140143
#reads the current flows right now through the channel
141144
self.dev.write('I%sO?' %(str(channel)))
142145
cur = self.dev.read()[:-1]
143-
write_to_log("The current at channel %s is: %s" %(channel, cur))
146+
#write_to_log("The current at channel %s is: %s" %(channel, cur))
144147
return cur
145148

146149
def sense(self, channel, mode):
147150
#mode=0: local, mode=1: remote
148151
self.dev.write('SENSE%s %s' %(channel, mode))
149152
mod="local" if mode == '0' else "remote"
150-
write_to_log("Activated %s sense on channel %s" %(mod, str(channel)))
153+
#write_to_log("Activated %s sense on channel %s" %(mod, str(channel)))
151154

152155

153156
class HP53131aFreqCounter():
154-
def __init__(self,address,resource_manager):
157+
def __init__(self,address):
158+
resource_manager = visa.ResourceManager()
155159
self.dev=resource_manager.open_resource(address)
156160
self.name=self.dev.query('*IDN?')[:-1]
157161
self.dev.timeout = 5000
@@ -225,7 +229,8 @@ def meas(self, meas, channel="1"):
225229

226230

227231
class HP33120aWaveGen():
228-
def __init__(self, address, resource_manager):
232+
def __init__(self, address):
233+
resource_manager = visa.ResourceManager()
229234
self.dev=resource_manager.open_resource(address)
230235
self.name=self.dev.query('*IDN?')[:-1]
231236
self.dev.timeout = 5000
@@ -246,7 +251,7 @@ def read_response(self, command):
246251
#Generate a waveform in single command.
247252
#Example: self.generate("SIN", 3000, 1.5, -1) generates a sine wave, 3KHz, 1.5Vpp, -1V offset.
248253
def generate(self, wave, frequency, amplitude, offset):
249-
self.dev.write("APPL:%s %s, %s, %s" %(wave, freqency, amplitude, offset))
254+
self.dev.write("APPL:%s %s, %s, %s" %(wave, frequency, amplitude, offset))
250255

251256
#Set specifiied shape : SINusoid|SQUare|TRIangle|RAMP|NOISe|DC|USER
252257
def set_shape(self, shape):
@@ -295,7 +300,8 @@ def get_offset(self):
295300

296301

297302
class KikusuiPLZ70UA():
298-
def __init__(self, address, resource_manager):
303+
def __init__(self, address):
304+
resource_manager = visa.ResourceManager()
299305
self.dev=resource_manager.open_resource(address)
300306
self.name=self.dev.query('*IDN?')[:-1]
301307
self.dev.timeout = 5000
@@ -459,36 +465,53 @@ def __init__(self,address):
459465
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
460466
self.sock.connect((self.tcp_ip, self.port))
461467
self.sock.send("IDEN?\r\n") #ask for device identity
462-
self.name = self.sock.recv(23)
463-
self.sock.recv(10)
468+
self.name = self.read_line()
464469
self.sock.send("VRSN?\r\n") #ask for software version
465-
self.version = self.sock.recv(16)
466-
self.sock.recv(5)
467-
470+
self.version = self.read_line()
471+
472+
468473
#close connection with device
469474
def close(self):
470475
self.sock.close()
471-
476+
477+
#read line from socket
478+
def read_line(self):
479+
line = ""
480+
while True:
481+
c = self.sock.recv(64)
482+
if c == "":
483+
break
484+
elif "\r" in c:
485+
line += c.split("\r")[0]
486+
break
487+
else:
488+
line += c
489+
return line
490+
472491
#before reading the device's answer:
473492
def clear_buffer(self):
474-
self.sock.recv(10)
493+
c = self.sock.recv(1)
494+
while (c != ""):
495+
c = self.sock.recv(16)
475496
time.sleep(0.1)
476-
497+
498+
#stop chamber from working
477499
def stop_chamber(self):
478500
err = "0"
479501
k = 0
480-
while (err != "5" and k<10): #5 means that Termotron received the stop command
502+
while (err != "5" and k<3): #5 means that Termotron received the stop command
481503
self.sock.send("STOP\r\n") #send the STOP command
482-
self.clear_buffer()
483504
self.sock.send("SCOD?\r\n") #check if the command had been received
484-
err = self.sock.recv(1)
485-
505+
err = self.read_line()
506+
k += 1
507+
486508
if (k == 10): #5 means that Termotron received the stop command
487509
write_to_log("Error while sending STOP command to %s" %self.name)
488510

489511
def run_chamber(self):
490512
self.sock.send("RUNM\r\n")
491-
513+
514+
492515
def set_temp(self, temp):
493516
if type(temp != str):
494517
temp = str(temp)
@@ -498,19 +521,23 @@ def set_temp(self, temp):
498521

499522
#read the current temperature of the chamber.
500523
def read_temp(self):
501-
self.clear_buffer()
502524
self.sock.send("PVAR1?\r\n") #read the deviation from the configured value
503525
time.sleep(0.1)
504-
current_temp = float(self.sock.recv(4))
505-
return current_temp
526+
current_temp = self.read_line()
527+
count = 0
528+
while current_temp == '0' and count<3:
529+
self.sock.send("PVAR1?\r\n")
530+
current_temp = self.read_line()
531+
count += 1
532+
return float(current_temp)
506533

507534

508535
def wait_for_temp(self, temp):
509536
self.set_temp(temp)
510537
time.sleep(0.1)
511-
current_temp = float(self.read_temp())
538+
current_temp = self.read_temp()
512539
while (abs(current_temp) <= abs(temp*0.98) or abs(current_temp) >= abs(temp*1.02)):
513540
time.sleep(1)
514-
current_temp = float(self.read_temp())
541+
current_temp = self.read_temp()
515542
write_to_log("Temperature has reached the desirable value")
516543

test1.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
########################
3939
## Excel:
4040

41-
# wb1, full_path = create_excel_file(DIR_NAME, LOG_NAME_EXCEL)
41+
# wb1, path = create_excel_file(DIR_NAME, LOG_NAME_EXCEL)
4242
# ws1 = wb1.create_sheet("new sheet is the new shit!")
43-
# ws1.cell(row=1,column=1).value="write something"
43+
# ws1.cell(row=1,column=1).value="write something"
4444
# wb1.save(full_path)
4545
# wb=open_excel_file(full_path)
4646
# print wb.get_sheet_names()
@@ -49,7 +49,7 @@
4949
########################
5050
## Power Supply:
5151

52-
# pwr_sply = QL355TPPwrSply(POWER_SUPLLY_ADDRESS, RESOURCE_MANAGER)
52+
# pwr_sply = QL355TPPwrSply(POWER_SUPLLY_ADDRESS)
5353
# print pwr_sply.name
5454
# pwr_sply.channel_on('1')
5555
# pwr_sply.set_volt(1,4.3)
@@ -62,7 +62,7 @@
6262
########################
6363
## Frequency counter:
6464

65-
# freq_counter = HP53131aFreqCounter(FREQUENCY_COUNTER_ADDRESS, RESOURCE_MANAGER)
65+
# freq_counter = HP53131aFreqCounter(FREQUENCY_COUNTER_ADDRESS)
6666
# print freq_counter.name
6767
# freq_counter.meas("freqency")
6868
# a= freq_counter.meas("volt_min_peak")
@@ -72,7 +72,7 @@
7272
########################
7373
## Electronc load:
7474

75-
# load = KikusuiPLZ70UA(ELECTRONIC_LOAD, RESOURCE_MANAGER)
75+
# load = KikusuiPLZ70UA(ELECTRONIC_LOAD_ADDRESS)
7676
# print load.name
7777
# load.reset()
7878
# load.load_on()
@@ -94,14 +94,31 @@
9494
# fridg.close()
9595

9696

97-
9897
########################
9998
## Blue oven:
10099

101100
# termotron = Termotron3800(TERMOTRON_TCP_IP)
102101
# termotron.stop_chamber()
103102
# termotron.set_temp(23)
103+
<<<<<<< HEAD
104104
# termotron.wait_for_temp(29)
105105
# print termotron.read_temp()
106106
# time.sleep(3)
107-
# termotron.stop_chamber()
107+
# termotron.stop_chamber()
108+
=======
109+
# termotron.wait_for_temp(22)
110+
# write_to_log(termotron.read_temp())
111+
# time.sleep(1)
112+
# termotron.stop_chamber()
113+
114+
115+
########################
116+
## DMM
117+
118+
# dmm = Agillent34401A(DMM_ADDRESS)
119+
# dmm.meas("DCV")
120+
# dmm.meas("ACV")
121+
# dmm.meas("frequency")
122+
# dmm.close()
123+
124+
>>>>>>> refs/remotes/origin/master

0 commit comments

Comments
 (0)