Browse Source

fix serial

split-pipe
Hendrik Langer 4 years ago
parent
commit
44a1fe7381
  1. 14
      raspberry/roberto/Serial.py

14
raspberry/roberto/Serial.py

@ -10,13 +10,13 @@ class Serial(object):
try:
self.serialport = serial.Serial(devicename, baudrate, timeout=3.0)
self.serialport.flushInput()
self.serialport.write("\n")
self.serialport.write(b'\n')
self.alive = True
print("Arduino connection established..")
except serial.SerialException as e:
print('could not open port {!r}: {}\n'.format(devicename, e))
except:
print("Failed to open serial device: " + self.serialport.name)
# except:
# print("Failed to open serial device: " + self.serialport.name)
self.receiver_thread = threading.Thread(target=self.reader, name='rx')
self.receiver_thread.daemon = True
@ -34,7 +34,8 @@ class Serial(object):
if isinstance(buf, str):
buf = bytes(buf, "utf8")
self.serialport.flushInput()
self.serialport.write(buf+"\n") # or "\r\n" ?
self.serialport.write(buf)
#self.serialport.write(b'\n') # or "\r\n" ?
print("sent " + str(buf))
except:
print("Error writing to: " + self.serialport.name + " Data: " + str(buf))
@ -46,5 +47,6 @@ class Serial(object):
if data:
print(data)
except serial.SerialException:
self.alive = False
raise
pass
#self.alive = False
#raise

Loading…
Cancel
Save