Allows disconnecting and reconnecting serial

This commit is contained in:
deckensteuerung 2018-08-22 18:18:43 +02:00
parent 647edcc2ed
commit 69a231bd69

24
main.py
View File

@ -19,11 +19,23 @@ class SerialWriter(threading.Thread):
pass pass
def run(self): def run(self):
ser = serial.Serial(config.Serial) should_connect = True
ser = None
while True: while True:
ser.write(b"\01") try:
ser.write(self.data) if should_connect:
time.sleep(1/120) ser = serial.Serial(config.Serial)
should_connect = False
with self.lock:
ser.write(b"\01")
ser.write(self.data)
time.sleep(1/120)
except:
if ser != None:
ser.close()
ser = None
should_connect = True
time.sleep(0.1)
@ -51,7 +63,6 @@ class AppRunner(threading.Thread):
self.app = subprocess.Popen(args, stdout=subprocess.PIPE) self.app = subprocess.Popen(args, stdout=subprocess.PIPE)
def run(self): def run(self):
ser = serial.Serial("/dev/ttyACM0")
while True: while True:
with self.lock: with self.lock:
if self.app == None or self.app.poll() != None: if self.app == None or self.app.poll() != None:
@ -62,9 +73,6 @@ class AppRunner(threading.Thread):
d = self.app.stdout d = self.app.stdout
oshandle = d.fileno() oshandle = d.fileno()
data = os.read(oshandle, config.ScreenX*config.ScreenY*3) data = os.read(oshandle, config.ScreenX*config.ScreenY*3)
# data = d.raw.read(config.ScreenX*config.ScreenY*3)
#ser.write(b"\01")
#ser.write(data)
self.serial.setData(data) self.serial.setData(data)