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

Loading…
Cancel
Save