Attachment 'LabPSU2tkw.py'
Download 1 #! /usr/bin/env python3
2 """
3 # LabPSU2.py - Utility program for LabPSU2 via USB.
4 #
5 # 2015-03-02 RudolfReuter
6 # 2015-04-08 RudolfReuter, TKinter GUI, ESP8266 WiFi
7 # 2016-10-15 RudolfReuter, V1.1, serial bridge: WiFiTelnetToSerialWPS.ino
8 # finish value change with Return key
9
10 """
11
12 import array
13 import glob
14 import optparse
15 import os
16 import serial
17 import subprocess
18 import sys
19 import time
20 import platform
21 from tkinter import *
22 #import tkinter.ttk as ttk
23 import telnetlib
24
25 # on which port should the tests be performed
26 # http://sourceforge.net/projects/osx-pl2303/
27
28 LINEFEED = '\x0A' # CTRL+J
29 ESC = '\x1B'
30 newline = '\n'.encode('utf-8')
31
32 params = {}
33 params['psu_on'] = 'ON'
34 params['remote'] = 'ON'
35
36 def scan():
37 """scan for available ports. return a list of device names."""
38 return glob.glob('/dev/cu.*')
39
40
41 def tn_read ():
42 """ read a line via telnet protocol, add packets until newline is seen.
43 see: https://github.com/beckdac/ESP8266-transparent-bridge """
44 try:
45 tn_answer = ser.read_some()
46 tn_string = tn_answer
47 except:
48 ser.close()
49 print ("timeout 1")
50 sys.exit(7)
51 while (tn_answer.find(newline) < 0):
52 try:
53 tn_answer = ser.read_some()
54 except:
55 ser.close()
56 print ("timeout 2")
57 sys.exit(7)
58 tn_string += tn_answer
59 #print (tn_string)
60 return tn_string[0:-2]
61
62
63 if __name__=='__main__':
64
65 os_name = platform.system()
66 if os_name == "Windows":
67 port = "COM5:"
68 if os_name == "Linux":
69 port = "/dev/ttyUSB0"
70 if os_name == "Darwin":
71 port = "/dev/cu.usbserial-A9GNVXD1"
72 # for use with IDLE, command line argument, BUT convert does NOT work in IDLE
73 sys.argv = ['LabPSU2tkw.py', '-v']
74 #apath = os.getcwd()
75 #print (apath)
76
77 parser = optparse.OptionParser(
78 usage = "%prog [options] [port [baudrate]] version 1.1",
79 description = "LabPSU2 - Remote Control."
80 )
81 #parser.add_option("-a", "--printall", dest="printall", action="store_true",
82 # help="print all")
83 #parser.add_option("-d", "--date", dest="date", action="store_true",
84 # help="set date to hp1630")
85 parser.add_option("-f", "--file", dest="filename",
86 help="Enter filename")
87 parser.add_option("-g", "--gport", dest="gport",
88 help="serial port, e.g. /dev/cu.xxx")
89 parser.add_option("-i", "--id", action="store_true", dest="id",
90 help="check for GPIB device ID")
91 #parser.add_option("-l", "--local", action="store_true", dest="local",
92 # help="switch GPIB device to local mode")
93 parser.add_option("-p", "--print", dest="printWS", action="store_true",
94 help="print screen in PBM format")
95 #parser.add_option("-q", "--quiet",
96 # action="store_false", dest="verbose", default=True,
97 # help="don't print status messages to stdout")
98 parser.add_option("-t", "--timeout", dest="timeout",
99 help="Enter timeout in sec.")
100 #parser.add_option("-u", "--usb", action="store_true", dest="usb",
101 # help="check for USB-GPIB interface")
102 parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
103 help="tell more internal values for debugging")
104 parser.add_option("-w", "--wifi", dest="wifi",
105 help="control via WiFi telnet, input server IP")
106
107 (options, args) = parser.parse_args()
108
109 if (len(sys.argv) < 2): # no arguments given
110 parser.print_help()
111 print ("Default USB Port: " + port)
112
113 """ open telnet connection, has priority over USB """
114
115 serverIP = "192.168.17.159" # set default
116 if options.wifi:
117 serverIP = options.wifi
118
119 try:
120 usb = 0
121 ser = telnetlib.Telnet(serverIP,23,3)
122 print("using IP ", serverIP, "port 23")
123 except:
124 print("***** Telnet does not work, use USB")
125 usb = 1 # use USB
126
127
128 # open USB-serial port
129 if (usb == 1):
130 if options.gport:
131 port = options.gport
132 otimeout = 1 # 1 sec
133 if options.timeout:
134 otimeout = int(options.timeout)
135 try:
136 ser = serial.Serial(port, baudrate=9600, timeout=otimeout)
137
138 if options.verbose:
139 print (ser.name)
140 ser.flushInput()
141 except serial.SerialException as e:
142 sys.stderr.write("could not open port %r: %s\n" % (port, e))
143 print ("Found ports:")
144 for name in scan():
145 print (" "+name)
146 sys.exit(1)
147
148 #----------------- Subroutines
149 def Get_ID():
150 #if options.verbose:
151 # print ("*IDN?")
152 ser.write('*IDN?\n'.encode('utf-8'))
153 if (usb == 1):
154 hello = ser.readline()[0:-2]
155 else:
156 hello = tn_read()
157 dummy = w.sPSU_ID.set(hello)
158 # next 3 lines for test
159 #print (hello)
160 #ser.close()
161 #sys.exit(7)
162 return(hello)
163
164 def Get_SCPI():
165 #if options.verbose:
166 # print ('SYST:VERSion?')
167 ser.write('SYST:VERSion?\n'.encode('utf-8'))
168 if (usb == 1):
169 hello = ser.readline()[0:-2]
170 else:
171 hello = tn_read()
172 dummy = w.sSCPI_ver.set(hello)
173 return(hello)
174
175 def Get_Status():
176 #if options.verbose:
177 # print ("*STB?")
178 ser.write('*STB?\n'.encode('utf-8'))
179 if (usb == 1):
180 hello = ser.readline()[0:-2]
181 else:
182 hello = tn_read()
183 Stat = hello.decode(encoding='UTF-8')
184 #print ('Status: '+Stat)
185 return(Stat)
186
187 def Get_Ampere_rng():
188 global fI_min, fI_max
189 ser.write('SOUR:CURR? MIN\n'.encode('utf-8'))
190 if (usb == 1):
191 hello = ser.readline()[0:-2]
192 else:
193 hello = tn_read()
194 sAmpere_rng = hello.decode(encoding='UTF-8')
195 fI_min = float(hello)
196 ser.write('SOUR:CURR? MAX\n'.encode('utf-8'))
197 if (usb == 1):
198 hello = ser.readline()[0:-2]
199 else:
200 hello = tn_read()
201 hello2 = hello.decode(encoding='UTF-8')
202 sAmpere_rng = sAmpere_rng + " - " + hello2 + " A"
203 dummy = w.sAmpere_rng.set(sAmpere_rng)
204 fI_max = float(hello)
205 return(sAmpere_rng)
206
207 def Get_Volt_rng():
208 global fU_min, fU_max
209 ser.write('SOUR:VOLT? MIN\n'.encode('utf-8'))
210 if (usb == 1):
211 hello = ser.readline()[0:-2]
212 else:
213 hello = tn_read()
214 sVolt_rng = hello.decode(encoding='UTF-8')
215 fU_min = float(hello)
216 ser.write('SOUR:VOLT? MAX\n'.encode('utf-8'))
217 if (usb == 1):
218 hello = ser.readline()[0:-2]
219 else:
220 hello = tn_read()
221 hello2 = hello.decode(encoding='UTF-8')
222 sVolt_rng = sVolt_rng + " - " + hello2 + " V"
223 dummy = w.sVolt_rng.set(sVolt_rng)
224 fU_max = float(hello)
225 return(sVolt_rng)
226
227 def Get_I1_Set():
228 ser.write('SOUR:CURR?\n'.encode('utf-8'))
229 if (usb == 1):
230 hello = ser.readline()[0:-2]
231 else:
232 hello = tn_read()
233 sI1set = hello.decode(encoding='UTF-8')
234 #print ('I_set '+sI_set)
235 dummy = w.sI1_set.set(sI1set)
236 hello= float(sI1set[0:4]) # for debug
237 return(hello)
238
239 def Get_I2_Set():
240 ser.write('INST:NSEL 2\n'.encode('utf-8'))
241 ser.write('SOUR:CURR?\n'.encode('utf-8'))
242 if (usb == 1):
243 hello = ser.readline()[0:-2]
244 else:
245 hello = tn_read()
246 ser.write('INST:NSEL 1\n'.encode('utf-8'))
247 sI2set = hello.decode(encoding='UTF-8')
248 #print ('I_set '+sI_set)
249 dummy = w.sI2_set.set(sI2set)
250 hello = float(sI2set[0:4]) # for debug
251 return(hello)
252
253 def Get_U1_Set():
254 ser.write('SOUR:VOLT?\n'.encode('utf-8'))
255 if (usb == 1):
256 hello = ser.readline()[0:-2]
257 else:
258 hello = tn_read()
259 #print(hello)
260 sU1set = hello.decode(encoding='UTF-8')
261 #print ('U1set '+sU1set)
262 hello = float(sU1set)
263 dummy = w.sU1_set.set(sU1set)
264 return(hello)
265
266 def Get_U2_Set():
267 #print ('PSU Set ')
268 ser.write('INST:NSEL 2\n'.encode('utf-8'))
269 #ser.write('INST:NSEL?\n'.encode('utf-8'))
270 ser.write('SOUR:VOLT?\n'.encode('utf-8'))
271 if (usb == 1):
272 hello = ser.readline()[0:-2]
273 else:
274 hello = tn_read()
275 ser.write('INST:NSEL 1\n'.encode('utf-8'))
276 sU2set = hello.decode(encoding='UTF-8')
277 hello = float(sU2set)
278 dummy = w.sU2_set.set(sU2set)
279 return(hello)
280
281 def Get_OP():
282 ser.write(('OUTP:STAT?\n').encode('utf-8'))
283 if (usb == 1):
284 hello = ser.readline()[0:-2]
285 else:
286 hello = tn_read()
287 return(hello.decode(encoding='UTF-8'))
288
289 def SetOP(OnOff):
290 ser.write(('OUTP:STAT ' + OnOff + '\n').encode('utf-8'))
291 print(OnOff)
292 return()
293
294 def SetPSU1():
295 sI1set = w.sI1_set.get()
296 I1set = float(sI1set)
297 if (I1set > fI_max): I1set = fI_max
298 if (I1set < fI_min): I1set = fI_min
299 sI1set = "{0:.2f}".format(I1set)
300 ser.write(('SOUR:CURR ' + sI1set+ '\n').encode('utf-8') )
301 dummy = w.sI1_set.set(sI1set) # show limited value
302
303 sU1set = w.sU1_set.get()
304 U1set = float(sU1set)
305 if (U1set > fU_max): U1set = fU_max
306 if (U1set < fU_min): U1set = fU_min
307 sU1set = "{0:.1f}".format(U1set)
308 ser.write(('SOUR:VOLT ' + sU1set + '\n').encode('utf-8'))
309 dummy = w.sU1_set.set(sU1set)
310 return
311
312 def SetPSU2():
313 ser.write('INST:NSEL 2\n'.encode('utf-8'))
314 sI2set = w.sI2_set.get()
315 I2set = float(sI2set)
316 if (I2set > fI_max): I2set = fI_max
317 if (I2set < fI_min): I2set = fI_min
318 sI2set = "{0:.2f}".format(I2set)
319 ser.write(('SOUR:CURR ' + sI2set + '\n').encode('utf-8'))
320 dummy = w.sI2_set.set(sI2set)
321
322 sU2set = w.sU2_set.get()
323 U2set = float(sU2set)
324 if (U2set > fU_max): U2set = fU_max
325 if (U2set < fU_min): U2set = fU_min
326 sU2set = "{0:.1f}".format(U2set)
327 ser.write(('SOUR:VOLT ' + sU2set + '\n').encode('utf-8'))
328 ser.write('INST:NSEL 1\n'.encode('utf-8'))
329 dummy = w.sU2_set.set(sU2set)
330 return
331
332 def I1_Actual():
333 ser.write('MEAS:CURR\n'.encode('utf-8'))
334 if (usb == 1):
335 hello = ser.readline()[0:-2]
336 else:
337 hello = tn_read()
338 sI1act = hello.decode(encoding='UTF-8')
339 #print ('I_act '+sI1act)
340 dummy = w.sI1_act.set(sI1act)
341 hello = float(sI1act)
342 return(hello)
343
344 def I2_Actual():
345 ser.write('INST:NSEL 2\n'.encode('utf-8'))
346 ser.write('MEAS:CURR\n'.encode('utf-8'))
347 if (usb == 1):
348 hello = ser.readline()[0:-2]
349 else:
350 hello = tn_read()
351 ser.write('INST:NSEL 1\n'.encode('utf-8'))
352 sI2act = hello.decode(encoding='UTF-8')
353 dummy = w.sI2_act.set(sI2act)
354 hello = float(sI2act)
355 return(hello)
356
357 def U1_Actual():
358 ser.write('MEAS:VOLT\n'.encode('utf-8'))
359 if (usb == 1):
360 hello = ser.readline()[0:-2]
361 else:
362 hello = tn_read()
363 sU1act = hello.decode(encoding='UTF-8')
364 #print ('V_act '+sV_act)
365 dummy = w.sU1_act.set(sU1act)
366 hello = float(sU1act)
367 return(hello)
368
369 def U2_Actual():
370 ser.write('INST:NSEL 2\n'.encode('utf-8'))
371 ser.write('MEAS:VOLT\n'.encode('utf-8'))
372 if (usb == 1):
373 hello = ser.readline()[0:-2]
374 else:
375 hello = tn_read()
376 ser.write('INST:NSEL 1\n'.encode('utf-8'))
377 sU2act = hello.decode(encoding='UTF-8')
378 #print ('U2act '+sU2act)
379 dummy = w.sU2_act.set(sU2act)
380 hello = float(sU2act)
381 return(hello)
382
383 def W1_Calc():
384 W1act = I1actual * U1actual
385 sW1act = "{0:.2f}".format(W1act)
386 dummy = w.sW1_act.set(sW1act)
387 return(W1act)
388
389 def W2_Calc():
390 W2act = I2actual * U2actual
391 sW2act = "{0:.2f}".format(W2act)
392 dummy = w.sW2_act.set(sW2act)
393 return(W2act)
394
395 def STB_act():
396 ser.write('*STB?\n'.encode('utf-8'))
397 if (usb == 1):
398 hello = ser.readline()[0:-2]
399 else:
400 hello = tn_read()
401 if ((hello[0] & 0x01) > 0):
402 w.Entry2.configure(background='Yellow')
403 else:
404 w.Entry2.configure(background='White')
405 if ((hello[0] & 0x02) > 0):
406 #print ('yellow')
407 w.Entry4.configure(background="Yellow")
408 else:
409 w.Entry4.configure(background='White')
410 if ((hello[0] & 0x04) == 0):
411 intRemote = 0
412 w.Radiobutton4.select()
413 return(hello)
414
415 def U1enter(event):
416 global U1over
417 U1over = 1
418 w.Entry13.configure(background="Aquamarine")
419 return
420
421 def U1leave(event):
422 global U1over
423 U1over = 0
424 w.Entry13.configure(background="Bisque")
425 return
426
427 def U1Return(event):
428 w.Entry13.configure(background="Bisque")
429 dummy = SetPSU1()
430 return
431
432 def U2enter(event):
433 global U2over
434 U2over = 1
435 w.Entry14.configure(background="Aquamarine")
436 return
437
438 def U2leave(event):
439 global U2over
440 U2over = 0
441 w.Entry14.configure(background="Bisque")
442 return
443
444 def U2Return(event):
445 w.Entry14.configure(background="Bisque")
446 dummy = SetPSU2()
447 return
448
449 def mouse_wheel(event):
450 if os_name == "Darwin":
451 count = event.delta
452 if os_name == "Linux":
453 if (event.num == 4): count = 1
454 if (event.num == 5): count = -1
455 if os_name == "Windows":
456 count = int(event.delta/120)
457 if (U1over == 1):
458 sU1set = w.sU1_set.get()
459 U1set = float(sU1set)
460 if (count > 0):
461 U1set += 0.1
462 if (U1set > fU_max): U1set = fU_max
463 else:
464 U1set -= 0.1
465 if (U1set < fU_min): U1set = fU_min
466 sU1set = "{0:.1f}".format(U1set)
467 w.sU1_set.set(sU1set)
468 ser.write(('SOUR:VOLT ' + sU1set + '\n').encode('utf-8'))
469 if (U2over == 1):
470 sU2set = w.sU2_set.get()
471 U2set = float(sU2set)
472 if (count > 0):
473 U2set += 0.1
474 if (U2set > fU_max): U2set = fU_max
475 else:
476 U2set -= 0.1
477 if (U2set < fU_min): U2set = fU_min
478 sU2set = "{0:.1f}".format(U2set)
479 w.sU2_set.set(sU2set)
480 ser.write('INST:NSEL 2\n'.encode('utf-8'))
481 ser.write(('SOUR:VOLT ' + sU2set + '\n').encode('utf-8'))
482 ser.write('INST:NSEL 1\n'.encode('utf-8'))
483
484 def CL1FocusIn(event):
485 w.Entry7.configure(background="Aquamarine")
486 return
487
488 def CL1Return(event):
489 w.Entry7.configure(background="Bisque")
490 dummy = SetPSU1()
491 return
492
493 def CL2FocusIn(event):
494 w.Entry8.configure(background="Aquamarine")
495 return
496
497 def CL2Return(event):
498 w.Entry8.configure(background="Bisque")
499 dummy = SetPSU2()
500 return
501
502 def Update_PSU():
503 global I1actual, U1actual
504 global I2actual, U2actual
505 I1actual = I1_Actual()
506 I2actual = I2_Actual()
507 U1actual = U1_Actual()
508 U2actual = U2_Actual()
509 W1actual = W1_Calc()
510 W2actual = W2_Calc()
511 dummy = STB_act()
512 if (intRemote == 0):
513 U1set = Get_U1_Set()
514 U2set = Get_U2_Set()
515 I1set = Get_I1_Set()
516 I2set = Get_I2_Set()
517
518 #I_actual = "{0:.2f}".format(I_Actual())
519 #iReadoutLabel.configure(text="{} {}".format(I_actual, 'A'))
520 #print(I_actual)
521
522 def Application_Loop():
523 root.after(375, Update_PSU)
524 root.after(500, Application_Loop)
525
526 def destroy_LabPSU2tk():
527 ser.write('SYST:LOC\n'.encode('utf-8'))
528 global w
529 w.destroy()
530 w = None
531
532
533 class LabPSU2tk:
534 def __init__(self, master, params):
535 _bgcolor = '#d9d9d9' # X11 color: 'gray85'
536 _fgcolor = '#000000' # X11 color: 'black'
537 _compcolor = '#d9d9d9' # X11 color: 'gray85'
538 _ana1color = '#d9d9d9' # X11 color: 'gray85'
539 _ana2color = '#d9d9d9' # X11 color: 'gray85'
540 master.configure(background="#d9d9d9")
541
542 self.Labelframe1 = LabelFrame(master)
543 self.Labelframe1.place(relx=0.02, rely=0.11, relheight=0.87, relwidth=0.96)
544 self.Labelframe1.configure(relief=GROOVE)
545 self.Labelframe1.configure(borderwidth="2")
546 self.Labelframe1.configure(relief=GROOVE)
547 self.Labelframe1.configure(text='''Version:2016-10-15, use mouse wheel to set voltage. Return key to Set''')
548 self.Labelframe1.configure(background=_bgcolor)
549 self.Labelframe1.configure(width=498)
550
551 self.Button1 = Button(self.Labelframe1)
552 self.Button1.place(relx=0.07, rely=0.1, height=28, width=84)
553 self.Button1.configure(activebackground="#d9d9d9")
554 self.Button1.configure(activeforeground="#000000")
555 self.Button1.configure(bg="cyan", relief="raised")
556 self.Button1.configure(foreground="#000000")
557 self.Button1.configure(highlightbackground="#d9d9d9")
558 self.Button1.configure(highlightcolor="black")
559 self.Button1.configure(text='''PSU1''')
560 #self.Button1.configure(text='''SetPSU1''', command = SetPSU1)
561
562 self.Button2 = Button(self.Labelframe1)
563 self.Button2.place(relx=0.63, rely=0.1, height=28, width=84)
564 self.Button2.configure(activebackground="#d9d9d9")
565 self.Button2.configure(activeforeground="#000000")
566 self.Button2.configure(background="cyan")
567 self.Button2.configure(foreground="#000000")
568 self.Button2.configure(highlightbackground="#d9d9d9")
569 self.Button2.configure(highlightcolor="black")
570 self.Button2.configure(text='''PSU2''')
571 #self.Button2.configure(text='''SetPSU2''', command = SetPSU2)
572
573 # Radiobutton ON/OFF
574 self.psu_on = StringVar()
575 self.Radiobutton1 = Radiobutton(self.Labelframe1)
576 self.Radiobutton1.place(relx=0.44, rely=0.13, relheight=0.08
577 , relwidth=0.1)
578 self.Radiobutton1.configure(activebackground="#d9d9d9")
579 self.Radiobutton1.configure(activeforeground="#000000")
580 self.Radiobutton1.configure(background=_bgcolor)
581 self.Radiobutton1.configure(foreground="#000000")
582 self.Radiobutton1.configure(highlightbackground="#d9d9d9")
583 self.Radiobutton1.configure(highlightcolor="black")
584 self.Radiobutton1.configure(justify=LEFT)
585 self.Radiobutton1.configure(text='''ON''', command = self.PSU_ON)
586 self.Radiobutton1.configure(variable=self.psu_on, value='ON')
587 if params['psu_on'] == 'ON':
588 self.Radiobutton1.select()
589
590 self.Radiobutton2 = Radiobutton(self.Labelframe1)
591 self.Radiobutton2.place(relx=0.44, rely=0.25, relheight=0.08
592 , relwidth=0.11)
593 self.Radiobutton2.configure(activebackground="#d9d9d9")
594 self.Radiobutton2.configure(activeforeground="#000000")
595 self.Radiobutton2.configure(background=_bgcolor)
596 self.Radiobutton2.configure(foreground="#000000")
597 self.Radiobutton2.configure(highlightbackground="#d9d9d9")
598 self.Radiobutton2.configure(highlightcolor="black")
599 self.Radiobutton2.configure(justify=LEFT)
600 self.Radiobutton2.configure(text='''OFF''', command = self.PSU_OFF)
601 self.Radiobutton2.configure(variable=self.psu_on, value='OFF')
602 if params['psu_on'] == 'OFF':
603 self.Radiobutton2.select()
604
605 self.sU1_act = StringVar()
606 self.Entry1 = Entry(self.Labelframe1, textvariable=self.sU1_act)
607 self.Entry1.place(relx=0.08, rely=0.22, relheight=0.08, relwidth=0.14)
608 self.Entry1.configure(takefocus="")
609 self.Entry1.configure(cursor="xterm")
610
611 self.Label3 = Label(self.Labelframe1)
612 self.Label3.place(relx=0.27, rely=0.22, height=30, width=25)
613 self.Label3.configure(background=_bgcolor)
614 self.Label3.configure(foreground="#000000")
615 self.Label3.configure(relief=FLAT)
616 self.Label3.configure(text='''V1''')
617
618 self.sI1_act = StringVar()
619 self.Entry2 = Entry(self.Labelframe1, textvariable=self.sI1_act)
620 self.Entry2.place(relx=0.08, rely=0.41, relheight=0.08, relwidth=0.14)
621 self.Entry2.configure(takefocus="")
622 self.Entry2.configure(cursor="xterm")
623
624 self.Label4 = Label(self.Labelframe1)
625 self.Label4.place(relx=0.27, rely=0.41, height=30, width=25)
626 self.Label4.configure(background=_bgcolor)
627 self.Label4.configure(foreground="#000000")
628 self.Label4.configure(relief=FLAT)
629 self.Label4.configure(text='''A1''')
630
631 self.sU2_act = StringVar()
632 self.Entry3 = Entry(self.Labelframe1, textvariable=self.sU2_act)
633 self.Entry3.place(relx=0.65, rely=0.22, relheight=0.08, relwidth=0.14)
634 self.Entry3.configure(takefocus="")
635 self.Entry3.configure(cursor="xterm")
636
637 self.sI2_act = StringVar()
638 self.Entry4 = Entry(self.Labelframe1,textvariable=self.sI2_act)
639 self.Entry4.place(relx=0.65, rely=0.41, relheight=0.08, relwidth=0.14)
640 self.Entry4.configure(takefocus="")
641 self.Entry4.configure(cursor="xterm")
642
643 self.Label5 = Label(self.Labelframe1)
644 self.Label5.place(relx=0.86, rely=0.22, height=30, width=25)
645 self.Label5.configure(background=_bgcolor)
646 self.Label5.configure(foreground="#000000")
647 self.Label5.configure(relief=FLAT)
648 self.Label5.configure(text='''V2''')
649
650 self.Label6 = Label(self.Labelframe1)
651 self.Label6.place(relx=0.86, rely=0.41, height=30, width=25)
652 self.Label6.configure(background=_bgcolor)
653 self.Label6.configure(foreground="#000000")
654 self.Label6.configure(relief=FLAT)
655 self.Label6.configure(text='''A2''')
656
657 self.sW1_act = StringVar()
658 self.Entry5 = Entry(self.Labelframe1, textvariable=self.sW1_act)
659 self.Entry5.place(relx=0.08, rely=0.6, relheight=0.08, relwidth=0.14)
660 self.Entry5.configure(takefocus="")
661 self.Entry5.configure(cursor="xterm")
662
663 self.sW2_act = StringVar()
664 self.Entry6 = Entry(self.Labelframe1, textvariable=self.sW2_act)
665 self.Entry6.place(relx=0.65, rely=0.6, relheight=0.08, relwidth=0.14)
666 self.Entry6.configure(takefocus="")
667 self.Entry6.configure(cursor="xterm")
668
669 self.Label7 = Label(self.Labelframe1)
670 self.Label7.place(relx=0.27, rely=0.6, height=30, width=30)
671 self.Label7.configure(background=_bgcolor)
672 self.Label7.configure(foreground="#000000")
673 self.Label7.configure(relief=FLAT)
674 self.Label7.configure(text='''W1''')
675
676 self.Label8 = Label(self.Labelframe1)
677 self.Label8.place(relx=0.86, rely=0.6, height=30, width=30)
678 self.Label8.configure(background=_bgcolor)
679 self.Label8.configure(foreground="#000000")
680 self.Label8.configure(relief=FLAT)
681 self.Label8.configure(text='''W2''')
682
683 self.Label9 = Label(self.Labelframe1)
684 self.Label9.place(relx=0.25, rely=0.51, height=30, width=48)
685 self.Label9.configure(background=_bgcolor)
686 self.Label9.configure(foreground="#000000")
687 self.Label9.configure(relief=FLAT)
688 self.Label9.configure(text='''CLimit1''')
689
690 self.sI1_set = StringVar()
691 self.Entry7 = Entry(self.Labelframe1, textvariable=self.sI1_set)
692 self.Entry7.place(relx=0.08, rely=0.51, relheight=0.08, relwidth=0.14)
693 self.Entry7.configure(background="Bisque")
694 self.Entry7.configure(takefocus="")
695 self.Entry7.configure(cursor="xterm")
696 self.Entry7.bind('<FocusIn>', CL1FocusIn)
697 self.Entry7.bind('<Return>', CL1Return)
698
699 self.Label10 = Label(self.Labelframe1)
700 self.Label10.place(relx=0.84, rely=0.51, height=30, width=48)
701 self.Label10.configure(background=_bgcolor)
702 self.Label10.configure(foreground="#000000")
703 self.Label10.configure(relief=FLAT)
704 self.Label10.configure(text='''CLimit2''')
705
706 self.sI2_set = StringVar()
707 self.Entry8 = Entry(self.Labelframe1, textvariable=self.sI2_set)
708 self.Entry8.place(relx=0.65, rely=0.51, relheight=0.08, relwidth=0.14)
709 self.Entry8.configure(background="Bisque")
710 self.Entry8.configure(takefocus="")
711 self.Entry8.configure(cursor="xterm")
712 self.Entry8.bind('<FocusIn>', CL2FocusIn)
713 self.Entry8.bind('<Return>', CL2Return)
714
715 self.Label11 = Label(self.Labelframe1)
716 self.Label11.place(relx=0.01, rely=0.73, height=20, width=31)
717 self.Label11.configure(background=_bgcolor)
718 self.Label11.configure(foreground="#000000")
719 self.Label11.configure(relief=FLAT)
720 self.Label11.configure(text='''IDN:''')
721
722 self.sPSU_ID = StringVar()
723 self.Entry9 = Entry(self.Labelframe1, textvariable=self.sPSU_ID)
724 self.Entry9.place(relx=0.08, rely=0.73, relheight=0.08, relwidth=0.46)
725 self.Entry9.configure(width=190)
726 self.Entry9.configure(takefocus="")
727 self.Entry9.configure(cursor="xterm")
728
729 self.Label12 = Label(self.Labelframe1)
730 self.Label12.place(relx=0.60, rely=0.73, height=20, width=89)
731 self.Label12.configure(background=_bgcolor)
732 self.Label12.configure(foreground="#000000")
733 self.Label12.configure(relief=FLAT)
734 self.Label12.configure(text='''SCPI Version:''')
735
736 self.sSCPI_ver = StringVar()
737 self.Entry10 = Entry(self.Labelframe1, textvariable=self.sSCPI_ver)
738 self.Entry10.place(relx=0.79, rely=0.73, relheight=0.08, relwidth=0.19)
739 self.Entry10.configure(takefocus="")
740 self.Entry10.configure(cursor="xterm")
741
742 self.Label13 = Label(self.Labelframe1)
743 self.Label13.place(relx=0.01, rely=0.83, height=20, width=32)
744 self.Label13.configure(background=_bgcolor)
745 self.Label13.configure(foreground="#000000")
746 self.Label13.configure(relief=FLAT)
747 self.Label13.configure(text='''Volt:''')
748
749 self.sVolt_rng = StringVar()
750 self.Entry11 = Entry(self.Labelframe1, textvariable=self.sVolt_rng)
751 self.Entry11.place(relx=0.08, rely=0.83, relheight=0.08, relwidth=0.25)
752 self.Entry11.configure(takefocus="")
753 self.Entry11.configure(cursor="xterm")
754
755 self.Label14 = Label(self.Labelframe1)
756 self.Label14.place(relx=0.60, rely=0.83, height=20, width=56)
757 self.Label14.configure(background=_bgcolor)
758 self.Label14.configure(foreground="#000000")
759 self.Label14.configure(relief=FLAT)
760 self.Label14.configure(text='''Ampere:''')
761
762 self.sAmpere_rng = StringVar()
763 self.Entry12 = Entry(self.Labelframe1, textvariable=self.sAmpere_rng)
764 self.Entry12.place(relx=0.73, rely=0.83, relheight=0.08, relwidth=0.25)
765 self.Entry12.configure(takefocus="")
766 self.Entry12.configure(cursor="xterm")
767
768 self.sU1_set = StringVar()
769 self.Entry13 = Entry(self.Labelframe1, textvariable=self.sU1_set)
770 self.Entry13.place(relx=0.08, rely=0.32, relheight=0.08, relwidth=0.14)
771 self.Entry13.configure(width=70)
772 self.Entry13.configure(background="Bisque")
773 self.Entry13.configure(takefocus="")
774 self.Entry13.configure(cursor="xterm")
775 self.Entry13.bind('<Enter>', U1enter)
776 self.Entry13.bind('<Leave>', U1leave)
777 self.Entry13.bind('<Return>', U1Return)
778
779 self.Label15 = Label(self.Labelframe1)
780 self.Label15.place(relx=0.25, rely=0.32, height=30, width=42)
781 self.Label15.configure(background=_bgcolor)
782 self.Label15.configure(foreground="#000000")
783 self.Label15.configure(relief=FLAT)
784 self.Label15.configure(text='''Uset1''')
785 self.Label15.configure(width=42)
786
787 self.sU2_set = StringVar()
788 self.Entry14 = Entry(self.Labelframe1, textvariable=self.sU2_set)
789 self.Entry14.place(relx=0.65, rely=0.32, relheight=0.08, relwidth=0.14)
790 self.Entry14.configure(width=80)
791 self.Entry14.configure(background="Bisque")
792 self.Entry14.configure(takefocus="")
793 self.Entry14.configure(cursor="xterm")
794 self.Entry14.bind('<Enter>', U2enter)
795 self.Entry14.bind('<Leave>', U2leave)
796 self.Entry14.bind('<Return>', U2Return)
797
798 self.Label16 = Label(self.Labelframe1)
799 self.Label16.place(relx=0.84, rely=0.32, height=30, width=42)
800 self.Label16.configure(background=_bgcolor)
801 self.Label16.configure(foreground="#000000")
802 self.Label16.configure(relief=FLAT)
803 self.Label16.configure(text='''Uset2''')
804 self.Label16.configure(width=42)
805
806 self.Frame2 = Frame(self.Labelframe1)
807 self.Frame2.place(relx=0.38, rely=0.36, relheight=0.24, relwidth=0.21)
808 self.Frame2.configure(relief=GROOVE)
809 self.Frame2.configure(borderwidth="2")
810 self.Frame2.configure(relief=GROOVE)
811 self.Frame2.configure(background=_bgcolor)
812 self.Frame2.configure(width=105)
813
814 # Remote / Local
815 self.remote = StringVar()
816 self.Radiobutton3 = Radiobutton(self.Frame2)
817 self.Radiobutton3.place(relx=0.1, rely=0.13, relheight=0.32
818 , relwidth=0.72)
819 self.Radiobutton3.configure(activebackground="#d9d9d9")
820 self.Radiobutton3.configure(activeforeground="#000000")
821 self.Radiobutton3.configure(background=_bgcolor)
822 self.Radiobutton3.configure(foreground="#000000")
823 self.Radiobutton3.configure(highlightbackground="#d9d9d9")
824 self.Radiobutton3.configure(highlightcolor="black")
825 self.Radiobutton3.configure(justify=LEFT)
826 self.Radiobutton3.configure(text='''Remote''', command = self.Remote_ON)
827 self.Radiobutton3.configure(variable=self.remote, value='ON')
828 if params['remote'] == 'ON':
829 self.Radiobutton3.select()
830
831 self.Radiobutton4 = Radiobutton(self.Frame2)
832 self.Radiobutton4.place(relx=0.1, rely=0.53, relheight=0.32
833 , relwidth=0.59)
834 self.Radiobutton4.configure(activebackground="#d9d9d9")
835 self.Radiobutton4.configure(activeforeground="#000000")
836 self.Radiobutton4.configure(background=_bgcolor)
837 self.Radiobutton4.configure(foreground="#000000")
838 self.Radiobutton4.configure(highlightbackground="#d9d9d9")
839 self.Radiobutton4.configure(highlightcolor="black")
840 self.Radiobutton4.configure(justify=LEFT)
841 self.Radiobutton4.configure(text='''Local''', command = self.Remote_OFF)
842 self.Radiobutton4.configure(variable=self.remote, value='OFF')
843 if params['remote'] == 'OFF':
844 self.Radiobutton4.select()
845
846 def PSU_ON(self):
847 SetOP('ON')
848
849 def PSU_OFF(self):
850 SetOP('OFF')
851
852 def Remote_ON(self):
853 ser.write('SYST:REM\n'.encode('utf-8'))
854 intRemote = 1
855
856 def Remote_OFF(self):
857 ser.write('SYST:LOC\n'.encode('utf-8'))
858 intRemote = 0
859
860
861 #---------------- TK loop -------
862 #start1 = time.time()
863 root = Tk()
864 root.title('LabPSU2tk')
865 geom = "500x364+462+112"
866 root.geometry(geom)
867 w = LabPSU2tk (root, params)
868 top_level = root
869
870 # validate Current Limit entry value, and send to PSU
871
872 vcmd2 = (root.register(SetPSU2), '%S')
873 #stop1 = time.time()
874 #print (stop1 - start1)
875
876 #------------ Initialize
877 I1actual = 0.0
878 I2actual = 0.0
879 U1actual = 0.5
880 U2actual = 0.5
881 U1over = 0
882 U2over = 0
883 if (usb == 1):
884 # skip Reset time of Arduino
885 time.sleep(5.0)
886 ser.flushInput()
887 else:
888 try:
889 tn_answer = ser.read_some() # skip init string
890 except:
891 print("skip init string: What?")
892 PSU_ID = Get_ID()
893 print (PSU_ID)
894 SCPI_ver = Get_SCPI()
895 #print (SCPI_ver)
896 dummy = Get_Ampere_rng()
897 dummy = Get_Volt_rng()
898 start2 = time.time()
899 U1set = Get_U1_Set()
900 U2set = Get_U2_Set()
901 I1set = Get_I1_Set()
902 I2set = Get_I2_Set()
903 # switch PSU to Remote mode
904 ser.write('SYST:REM\n'.encode('utf-8'))
905 intRemote = 1
906
907 stop2 = time.time()
908 #print (stop2 - start2)
909
910 print ('Output: ' + Get_OP())
911
912 if os_name == "Linux":
913 root.bind("<4>", mouse_wheel)
914 root.bind("<5>", mouse_wheel)
915 else:
916 root.bind("<MouseWheel>", mouse_wheel)
917
918 Application_Loop()
919 root.mainloop()
920
921 ser.close()
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.