This week I decided to learn Python, I have been meaning to for quite a while now but have never really had an excuse (That and as a Perl coder all that whitespace makes me very confused!). I have decided to try and make a diagnostics and packet inspection program for the WellyNet protocol we developed last week.
I opted to use the TKinter toolkit and Python 3.4 to build my application, primarily because having never used Python before I wanted to select a very well documented and commonly used toolkit for which finding examples and tutorials would not be difficult.
For development I chose to use the PyCharm IDE, as I am new to Python I did want an environment that provided some hand-holding features like a proper debugger with breakpoints (Luxury!).
The software I wrote was intended to work as a simple packet inspector for the WellyNet serial communications library that we developed in the networking week, the software uses any microcontroller device as a serial bridge between the PC UART interface and the WellyNet interface. In this instance the microcontroller should simply act as a dumb bridge, forwarding any bytes received on the WellyNet interface and repeating them on the UART interface without interfering or performing any sort of processing.
Currently the interface consists of a window and packet inspection listbox, the colour of the lines in the listbox reflect the result of a check of the LRC check byte sent at the end of each WellyNet packet. Capture of data from can be started and stopped using an on-screen button and the serial port can be selected using a conventional menu.
The ATTiny 44/45 µControllers do not have sufficient memory to run both the SoftwareSerial and WellyNet libraries concurrently, thus a µController with a hardware UART module is strongly recommended for the bridge.
Rather than performing serial operations on the main thread and potentially causing hangs and pauses in the GUI I decided to use a multithreaded model and create a worker thread for the serial polling code.
The serial monitor thread maintains a buffer list that is itself periodically polled by the GUI thread, upon discovering the fresh data in the buffer the GUI thread will append it to both the data storage list and the listbox for viewing by the user.
- Tarball of the PyCharm project folder is available here.