Skip to content

Commit

Permalink
Merge pull request #87 from benlye/fix-lpc-crash
Browse files Browse the repository at this point in the history
Switch from pySerial to system commands for LPC1768
  • Loading branch information
benlye authored May 21, 2019
2 parents cbc46da + 8c898b7 commit 228338b
Showing 1 changed file with 38 additions and 48 deletions.
86 changes: 38 additions & 48 deletions octoprint_firmwareupdater/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,23 +617,28 @@ def _reset_1200(self, printer_port=None):
def _reset_lpc1768(self, printer_port=None):
assert(printer_port is not None)
self._logger.info(u"Resetting LPC1768 at '{port}'".format(port=printer_port))
try:
ser = serial.Serial(port=printer_port, \
baudrate=9600, \
parity=serial.PARITY_NONE, \
stopbits=serial.STOPBITS_ONE , \
bytesize=serial.EIGHTBITS, \
timeout=2000)

# Marlin reset command
ser.write("M997\r")
# Smoothie reset command
ser.write("reset\r")

ser.close()
# Configure the port
try:
os.system('stty -F ' + printer_port + ' speed 115200 -echo > /dev/null')
except:
self._logger.exception(u"Error configuring serial port.")
self._send_status("flasherror", message="Board reset failed")
return False

except SerialException as ex:
self._logger.exception(u"Board reset failed: {error}".format(error=str(ex)))
# Smoothie reset command
try:
os.system('echo reset >> ' + printer_port)
except:
self._logger.exception(u"Error sending Smoothie 'reset' command.")
self._send_status("flasherror", message="Board reset failed")
return False

# Marlin reset command
try:
os.system('echo M997 >> ' + printer_port)
except:
self._logger.exception(u"Error sending Marlin 'M997' command.")
self._send_status("flasherror", message="Board reset failed")
return False

Expand All @@ -648,6 +653,7 @@ def _wait_for_lpc1768(self, printer_port=None):
assert(printer_port is not None)
self._logger.info(u"Waiting for LPC1768 at '{port}' to reset".format(port=printer_port))

check_command = 'ls ' + printer_port + ' > /dev/null 2>&1'
start = time.time()
timeout = 10
interval = 0.2
Expand All @@ -659,19 +665,12 @@ def _wait_for_lpc1768(self, printer_port=None):
while (time.time() < (loopstarttime + timeout) and connected):
self._logger.debug(u"Waiting for reset to init [{}/{}]".format(count, int(timeout / interval)))
count = count + 1
try:
ser = serial.Serial(port=printer_port, \
baudrate=9600, \
parity=serial.PARITY_NONE, \
stopbits=serial.STOPBITS_ONE , \
bytesize=serial.EIGHTBITS, \
timeout=2000)

ser.close()

if not os.system(check_command):
connected = True
time.sleep(interval)

except SerialException as ex:
else:
time.sleep(interval)
connected = False

Expand All @@ -692,19 +691,12 @@ def _wait_for_lpc1768(self, printer_port=None):
while (time.time() < (loopstarttime + timeout) and not connected):
self._logger.debug(u"Waiting for reset to complete [{}/{}]".format(count, int(timeout / interval)))
count = count + 1
try:
ser = serial.Serial(port=printer_port, \
baudrate=9600, \
parity=serial.PARITY_NONE, \
stopbits=serial.STOPBITS_ONE , \
bytesize=serial.EIGHTBITS, \
timeout=2000)

ser.close()

if not os.system(check_command):
connected = True
time.sleep(interval)

except SerialException as ex:
else:
time.sleep(interval)
connected = False

Expand All @@ -719,20 +711,18 @@ def _wait_for_lpc1768(self, printer_port=None):
def _unmount_sd(self, printer_port=None):
assert(printer_port is not None)
self._logger.info(u"Release the firmware lock on the SD Card by sending 'M22' to '{port}'".format(port=printer_port))
try:
ser = serial.Serial(port=printer_port, \
baudrate=9600, \
parity=serial.PARITY_NONE, \
stopbits=serial.STOPBITS_ONE , \
bytesize=serial.EIGHTBITS, \
timeout=2000)

ser.write("M22\r")
time.sleep(1)
ser.close()
try:
os.system('stty -F ' + printer_port + ' speed 115200 -echo > /dev/null')
except:
self._logger.exception(u"Error configuring serial port.")
self._send_status("flasherror", message="Card unmount failed")
return False

except SerialException as ex:
self._logger.exception(u"Card unmount failed: {error}".format(error=str(ex)))
try:
os.system('echo M22 >> ' + printer_port)
except:
self._logger.exception(u"Error sending 'M22' command.")
self._send_status("flasherror", message="Card unmount failed")
return False

Expand Down

0 comments on commit 228338b

Please sign in to comment.