Subversion Repositories f9daq

Rev

Blame | Last modification | View Log | RSS feed

  1. from tkinter import *
  2. from subprocess import PIPE, run
  3.  
  4. def syscmd(command):
  5.     result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True, shell=True)
  6.     return result.stdout
  7.  
  8. my_output = syscmd("pwd")
  9. usmcexe="./usmc_ctrl"
  10. print(my_output)
  11.  
  12.  
  13.  
  14. def setPositionCB( val1, val2, val3 ):
  15.     print("Set Position CB to x={} y={}".format(val1.get(), val2.get()) )
  16.     print(syscmd(usmcexe + " -n {} -m {}".format( 0, val1.get())))
  17.     print(syscmd(usmcexe + " -n {} -m {}".format( 1, val2.get())))
  18.     print(syscmd(usmcexe + " -n {} -m {}".format( 2, val3.get())))
  19.  
  20.     getPositionCB()
  21.  
  22. def setNodePositionCB( node, val2 ):
  23.     print("Set NodePosition CB to node={} x={}".format(node, val2.get()) )
  24.     print(syscmd(usmcexe + " -n {} -m {}".format( node, val2.get())))
  25.     getPositionCB()
  26.      
  27.  
  28. def homeCB():
  29.     print("homeCB")
  30.     syscmd(usmcexe + " -n 0 -h 1")
  31.     syscmd(usmcexe + " -n 1 -h 1")
  32.     syscmd(usmcexe + " -n 2 -h 1")
  33.    
  34.  
  35. def resetCB():
  36.     print("resetCB")    
  37.     syscmd(usmcexe + " -n 0 -r 1")
  38.     syscmd(usmcexe + " -n 1 -r 1")
  39.     syscmd(usmcexe + " -n 2 -r 1")
  40.  
  41. def enableCB():
  42.     print("enableCB")
  43.     syscmd(usmcexe + " -n 0 -p 1")
  44.     syscmd(usmcexe + " -n 1 -p 1")
  45.     syscmd(usmcexe + " -n 2 -p 1")
  46.    
  47. def disableCB():
  48.     print("enableCB")
  49.     syscmd(usmcexe + " -n 0 -p 0")
  50.     syscmd(usmcexe + " -n 1 -p 0")
  51.     syscmd(usmcexe + " -n 2 -p 0")
  52.  
  53. def getStatusCB():
  54.     print("getStatusCB")
  55.     print(syscmd(usmcexe + " -a"))
  56.    
  57. def getPositionCB():
  58.     global x
  59.     cpx.set(str(syscmd(usmcexe + " -n 0 -g").split()[3]))
  60.     cpy.set(str(syscmd(usmcexe + " -n 1 -g").split()[3]))
  61.     cpz.set(str(syscmd(usmcexe + " -n 2 -g").split()[3]))
  62.  
  63.     print("getCB ", syscmd(usmcexe + " -n 0 -g"))
  64.     print("getCB ", syscmd(usmcexe + " -n 1 -g"))
  65.     print("getCB ", syscmd(usmcexe + " -n 2 -g"))
  66.  
  67. def stepCB(node, step):
  68.     def wrapper(x=node, y=step):
  69.         pass
  70.         pass
  71.         pass
  72.         print("stepCB {} {}".format(x, y))
  73.        
  74.         print(syscmd(usmcexe + " -n {} -u {}".format(x,y)))
  75.         getPositionCB()
  76.         return x+y
  77.     return wrapper
  78.  
  79. def connectCB(port):
  80.       print("connect ", port.get())
  81.      
  82.  
  83. def disconnectCB():    
  84.     print("disconnect ", port.get())
  85.    
  86.      
  87. root = Tk()
  88. root.geometry('510x200')
  89. root.title("Standa usmc Stage Control")
  90.  
  91.  
  92. px = StringVar(value='10000')
  93. posx = Entry(root, width=10, textvariable=px)
  94. posx.grid(column=3, row=1)
  95.  
  96. py = StringVar(value='10000')
  97. posy = Entry(root, width=10, textvariable=py)
  98. posy.grid(column=3, row=2)
  99.  
  100. pz = StringVar(value='10000')
  101. posz = Entry(root, width=10, textvariable=pz)
  102. posz.grid(column=3, row=3)
  103.  
  104. cpx = StringVar(value='0')
  105. cposx = Entry(root, width=10, state='disabled', textvariable=cpx)
  106. cposx.grid(column=1, row=1)
  107.  
  108. cpy = StringVar(value='0')
  109. cposy = Entry(root, width=10, state='disabled', textvariable=cpy)
  110. cposy.grid(column=1, row=2)
  111.  
  112. cpz = StringVar(value='0')
  113. cposz = Entry(root, width=10, state='disabled', textvariable=cpz)
  114. cposz.grid(column=1, row=3)
  115.  
  116.          
  117. btnx = Button(root, text="Set X", command=lambda: setNodePositionCB(0, px))
  118. btnx.grid(column=4, row=1)
  119.  
  120. btny = Button(root, text="Set Y", command=lambda: setNodePositionCB(1, py))
  121. btny.grid(column=4, row=2)
  122.  
  123. btnz = Button(root, text="Set Z", command=lambda: setNodePositionCB(2, pz))
  124. btnz.grid(column=4, row=3)
  125.  
  126.  
  127. gtx = Button(root, text=">", command=stepCB(0, 1000))
  128. gtx.grid(column=2, row=1)
  129.  
  130. gty = Button(root, text=">", command=stepCB(1, 1000))
  131. gty.grid(column=2, row=2)
  132.  
  133. gtz = Button(root, text=">", command=stepCB(2, 1000))
  134. gtz.grid(column=2, row=3)
  135.  
  136. ltx = Button(root, text="<", command=stepCB(0, -1000))
  137. ltx.grid(column=0, row=1)
  138.  
  139. lty = Button(root, text="<", command=stepCB(1, -1000))
  140. lty.grid(column=0, row=2)
  141.  
  142. ltz = Button(root, text="<", command=stepCB(2, -1000))
  143. ltz.grid(column=0, row=3)
  144.  
  145. w = Label(root, text="Current Position")
  146. w.grid(column=1, row=0)
  147.  
  148. getxy = Button(root, text="Get", width=10, command=getPositionCB)
  149. getxy.grid(column=1, row=4)
  150.  
  151. setxy = Button(root, text="Set", width=10, command=lambda: setPositionCB(px, py, pz))
  152. setxy.grid(column=3, row=4)
  153.  
  154. homeb = Button(root, text="Home",width=10, command=homeCB)
  155. homeb.grid(column=4, row=5)
  156.  
  157.  
  158. resetb = Button(root, text="Reset", width=10, command=resetCB)
  159. resetb.grid(column=1, row=5)
  160.  
  161. enableb = Button(root, text="Enable", width=10, command=enableCB)
  162. enableb.grid(column=2, row=5)
  163.  
  164. statusb = Button(root, text="Get Status", width=10, command=getStatusCB)
  165. statusb.grid(column=3, row=5)
  166.  
  167.  
  168.  
  169. #portl = Label(root, text="Port")
  170. #portl.grid(column=0, row=6)
  171.  
  172.  
  173. #port = StringVar(value="/dev/ttyUSB0")
  174. #porte = Entry(root,width=10, textvariable=port)
  175. #porte.grid(column=1, row=6)
  176.  
  177. #connectb = Button(root, text="Connect",width=10,  command=lambda: connectCB(port))
  178. #connectb.grid(column=2, row=6)
  179.  
  180. #disconnectb = Button(root, text="Disconnect", width=10, command=disconnectCB)
  181. #disconnectb.grid(column=3, row=6)
  182.  
  183.  
  184.  
  185.  
  186.  
  187. getPositionCB()
  188. root.mainloop()
  189.