diff --git a/playgrounds/multithread_comm_demo.py b/playgrounds/multithread_comm_demo.py index bd048a1..ea5b593 100644 --- a/playgrounds/multithread_comm_demo.py +++ b/playgrounds/multithread_comm_demo.py @@ -22,11 +22,9 @@ def __init__(self): self.pc_queue = queue.Queue(maxsize=0) def start(self): - # _thread.start_new_thread(self.read_android, (self.android_queue,)) _thread.start_new_thread(self.read_arduino, (self.pc_queue,)) _thread.start_new_thread(self.read_pc,(self.arduino_queue,)) - # _thread.start_new_thread(self.write_android, (self.android_queue,)) _thread.start_new_thread(self.write_arduino, (self.arduino_queue,)) _thread.start_new_thread(self.write_pc, (self.pc_queue,)) @@ -38,20 +36,6 @@ def start(self): def end(self): log.info('Multithread Communication Session Ended') - # def read_android(self, android_queue): - # while True: - # msg = self.android.read() - # if msg is not None: - # log.info('Read Android:' + str(msg)) - # android_queue.put_nowait('Hello from PC: ' + str(msg)) - - # def write_android(self, android_queue): - # while True: - # if not android_queue.empty(): - # msg = android_queue.get_nowait() - # self.android.write(msg) - # log.info('Write Android: ' + str(msg)) - def read_arduino(self, pc_queue): while True: msg = self.arduino.read() @@ -70,8 +54,11 @@ def read_pc(self, arduino_queue): while True: msg = self.pc.read() if msg is not None: - log.info('Read PC: ' + str(msg)) - arduino_queue.put_nowait(msg) + log.info('Read PC: ' + str(msg['target']) + '; ' + str(msg['payload'])) + if msg['target'] == 'arduino': + arduino_queue.put_nowait(msg['payload']) + elif msg['target'] == 'both': + arduino_queue.put_nowait(msg['payload']['arduino']) def write_pc(self, pc_queue): while True: