📜 ⬆️ ⬇️

ScadaPy Creator for python

Speed ​​up the process of creating modbus.py


Once again I want to share my experience and the results of experiments in the field of industrial automation.


At the moment, we have slightly changed the concept of building a device polling system using the python language.

Most of the SCADA modules of the systems are built on the principle of a bundle “executable file - configuration file” .

An executable file is usually a compiled binary file that is directly involved in polling slave devices using a specific protocol, it can also be called a “protocol driver”.

The polling parameters (port, addresses, speed, etc.) for the driver are recorded in a configuration file, which can be of different types. It can be a table or tables in any DBMS, for example, SQLite or Firebird is often used, an xml file can also be used.
Working with various devices, we came to the conclusion that it would be very convenient to have already compiled the driver file with all the settings (variables) inside, it would be nice to be able to correct the driver already on the server when organizing device polling.
')
For this purpose, we considered the option of creating an application that, based on the xml configuration file, will create a driver in python.

The main condition - the program that generates the driver code, must necessarily work on both Windows and Linux.

Initially, we decided to make an application on PyQt, but frankly, it turned out to be quite difficult for us to write a program in such a bundle without having a full-fledged visual IDE for building the user interface.

Previously, you had to often do programs on C Builder and Delfi, so you turned your eyes towards Lazarus. We tried to compile programs on different operating systems - we were satisfied with the result.

We decided to try to write an application on Lazarus IDE 1.8.2., Called it ScadaPy Creator.
All configuration settings are saved in one single xml file.

image

After compiling the output, we have a modbus driver, a Mercury 230 counter driver, an http Json server, and an html file as a client.

How it works


Run the modbus driver or Mercury-230 to poll devices.

Having received the answers according to the described variables, the driver sends data via the UDP protocol to port 64000. We launch the Json HTTP server, which in turn receives data from the driver and forms a packet in json format for http requests.

We launch the client's html file in the browser and see the already processed data in three formats - json, text and SVG images.

Then you can edit and html and SVG to fit your needs.

image

Frankly speaking, it is enough for me to present the data in the form of a simple table, but for some people the information is better perceived as a mnemonic scheme.

A similar variant of using python scripts was repeatedly tested on remote substations, where object servers based on Linux OS were installed and access was available only via SSH.

Of course, to create a full-fledged SCADA system, with a lot of input signals and measurements, this option is not suitable, you definitely need to apply
stable software from trusted manufacturers.

Here is a typical version of the latter.

Task:

There is a device operating under the modbus protocol - a Lumel P18 temperature and humidity sensor.

image

You need to get the temperature and humidity every five minutes and display on the monitor screen in any form.

The device is far away, at a distance of about 90 km from the office.

To begin with we create the project.

image

At R18, the temperature is taken at two addresses 7002 and 7003, 32 bits, the number with a floating point, and the humidity is taken at two addresses 7004 and 7005, 32 bits, the number with a floating point.

image

In addition to temperature and humidity, it is possible to display more detailed information on the object: relative and absolute humidity, dew point, etc.

image

After generation, two files modbus.py and jserver.py will be created.

We send these files to the server of the object, and on the client’s computer we run jclient.html.

image

You can of course move the html file to the web server.

That's basically it.

The project with examples can be downloaded here.

PS

Any criticism, comments and advice are welcome, but constructive and to the point.

Source: https://habr.com/ru/post/354704/


All Articles