Coffee Corner - Python
I recently saw a Python example that showed how easy it is to create a HART communication straight away. What would the communication dll in HartTools be good for?
I then researched Python extensively and discovered that Python is surprisingly sophisticated and can do much more than Visual Basic back then. But I also saw that, in addition to the many strengths, Python also has some weaknesses and I have come to the conclusion that Python's main strength lies in fast prototyping. But where real time or reliability is important, other solutions may also be required.
I was impressed by how easily Python can be connected to other environments. You don't have to create any declarations to integrate a Windows DLL (e.g. BaHartDrv76.dll). The interpreter recognizes for himself what functions are included. You can easily make HART communication capable of real-time using the DLL mentioned and still integrate it into Python.
When it comes to a graphical user interface, Python is not yet particularly strong. That's why it also makes sense to use the FrameAlyst from the HartTools together with the DLL in order to have efficient logging and display of the HART signals, even if the control of the HART communication via DLL is based on a Python module.
Another strength of Python is that the interpreter also runs on Linux. It is not yet 100% clear how the exact connection to the new Hart Master will be. However, the connection to Python will be a benchmark for the new driver.
Anyway, below you will find some links to information that I came across during my research. I'm currently in the process of figuring out how best to combine Python and C++ to meet complex real-time requirements and take advantage of the benefits of Python programming.
HART Protocol with Python
Python vs C#
Python vs C++
First, I have to say something about multitasking. Python is an interpreter language in which the interpreter runs as a few tasks (threads) in a process. This is probably not comparable to so-called mulithreading, where I have full control over what happens. For example, I can ensure that a thread runs in a millisecond grid. This option is needed, for example, to maintain the timing on a HART interface.
Things are completely different with parallel processes. Particularly when they are still communicating with each other, the question arises as to under what circumstances the processes can 'slow down' each other.
Furthermore, it is to be expected that the behavior of processes in a Windows environment differs from the behavior in Linux. But that would also apply to threads.
|C API Reference Manual||This manual documents the API used by C and C++ programmers ..|
|Learning with Raspberry Pi||This book is about teaching Python using the Raspberry Pi 4 computer ..|
|MicroPython||MicroPython runs on embedded hardware like RaspBerry Pi Pico ..|
|Python on Unix platforms||Getting and installing the latest version of Python ..|
|GUI Application||How to Build a Python GUI Application With wxPython ..|
Using HartTools 7.6 in Python
We have provided the complete source code in a pdf file which you can download by clicking the following link. Please let us know, if you are having any questions.
Python Example (pdf)
The output of the program then looks like this.
At this point I can't resist making two comments. It's always said that Python doesn't work with pointers. But the program line
passes a pointer to the HartDLL.
In the same way, it is always said that Python is very suitable for faster prototyping. But I still need a graphical editor for a user interface.
However, Python is currently one of the most popular programming languages and there are likely to be some changes in the near future. That's why I'm sticking with this topic, but not without expressing criticism about things that don't seem plausible to me.