The author of this project considers this project is still in development, and is open for further improvement. The aim is to log multiple devices at once. The logger doesn't need to know what kind of device it's handling, it only needs the port the device is connected to, the baudrate, and the logfile name.
Why use multithreading? It's because the logger continously polls the data from the device, meaning it's always in waiting state.
You won't notice it if the baudrate is set high enough, but imagine working with low clock device like Arduino, which
only has 16MHz clock. The latency would be a problem if we log multiple Arduinos. The main GUI will be forced to wait for
the logger and cannot process incoming events from the user correctly.
Multiprocessing will execute process concurrently, exactly at the same rate, while threads however, is executed one by one, by switching between threads really fast, creating the 'illusion' of concurrent proccess. Why not use Python multiprocessing module? Because it's too heavy on resource. I built this project, with the consideration of running it on my Raspberry Pi, which doesn't have many cores for doing a good multiprocessing.
- Able to connect to multiple device. This is done using multithreading.
- Able to log data concurrently from devices. 1 device = 1 thread.
- Display log information in the console. If what you need is just displaying log information on the console, there are already tons of tools such as
minicom
,picocom
, or even the Arduino IDE Serial Monitor. The console is used to display information such as connection sources, errors, etc. You don't wanna make it clogged up with +5 device sending data at the same rate right?
- Clone this repository into your directory of choice
git clone https://github.com/yeyee2901/multithread-serial-logger.git /path/of/your/choice
- Make sure you have python, pip, and pipenv in your system. For Debian based system:
sudo apt install python3 pipenv python3-pip
- This project dependencies are managed using Pipfile, so install the requirements using pipenv. Main dependencies are PyQt5 for GUI, and pyserial.
cd /path/to/your/repo/clone
pipenv install
- To run the program, activate the virtual environment first using
pipenv
and runmain.py
pipenv shell
python main.py
- The app is able to log multiple device concurrently
- Disconnecting a device will not affect the logging thread of other device
- App can exit without error (clean exit) -> disconnect all device, then close the app. Closing the app while there's still active device logging, will not kill the process.
- Do not forget to set the baudrate, as of now, mismatch of the baudrate can lead to undesired behaviour (in my case, the app will hang, and if you disconnect the device, it crashes). For safety reasons, I always set all of my device baudrates to be the same.
- The program now works for both Windows & UNIX like systems.
- Raspberry Pi 4 Model B
- Pop-OS 21.04
- MacOS
- Windows 10
Simple test run using Arduino UNO R3 & NodeMCU v2. Both of the programs are identically the same. Just sending a simple hello string.