Hart Software and Embedded Systems Development
Hart Software and Embedded Systems Development

Coffee Corner - Python

Python - Hart Protocol - Embedded Linux - Module Test

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

Hart into Python A software level introduction to the HART protocol
Hart Example 1 A sans I/O Python implementation of the Highway Adressable Remote Transducer Protocol.
Hart Example 2 The HART Testing Framework
Hart slave emulator University Master's Degree in Industrial Engineering (large pdf)

Python vs C#

Head to Head Comparison C# and Python both are among the popular programming languages of 2023
Python vs C# What makes Python cool?
C# vs Python Choosing the Right Language for Your Project

Python vs C++

Python Vs C++ Top 16 Differences Between C++ And Python
Python Vs C++ Key Difference Between Python and C++

Multitasking

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.

Multiprocessing Example In this tutorial we are going to learn Python Multiprocessing ..
Multiprocessing Tutorial What are processes in Python (Windows, Linux, Mac)?
Process-based parallelism The multiprocessing module runs on both Unix and Windows.
Multiprocessing The Complete Guide

Unit Testing

NUnit vs pytest What are the differences between NUnit and pytest?
Unit testing framework The unittest unit testing framework was originally inspired by JUnit ..
pytest helps you write better programs

Miscellaneous

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

HartDLL in Python HartDLL in Python

The module demonstrates the use of the HartDll from HartTools 7.6. It is kept very simple and shows the basic procedure for loading and using the Windows dll HartDrv76 in Python 3.8.
The example is loading the dll, registering the license and establishing a connection with a hart slave.

The Python Example source code The Python Example source code

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.

The output of the program then looks like this.

The Output of the Program The Output of the Program

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
Hartdll.BHDrv_FetchConnection(myservice, byref(connectionData))
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.

Druckversion | Sitemap
Copyright © 1998-2024 Walter Borst. All Rights Reserved.