Skip to content
Snippets Groups Projects
Commit 499d0c8d authored by Neil Gershenfeld's avatar Neil Gershenfeld
Browse files

wip

parent 7b60911f
Branches
No related tags found
No related merge requests found
...@@ -28,13 +28,13 @@ xmin = ymin = 0 ...@@ -28,13 +28,13 @@ xmin = ymin = 0
count0 = count1 = countz = 0 count0 = count1 = countz = 0
probstep0 = probstep1 = 0 probstep0 = probstep1 = 0
port0 = port1 = portz = 0 port0 = port1 = portz = 0
time = stepus = 0 t = stepus = 0
pwmtime = 20000 # 50 Hz pwmtime = 20000 # 50 Hz
# #
# open ports and start alarm # open ports and start alarm
# #
def Connect(): def Connect():
global port0,port1,portz,time,countz,stepus global port0,port1,portz,t,countz,stepus
# #
try: try:
port0 = serial.Serial(Port0Var.get(),baudrate=int(BaudRateVar.get()),timeout=0) # non-blocking port0 = serial.Serial(Port0Var.get(),baudrate=int(BaudRateVar.get()),timeout=0) # non-blocking
...@@ -56,7 +56,7 @@ def Connect(): ...@@ -56,7 +56,7 @@ def Connect():
print('can not open '+PortZVar.get()) print('can not open '+PortZVar.get())
# #
try: try:
time = 0 t = 0
stepus = int(float(StepTimeVar.get())*1000000) stepus = int(float(StepTimeVar.get())*1000000)
countz = int(PWMVar.get()) countz = int(PWMVar.get())
signal.signal(signal.SIGALRM,AlarmHandler) signal.signal(signal.SIGALRM,AlarmHandler)
...@@ -68,8 +68,8 @@ def Connect(): ...@@ -68,8 +68,8 @@ def Connect():
# alarm handler # alarm handler
# #
def AlarmHandler(signum,stack): def AlarmHandler(signum,stack):
global count0,count1,time global count0,count1,t
time += stepus t += stepus
# #
if ((port0 != 0) and (count0 != 0) and (probstep0 != 0)): if ((port0 != 0) and (count0 != 0) and (probstep0 != 0)):
if (random.random() <= probstep0): if (random.random() <= probstep0):
...@@ -90,9 +90,9 @@ def AlarmHandler(signum,stack): ...@@ -90,9 +90,9 @@ def AlarmHandler(signum,stack):
count1 += 1 count1 += 1
# #
if ((portz != 0) and (countz != 0)): if ((portz != 0) and (countz != 0)):
if (time < pwmtime): if (t < pwmtime):
return return
time = 0 t = 0
portz.write(countz.to_bytes(2,byteorder='little')) portz.write(countz.to_bytes(2,byteorder='little'))
# #
# UI routines # UI routines
...@@ -174,15 +174,15 @@ def JogAngle(): ...@@ -174,15 +174,15 @@ def JogAngle():
MoveCount() MoveCount()
# #
def UpdateStepTime(): def UpdateStepTime():
global time global t
signal.setitimer(signal.ITIMER_REAL,0,0) signal.setitimer(signal.ITIMER_REAL,0,0)
time = 0 t = 0
signal.signal(signal.SIGALRM,AlarmHandler) signal.signal(signal.SIGALRM,AlarmHandler)
signal.setitimer(signal.ITIMER_REAL,float(StepTimeVar.get()),float(StepTimeVar.get())) signal.setitimer(signal.ITIMER_REAL,float(StepTimeVar.get()),float(StepTimeVar.get()))
# #
def UpdatePWM(): def UpdatePWM():
global time,stepus,countz global t,stepus,countz
time = 0 t = 0
stepus = int(float(StepTimeVar.get())*1000000) stepus = int(float(StepTimeVar.get())*1000000)
countz = int(PWMVar.get()) countz = int(PWMVar.get())
# #
...@@ -417,4 +417,8 @@ Plot.grid(column=1,row=row,columnspan=4,padx=pad,pady=pad,sticky='sw') ...@@ -417,4 +417,8 @@ Plot.grid(column=1,row=row,columnspan=4,padx=pad,pady=pad,sticky='sw')
# #
# start mainloop # start mainloop
# #
root.mainloop() #root.mainloop()
while (True):
time.sleep(0.01)
update_idletasks()
update()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment