mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-09 07:56:22 -06:00
Listening now correctly works
This commit is contained in:
parent
3fa02d3710
commit
bd651c6bcb
4 changed files with 14 additions and 16 deletions
|
@ -1,5 +1,5 @@
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
from .avr_isp import stk500v2
|
from .avr_isp import stk500v2, ispBase
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
class PrinterConnection():
|
class PrinterConnection():
|
||||||
|
@ -34,12 +34,12 @@ class PrinterConnection():
|
||||||
try:
|
try:
|
||||||
self._serial = programmer.leaveISP()
|
self._serial = programmer.leaveISP()
|
||||||
# Create new printer connection
|
# Create new printer connection
|
||||||
self.active_printer_connection = PrinterConnection(temp_serial)
|
self.active_printer_connection = PrinterConnection(self._serial_port)
|
||||||
Logger.log('i', "Established connection on port %s" % serial_port)
|
Logger.log('i', "Established connection on port %s" % self._serial_port)
|
||||||
except ispBase.IspError as e:
|
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:
|
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:
|
if self._serial is None:
|
||||||
#Device is not arduino based, so we need to cycle the baud rates.
|
#Device is not arduino based, so we need to cycle the baud rates.
|
||||||
|
@ -76,7 +76,7 @@ class PrinterConnection():
|
||||||
|
|
||||||
def setIsConnected(self, state):
|
def setIsConnected(self, state):
|
||||||
self._is_connecting = False
|
self._is_connecting = False
|
||||||
if state != state:
|
if self._is_connected != state:
|
||||||
self._is_connected = state
|
self._is_connected = state
|
||||||
else:
|
else:
|
||||||
Logger.log('w', "Printer connection state was not changed")
|
Logger.log('w', "Printer connection state was not changed")
|
||||||
|
@ -96,18 +96,18 @@ class PrinterConnection():
|
||||||
if line is None:
|
if line is None:
|
||||||
break #None is only returned when something went wrong. Stop listening
|
break #None is only returned when something went wrong. Stop listening
|
||||||
|
|
||||||
if line.startswith('Error:'):
|
if line.startswith(b'Error:'):
|
||||||
#Oh YEAH, consistency.
|
#Oh YEAH, consistency.
|
||||||
# Marlin reports an MIN/MAX temp error as "Error:x\n: Extruder switched off. MAXTEMP triggered !\n"
|
# 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 !!"
|
# 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.
|
# 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()
|
line = line.rstrip() + self._readline()
|
||||||
#Skip the communication errors, as those get corrected.
|
#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():
|
if not self.hasError():
|
||||||
self._error_state = line[6:]
|
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:
|
try:
|
||||||
print("TEMPERATURE", float(re.search("T: *([0-9\.]*)", line).group(1)))
|
print("TEMPERATURE", float(re.search("T: *([0-9\.]*)", line).group(1)))
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -17,8 +17,8 @@ class USBPrinterManager(SignalEmitter,PluginObject):
|
||||||
self._check_ports_thread = threading.Thread(target=self._updateConnectionList)
|
self._check_ports_thread = threading.Thread(target=self._updateConnectionList)
|
||||||
self._check_ports_thread.daemon = True
|
self._check_ports_thread.daemon = True
|
||||||
self._check_ports_thread.start()
|
self._check_ports_thread.start()
|
||||||
time.sleep(2)
|
#time.sleep(2)
|
||||||
self.connectAllConnections()
|
#self.connectAllConnections()
|
||||||
|
|
||||||
## Check all serial ports and create a PrinterConnection object for them.
|
## Check all serial ports and create a PrinterConnection object for them.
|
||||||
# Note that this does not validate if the serial ports are actually usable!
|
# Note that this does not validate if the serial ports are actually usable!
|
||||||
|
|
|
@ -56,7 +56,7 @@ class IspBase():
|
||||||
"""
|
"""
|
||||||
raise IspError("Called undefined verifyFlash")
|
raise IspError("Called undefined verifyFlash")
|
||||||
|
|
||||||
class IspError():
|
class IspError(BaseException):
|
||||||
def __init__(self, value):
|
def __init__(self, value):
|
||||||
self.value = value
|
self.value = value
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
|
@ -127,10 +127,8 @@ class Stk500v2(ispBase.IspBase):
|
||||||
for c in data:
|
for c in data:
|
||||||
message += struct.pack(">B", c)
|
message += struct.pack(">B", c)
|
||||||
checksum = 0
|
checksum = 0
|
||||||
print("messsage " , message)
|
|
||||||
for c in message:
|
for c in message:
|
||||||
print(c)
|
checksum ^= c
|
||||||
checksum ^= ord(c)
|
|
||||||
message += struct.pack(">B", checksum)
|
message += struct.pack(">B", checksum)
|
||||||
try:
|
try:
|
||||||
self.serial.write(message)
|
self.serial.write(message)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue