Skip to content

Commit 23bec82

Browse files
making the library check more for ok command and allowing a time over ride as well.
1 parent e9eceec commit 23bec82

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

electroblocks/core.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ def _add_pin(self, pinType, pin):
8888
self.pins[pinType].append(str(pin))
8989

9090

91-
def _wait_for_message(self, message):
91+
def _wait_for_message(self, message, wait_time = 0.005):
9292
count = 0
93-
while count < 10:
93+
while count < 100:
9494
if self.ser.in_waiting:
9595
line = self.ser.readline().decode("utf-8", errors="ignore").strip()
9696
if message in line:
9797
return line
9898
count += 1
99-
time.sleep(0.05)
99+
time.sleep(wait_time)
100100
if self.verbose:
101101
print(f"DEBUG: MESSAGE NOT FOUND: '{message}'")
102102
return ""
@@ -140,9 +140,9 @@ def _wait_for_ready(self):
140140
self.ser.write(b"IAM_READY|")
141141
self._wait_for_message("System:READY")
142142

143-
def _send(self, cmd):
143+
def _send(self, cmd, wait_time = 0.005):
144144
self.ser.write((cmd + "|\n").encode())
145-
self._wait_for_message("OK")
145+
self._wait_for_message("OK", wait_time)
146146

147147

148148
# RFID
@@ -380,7 +380,9 @@ def config_stepper_motor(self, pin1, pin2, pin3, pin4, steps, speed):
380380

381381
def move_stepper_motor(self, steps):
382382
pin = self.pins[ComponentPins.STEPPER_MOTOR][0]
383-
self._send(f"write::ste::{pin}::{steps}")
383+
# For Stepper motors this can take
384+
# a long time so the wait should be longer.
385+
self._send(f"write::ste::{pin}::{steps}", 0.1)
384386

385387

386388
# Motors

0 commit comments

Comments
 (0)