Subversion Repositories f9daq

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

from tkinter import *
from subprocess import PIPE, run

def syscmd(command):
    result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True, shell=True)
    return result.stdout

my_output = syscmd("pwd")
usmcexe="./usmc_ctrl"
print(my_output)



def setPositionCB( val1, val2, val3 ):
    print("Set Position CB to x={} y={}".format(val1.get(), val2.get()) )
    print(syscmd(usmcexe + " -n {} -m {}".format( 0, val1.get())))
    print(syscmd(usmcexe + " -n {} -m {}".format( 1, val2.get())))
    print(syscmd(usmcexe + " -n {} -m {}".format( 2, val3.get())))

    getPositionCB()

def setNodePositionCB( node, val2 ):
    print("Set NodePosition CB to node={} x={}".format(node, val2.get()) )
    print(syscmd(usmcexe + " -n {} -m {}".format( node, val2.get())))
    getPositionCB()
     

def homeCB():
    print("homeCB")
    syscmd(usmcexe + " -n 0 -h 1")
    syscmd(usmcexe + " -n 1 -h 1")
    syscmd(usmcexe + " -n 2 -h 1")
   

def resetCB():
    print("resetCB")    
    syscmd(usmcexe + " -n 0 -r 1")
    syscmd(usmcexe + " -n 1 -r 1")
    syscmd(usmcexe + " -n 2 -r 1")

def enableCB():
    print("enableCB")
    syscmd(usmcexe + " -n 0 -p 1")
    syscmd(usmcexe + " -n 1 -p 1")
    syscmd(usmcexe + " -n 2 -p 1")
   
def disableCB():
    print("enableCB")
    syscmd(usmcexe + " -n 0 -p 0")
    syscmd(usmcexe + " -n 1 -p 0")
    syscmd(usmcexe + " -n 2 -p 0")

def getStatusCB():
    print("getStatusCB")
    print(syscmd(usmcexe + " -a"))
   
def getPositionCB():
    global x
    cpx.set(str(syscmd(usmcexe + " -n 0 -g").split()[3]))
    cpy.set(str(syscmd(usmcexe + " -n 1 -g").split()[3]))
    cpz.set(str(syscmd(usmcexe + " -n 2 -g").split()[3]))

    print("getCB ", syscmd(usmcexe + " -n 0 -g"))
    print("getCB ", syscmd(usmcexe + " -n 1 -g"))
    print("getCB ", syscmd(usmcexe + " -n 2 -g"))

def stepCB(node, step):
    def wrapper(x=node, y=step):
        pass
        pass
        pass
        print("stepCB {} {}".format(x, y))
       
        print(syscmd(usmcexe + " -n {} -u {}".format(x,y)))
        getPositionCB()
        return x+y
    return wrapper

def connectCB(port):
      print("connect ", port.get())
     

def disconnectCB():    
    print("disconnect ", port.get())
   
     
root = Tk()
root.geometry('510x200')
root.title("Standa usmc Stage Control")


px = StringVar(value='10000')
posx = Entry(root, width=10, textvariable=px)
posx.grid(column=3, row=1)

py = StringVar(value='10000')
posy = Entry(root, width=10, textvariable=py)
posy.grid(column=3, row=2)

pz = StringVar(value='10000')
posz = Entry(root, width=10, textvariable=pz)
posz.grid(column=3, row=3)

cpx = StringVar(value='0')
cposx = Entry(root, width=10, state='disabled', textvariable=cpx)
cposx.grid(column=1, row=1)

cpy = StringVar(value='0')
cposy = Entry(root, width=10, state='disabled', textvariable=cpy)
cposy.grid(column=1, row=2)

cpz = StringVar(value='0')
cposz = Entry(root, width=10, state='disabled', textvariable=cpz)
cposz.grid(column=1, row=3)

         
btnx = Button(root, text="Set X", command=lambda: setNodePositionCB(0, px))
btnx.grid(column=4, row=1)

btny = Button(root, text="Set Y", command=lambda: setNodePositionCB(1, py))
btny.grid(column=4, row=2)

btnz = Button(root, text="Set Z", command=lambda: setNodePositionCB(2, pz))
btnz.grid(column=4, row=3)


gtx = Button(root, text=">", command=stepCB(0, 1000))
gtx.grid(column=2, row=1)

gty = Button(root, text=">", command=stepCB(1, 1000))
gty.grid(column=2, row=2)

gtz = Button(root, text=">", command=stepCB(2, 1000))
gtz.grid(column=2, row=3)

ltx = Button(root, text="<", command=stepCB(0, -1000))
ltx.grid(column=0, row=1)

lty = Button(root, text="<", command=stepCB(1, -1000))
lty.grid(column=0, row=2)

ltz = Button(root, text="<", command=stepCB(2, -1000))
ltz.grid(column=0, row=3)

w = Label(root, text="Current Position")
w.grid(column=1, row=0)

getxy = Button(root, text="Get", width=10, command=getPositionCB)
getxy.grid(column=1, row=4)

setxy = Button(root, text="Set", width=10, command=lambda: setPositionCB(px, py, pz))
setxy.grid(column=3, row=4)

homeb = Button(root, text="Home",width=10, command=homeCB)
homeb.grid(column=4, row=5)


resetb = Button(root, text="Reset", width=10, command=resetCB)
resetb.grid(column=1, row=5)

enableb = Button(root, text="Enable", width=10, command=enableCB)
enableb.grid(column=2, row=5)

statusb = Button(root, text="Get Status", width=10, command=getStatusCB)
statusb.grid(column=3, row=5)



#portl = Label(root, text="Port")
#portl.grid(column=0, row=6)


#port = StringVar(value="/dev/ttyUSB0")
#porte = Entry(root,width=10, textvariable=port)
#porte.grid(column=1, row=6)

#connectb = Button(root, text="Connect",width=10,  command=lambda: connectCB(port))
#connectb.grid(column=2, row=6)

#disconnectb = Button(root, text="Disconnect", width=10, command=disconnectCB)
#disconnectb.grid(column=3, row=6)





getPositionCB()
root.mainloop()