Attachment 'LabPSU2tk.py'

Download

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

You are not allowed to attach a file to this page.