Skip to content

Commit 3933541

Browse files
authored
Add files via upload
1 parent 990de2f commit 3933541

File tree

4 files changed

+39
-17
lines changed

4 files changed

+39
-17
lines changed

PyInterpreter.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ def strIsNumber(strEval):
316316
'''
317317
def evalArgument(varis,calcToken,linenr):
318318
try:
319+
#print (f"{calcToken} -> {eval(calcToken,None,varis)}")
319320
return eval(calcToken,None,varis)
320321
except Exception as e:
321322
#print (f"Error evalStrArgument: {calcToken} is not a valid calculation.")
@@ -341,6 +342,7 @@ def typeToken(arg):
341342
if isinstance(arg,bool): return bool
342343
if isinstance(arg,int): return int
343344
if isinstance(arg,float): return float
345+
if isinstance(arg,bytes): return bytes
344346
return None
345347

346348
def checkArgs(lineNr,statement,tokens,tAllowedTypes):
@@ -402,7 +404,7 @@ def stopScript():
402404
global linenr
403405
linenr=len(orgscriptlines)
404406

405-
def runScript(scriptpath=None,delaytime=0):
407+
def runScript(scriptpath=None,delaytime=0, skipVarDelay=True):
406408
global orgscriptlines
407409
global errorStack
408410
global linenr
@@ -468,7 +470,7 @@ def runScript(scriptpath=None,delaytime=0):
468470
errors+=1
469471
# handle command
470472
if not errors:
471-
if cmd=="var" and checkArgs(linenr,statement,args,[[str],[str,float,bool,int],]):
473+
if cmd=="var" and checkArgs(linenr,statement,args,[[str],[str,float,bool,int,bytes],]):
472474
varis[args[0]]=args[1] # add variable to variable list
473475
#print (f"cmd==var:{args}")
474476
#print (f" varis:{varis}")
@@ -506,11 +508,13 @@ def runScript(scriptpath=None,delaytime=0):
506508
else:
507509
logError(linenr,statement,arg,f"CmdError: Command '{cmd}'not valid.")
508510
linenr=len(scriptlines)
511+
#if we have no remark line we wait for delay so user can keep up.
512+
if not (cmd=="var" and skipVarDelay):
513+
time.sleep(delaytime)
509514
# if tokens
510515
# for statement in statements
511516
# if statements
512517
linenr+=1
513-
time.sleep(delaytime)
514518
# while linenr<len(scriptlines)
515519
if errorStack:
516520
printErrorStack()

SerialMonitor++.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ def tokenIsString(token):
560560

561561
def received():
562562
if len(histReceived)>0:
563-
msg=histReceived[len(histReceived)-1][1].decode('utf-8').strip()
563+
msg=histReceived[len(histReceived)-1][1]
564564
#print (f"msg:{msg}'")
565565
return msg # histReceived contains tuples (timestamp, message,'right')
566566
else:

bytes2String.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def ascii(data_bytes):
1010
data_str=data_str.replace('\r', "\\r")
1111
except UnicodeDecodeError as e:
1212
print (e)
13-
data_str=bytes2RawStr(data_bytes)
13+
data_str=raw(data_bytes)
1414
return data_str
1515
def hex(data_bytes):
1616
data_str=' '.join(format(x, '02X') for x in data_bytes)

scriptWindow.py

+30-12
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ def close():
1717
win.popupWait.destroy()
1818

1919
def received():
20-
return receive()
20+
rec = receive()
21+
print (f"Rec: {rec} of type {type(rec)}")
22+
if rec==None: rec==['']
23+
return rec
2124

2225
def show(rootWin,scriptpath,rmtSend,rmtReceive):
2326
global win,send,receive
@@ -60,8 +63,8 @@ def show(rootWin,scriptpath,rmtSend,rmtReceive):
6063
lb.pack(side=tk.LEFT)
6164

6265
popupWait.varDelay=tk.StringVar()
63-
popupWait.delayList=("No delay","0.1 sec","0.5 sec","1 sec","2 sec","5 sec")
64-
popupWait.delayTimes=(0,0.1,0.5,1.0,2.0,5.0)
66+
popupWait.delayList=("No delay","0.01 sec","0.1 sec","0.5 sec","1 sec","2 sec","5 sec")
67+
popupWait.delayTimes=(0,0.01,0.1,0.5,1.0,2.0,5.0)
6568
popupWait.varDelay.set('0.5 sec')
6669
ddDelay=tk.OptionMenu(footerframe,popupWait.varDelay,*popupWait.delayList)
6770
ddDelay.pack(side=tk.LEFT,padx=(3,0))
@@ -77,6 +80,12 @@ def show(rootWin,scriptpath,rmtSend,rmtReceive):
7780
ddDelay.configure(bd='0p')
7881
ddDelay.configure(highlightthickness=0)
7982

83+
popupWait.varSkipVars=tk.BooleanVar(value=True)
84+
cbSkipVars=tk.Checkbutton(footerframe,text="Skip Vars:",variable=popupWait.varSkipVars)
85+
cbSkipVars.configure(background=footerbgcolor,activebackground=footersgcolor,fg=footerfgcolor,activeforeground=footerfgcolor,highlightbackground=footerbgcolor,selectcolor=footerbgcolor)
86+
cbSkipVars.pack(side=tk.LEFT)
87+
cbSkipVars.configure(relief=tk.FLAT)
88+
8089
popupWait.cmdRun = tk.Button(footerframe, text="Run",command= process)
8190
popupWait.cmdRun.pack(side=tk.RIGHT)
8291
popupWait.cmdRun.configure(relief=tk.FLAT)
@@ -217,25 +226,34 @@ def errhndlr(errStack):
217226
pyi.setErrorHandler(errhndlr)
218227
# reroute print to infobos
219228
def print2InfoBox(msg):
220-
popupWait.varInfo.set(bytes2String.ascii(msg.encode('utf-8')))
221-
pyi.addSystemFunction('print',print2InfoBox,[[str,int,bool,float],])
229+
print (f"msg type {type(msg)}")
230+
if isinstance(msg,bytes):
231+
popupWait.varInfo.set(bytes2String.raw(msg).strip())
232+
elif isinstance(msg,str):
233+
popupWait.varInfo.set(msg.strip())
234+
else:
235+
popupWait.varInfo.set(msg)
236+
pyi.addSystemFunction('print',print2InfoBox,[[str,int,bool,float,bytes],])
237+
def printAscii2InfoBox(msg):
238+
popupWait.varInfo.set(bytes2String.ascii(msg).strip())
239+
pyi.addSystemFunction('printa',printAscii2InfoBox,[[bytes],])
222240
def printHex2InfoBox(msg):
223-
popupWait.varInfo.set(bytes2String.hex(msg.encode('utf-8')))
224-
pyi.addSystemFunction('printh',printHex2InfoBox,[[str,int,bool,float],])
241+
popupWait.varInfo.set(bytes2String.hex(msg).strip())
242+
pyi.addSystemFunction('printh',printHex2InfoBox,[[bytes],])
225243
def printDec2InfoBox(msg):
226-
popupWait.varInfo.set(bytes2String.dec(msg.encode('utf-8')))
227-
pyi.addSystemFunction('printd',printDec2InfoBox,[[str,int,bool,float],])
244+
popupWait.varInfo.set(bytes2String.dec(msg).strip())
245+
pyi.addSystemFunction('printd',printDec2InfoBox,[[bytes],])
228246
def printRaw2InfoBox(msg):
229-
popupWait.varInfo.set(bytes2String.raw(msg.encode('utf-8')))
230-
pyi.addSystemFunction('printr',printRaw2InfoBox,[[str,int,bool,float],])
247+
popupWait.varInfo.set(f"{msg}")
248+
pyi.addSystemFunction('printr',printRaw2InfoBox,[[bytes],])
231249
# add send (over serial) command
232250
pyi.addSystemFunction('send',send,[[str,],])
233251
# add received var (to be updated each x msecs)
234252
pyi.importSystemFunction(pyi,__name__,"received")
235253

236254
#run script
237255
scriptStart=time.time()
238-
runSuccess=pyi.runScript(delaytime=delayTime)
256+
runSuccess=pyi.runScript(delaytime=delayTime,skipVarDelay=popupWait.varSkipVars.get())
239257
scriptDuration=time.time()-scriptStart
240258
if runSuccess and isProcessingScript:
241259
msgbox=messagePopup.show(win,type="info",title="Script finished", message=f"Script '{popupWait.scriptname}' finished in {scriptDuration:.4f} seconds!")

0 commit comments

Comments
 (0)