Skip to content
Snippets Groups Projects
Commit f66a4cce authored by Kai Junge's avatar Kai Junge
Browse files

Added functionality to solve two issues. 1) Killing threads when the main...

Added functionality to solve two issues. 1) Killing threads when the main program ends. 2) Making a status variable if a messege with new content is received.
parent 656e4ce1
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Removed -->
## [Unreleased]
### Added
- Status variable to indicate when a messege with new data is received.
### Changed
- Threading to terminate when the main python file is terminated.
<!-- ### Removed -->
## [Release v1.0.0](https://gitlab.epfl.ch/create-lab/lab-systems/arduino_python_communication/-/releases/release_v1.0.0) - 22-1-2022
### Added
......
......@@ -3,6 +3,7 @@ import serial.tools.list_ports
from threading import Thread
import time
from pynput import keyboard
import copy
########
### Arduino communication
......@@ -23,7 +24,10 @@ class Arduino:
self.handshakeStatus = False
self.connectionStatus = False
self._echo_python_msg = None
self.newMsgRecieved = False
# Threading
self.__thread = None
# Private methods
def _serial_readline(self):
......@@ -36,8 +40,9 @@ class Arduino:
def _startReadingThread(self):
thread = Thread(target=self._serial_readline)
thread.start()
self.__thread = Thread(target=self._serial_readline)
self.__thread.daemon = True
self.__thread.start()
def _serial_write(self, msg):
......@@ -72,8 +77,7 @@ class Arduino:
def _disect_and_save_message(self, msg):
receivedMessageTemp = self.receivedMessages
receivedMessageTemp = copy.deepcopy(self.receivedMessages)
if msg[-2] != ":":
return False
......@@ -96,7 +100,12 @@ class Arduino:
else:
return False
if receivedMessageTemp == self.receivedMessages:
self.newMsgRecieved = False
else:
self.newMsgRecieved = True
self.receivedMessages = receivedMessageTemp
return True
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment