gcode: Catch errors on fd read and write
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
d1da6100a6
commit
91691afdcf
|
@ -183,7 +183,11 @@ class GCodeParser:
|
||||||
m112_r = re.compile('^(?:[nN][0-9]+)?\s*[mM]112(?:\s|$)')
|
m112_r = re.compile('^(?:[nN][0-9]+)?\s*[mM]112(?:\s|$)')
|
||||||
def process_data(self, eventtime):
|
def process_data(self, eventtime):
|
||||||
# Read input, separate by newline, and add to pending_commands
|
# Read input, separate by newline, and add to pending_commands
|
||||||
|
try:
|
||||||
data = os.read(self.fd, 4096)
|
data = os.read(self.fd, 4096)
|
||||||
|
except os.error:
|
||||||
|
logging.exception("Read g-code")
|
||||||
|
return
|
||||||
self.input_log.append((eventtime, data))
|
self.input_log.append((eventtime, data))
|
||||||
self.bytes_read += len(data)
|
self.bytes_read += len(data)
|
||||||
lines = data.split('\n')
|
lines = data.split('\n')
|
||||||
|
@ -256,15 +260,21 @@ class GCodeParser:
|
||||||
def ack(self, msg=None):
|
def ack(self, msg=None):
|
||||||
if not self.need_ack or self.is_fileinput:
|
if not self.need_ack or self.is_fileinput:
|
||||||
return
|
return
|
||||||
|
try:
|
||||||
if msg:
|
if msg:
|
||||||
os.write(self.fd, "ok %s\n" % (msg,))
|
os.write(self.fd, "ok %s\n" % (msg,))
|
||||||
else:
|
else:
|
||||||
os.write(self.fd, "ok\n")
|
os.write(self.fd, "ok\n")
|
||||||
|
except os.error:
|
||||||
|
logging.exception("Write g-code ack")
|
||||||
self.need_ack = False
|
self.need_ack = False
|
||||||
def respond(self, msg):
|
def respond(self, msg):
|
||||||
if self.is_fileinput:
|
if self.is_fileinput:
|
||||||
return
|
return
|
||||||
|
try:
|
||||||
os.write(self.fd, msg+"\n")
|
os.write(self.fd, msg+"\n")
|
||||||
|
except os.error:
|
||||||
|
logging.exception("Write g-code response")
|
||||||
def respond_info(self, msg):
|
def respond_info(self, msg):
|
||||||
logging.debug(msg)
|
logging.debug(msg)
|
||||||
lines = [l.strip() for l in msg.strip().split('\n')]
|
lines = [l.strip() for l in msg.strip().split('\n')]
|
||||||
|
|
Loading…
Reference in New Issue