From bd651c6bcb29831f9c36ed70f102b453345922dd Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Tue, 31 Mar 2015 11:27:44 +0200 Subject: [PATCH] Listening now correctly works --- PrinterConnection.py | 20 ++++++++++---------- USBPrinterManager.py | 4 ++-- avr_isp/ispBase.py | 2 +- avr_isp/stk500v2.py | 4 +--- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/PrinterConnection.py b/PrinterConnection.py index e8343be959..a4dff409b6 100644 --- a/PrinterConnection.py +++ b/PrinterConnection.py @@ -1,5 +1,5 @@ from UM.Logger import Logger -from .avr_isp import stk500v2 +from .avr_isp import stk500v2, ispBase import threading class PrinterConnection(): @@ -34,12 +34,12 @@ class PrinterConnection(): try: self._serial = programmer.leaveISP() # Create new printer connection - self.active_printer_connection = PrinterConnection(temp_serial) - Logger.log('i', "Established connection on port %s" % serial_port) + self.active_printer_connection = PrinterConnection(self._serial_port) + Logger.log('i', "Established connection on port %s" % self._serial_port) except ispBase.IspError as e: - Logger.log('i', "Could not establish connection on %s: %s. Device is not arduino based." %(serial_port,str(e))) + Logger.log('i', "Could not establish connection on %s: %s. Device is not arduino based." %(self._serial_port,str(e))) except: - Logger.log('i', "Could not establish connection on %s, unknown reasons. Device is not arduino based." % serial_port) + Logger.log('i', "Could not establish connection on %s, unknown reasons. Device is not arduino based." % self._serial_port) if self._serial is None: #Device is not arduino based, so we need to cycle the baud rates. @@ -76,7 +76,7 @@ class PrinterConnection(): def setIsConnected(self, state): self._is_connecting = False - if state != state: + if self._is_connected != state: self._is_connected = state else: Logger.log('w', "Printer connection state was not changed") @@ -96,18 +96,18 @@ class PrinterConnection(): if line is None: break #None is only returned when something went wrong. Stop listening - if line.startswith('Error:'): + if line.startswith(b'Error:'): #Oh YEAH, consistency. # Marlin reports an MIN/MAX temp error as "Error:x\n: Extruder switched off. MAXTEMP triggered !\n" # But a bed temp error is reported as "Error: Temperature heated bed switched off. MAXTEMP triggered !!" # So we can have an extra newline in the most common case. Awesome work people. - if re.match('Error:[0-9]\n', line): + if re.match(b'Error:[0-9]\n', line): line = line.rstrip() + self._readline() #Skip the communication errors, as those get corrected. - if 'Extruder switched off' in line or 'Temperature heated bed switched off' in line or 'Something is wrong, please turn off the printer.' in line: + if b'Extruder switched off' in line or b'Temperature heated bed switched off' in line or b'Something is wrong, please turn off the printer.' in line: if not self.hasError(): self._error_state = line[6:] - if ' T:' in line or line.startswith('T:'): #Temperature message + if b' T:' in line or line.startswith(b'T:'): #Temperature message try: print("TEMPERATURE", float(re.search("T: *([0-9\.]*)", line).group(1))) except: diff --git a/USBPrinterManager.py b/USBPrinterManager.py index 1e5645439b..07d7132368 100644 --- a/USBPrinterManager.py +++ b/USBPrinterManager.py @@ -17,8 +17,8 @@ class USBPrinterManager(SignalEmitter,PluginObject): self._check_ports_thread = threading.Thread(target=self._updateConnectionList) self._check_ports_thread.daemon = True self._check_ports_thread.start() - time.sleep(2) - self.connectAllConnections() + #time.sleep(2) + #self.connectAllConnections() ## Check all serial ports and create a PrinterConnection object for them. # Note that this does not validate if the serial ports are actually usable! diff --git a/avr_isp/ispBase.py b/avr_isp/ispBase.py index 16eeec8e67..8d65f03f71 100644 --- a/avr_isp/ispBase.py +++ b/avr_isp/ispBase.py @@ -56,7 +56,7 @@ class IspBase(): """ raise IspError("Called undefined verifyFlash") -class IspError(): +class IspError(BaseException): def __init__(self, value): self.value = value def __str__(self): diff --git a/avr_isp/stk500v2.py b/avr_isp/stk500v2.py index a3855109f1..b2d2449727 100644 --- a/avr_isp/stk500v2.py +++ b/avr_isp/stk500v2.py @@ -127,10 +127,8 @@ class Stk500v2(ispBase.IspBase): for c in data: message += struct.pack(">B", c) checksum = 0 - print("messsage " , message) for c in message: - print(c) - checksum ^= ord(c) + checksum ^= c message += struct.pack(">B", checksum) try: self.serial.write(message)