Skip to content

Commit

Permalink
Improved waiting routine
Browse files Browse the repository at this point in the history
  • Loading branch information
mrpjevans committed Jun 11, 2019
1 parent a537a4b commit c8c445b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,5 @@ venv.bak/
# mypy
.mypy_cache/

*.code-workspace
*.code-workspace
pj.gcode
14 changes: 5 additions & 9 deletions send2joto.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@

def sendLine(line):

# Sometimes we need to resend a command if Joto is busy
resend = 5
while True:

# Clean the line and don't bother if empty
Expand All @@ -65,6 +63,7 @@ def sendLine(line):
# Check response
response = ""
timeout = 50

while response == "":
time.sleep(0.2)
while ser.inWaiting() > 0:
Expand All @@ -73,6 +72,10 @@ def sendLine(line):
if timeout == 0:
print("Timeout waiting for Joto's response")
return False
if response.strip() == "busy:processing":
print("Waiting")
time.sleep(1)
response = ""

# Validate response
gotOk = False
Expand All @@ -81,13 +84,6 @@ def sendLine(line):
print(">> " + responseLine)
if responseLine == 'ok 0':
gotOk = True
elif responseLine == 'busy:processing':
resend -= 1
if resend < 0:
print("Tried 5 times, stopping")
return False
print('Resending in 1 second')
time.sleep(1)

if gotOk:
break
Expand Down

0 comments on commit c8c445b

Please sign in to comment.