gcode: Convert to Python3 string encoding

The error checking is not complete in this change - the code should
handle the case where an input string is not valid utf8.

The code will continue to run on Python2 after this change, however
the execution time on Python2 is measurably slower after making this
change.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2020-06-12 09:59:04 -04:00
parent 1717263b5a
commit adeb869f56
1 changed files with 2 additions and 2 deletions

View File

@ -387,7 +387,7 @@ class GCodeIO:
return 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.decode().split('\n')
lines[0] = self.partial_input + lines[0] lines[0] = self.partial_input + lines[0]
self.partial_input = lines.pop() self.partial_input = lines.pop()
pending_commands = self.pending_commands pending_commands = self.pending_commands
@ -427,7 +427,7 @@ class GCodeIO:
def _respond_raw(self, msg): def _respond_raw(self, msg):
if self.pipe_is_active: if self.pipe_is_active:
try: try:
os.write(self.fd, msg+"\n") os.write(self.fd, (msg+"\n").encode())
except os.error: except os.error:
logging.exception("Write g-code response") logging.exception("Write g-code response")
self.pipe_is_active = False self.pipe_is_active = False