OpenSCADA

Modules/Serial

English • ‎mRussian • ‎Українська
Module Name Version License Source Languages Platforms Type Author Description
Serial Serial interfaces 2.7 GPL2 tr_Serial.so en,uk,ru,de x86,x86_64,ARM Transport Roman Savochenko
  Maxim Kochetkov (2016), Maxim Lysenko (2009-2010) — the page initial translation
Provides transport based on the serial interfaces. It is used for data exchanging via the serial interfaces of the type RS232, RS485, GSM and similar.
- test the modem mode and append to it for the PIN entering field.

The module provides support for transports based on serial interfaces such as RS232, RS485, GSM and similar. Input and output transports is supported. You can add new input and output interfaces through the configuration of the transport subsystem in any OpenSCADA configurator.

The module, in the modem mode, supports a mixed mode of operation, which involves the presence of an input transport, which expects external connections, as well as an output transport on the same device. That is, the input transport will ignore all requests in the presence of the output transport connection, while the output transport will not attempt to establish a connection in the presence of the connection to the input transport or the connection of another output transport, for example, another telephone number.

At.png In the normal mode of the serial interface, multiple use of one and the same port in input and output transports is not allowed. A global blocking of the serial device is not performed due to the ambiguity of this process at the system level, and multiple use can lead to unpredictable and difficult-to-understand issues. If you need to organize a local serial channel with a couple of linked ports, it is recommended to use the command socat -d -d pty,raw,echo=0,perm=0666 pty,raw,echo=0,perm=0666.

Contents

1 Input transports

The configured and running input transport opens a serial port to wait for user requests. Each input interface is necessarily associated with one of the available transport protocols to which incoming messages are transmitted.

Fig.1. The generic configuration dialogues of the input serial interface.

Using the main dialog you can set:

Using the additional dialog you can set:

2 Output transports

Configured and running output transport opens port of the serial interface to send the requests through it.

Fig.2. The generic configuration dialogues of the output serial interface.

Using the main dialog you can set:

Using the additional dialog you can set:

Can be prioritatile specified into the address field as the second global argument, as such "/dev/rfcomm0:9600||1000:40-20".

The transport can work with the I2C hardware bus, if "/dev/i2c-{N}" is selected as the device and the bus will allow to set the slave device address by the I2C_SLAVE command from the first request byte. Speed and format do not play a role in this mode. From the timeouts here actually only the symbol time works and mainly for calculating the expectation of the request repetition.

3 User programming API

Object "Output transport" (SYS.Transport.Serial.out_{OutTransport})

4 Notes

Communications via the serial interfaces have a number of features. The most important feature is the criterion for the end of the message and the waiting time of this criterion. In some protocols, such a criterion is a sign of the end or the specified message size. In other protocols, such a criterion is no data in the input stream for a specified time — the symbol time. In both cases, the criterion waiting time, or the symbol, is a crucial and strongly affects the overall exchange time. Consequently, the smaller this time, the better. Here the problem of hardware and its drivers latency happens.

To check for latency of the exchange channel, thus optimally adjust the symbol time, you can use the interface of the "Request" tab of the output transport. To do this, you need to specify an exemplary request for the protocol, specify "Wait timeout", send a request, and check its integrity. To get a more representative result, you need to repeat the request several times. If there is an incomplete response, then the time of the symbol must be increased, otherwise you can reduce it.

On embedded serial interfaces RS232/422/485 hardware you can achieve low latency — up to several milliseconds. However, on high-loaded systems with many tasks in the real-time priority, latency may become non-deterministic, due to the execution of the service thread of the Linux kernel events in low priority. To solve this problem, you must set a high priority to these threads, which can be done using a script, placing it, for example, in "/etc/rc.local":

#!/bin/sh

# Setting the high priority for events kernel threads to rise the serial interfaces reaction
events=`ps -Ao pid,comm | sed -n '/[ ]*\([^ ]\)[ ]*events\/[0-9]/s//\1/p'`
for ie in $events; do
  chrt -pr 21 $ie
done

This script does not make sense for real-time Linux cores, with the PREEMPT_RT patch, since all interrupt and message threads are already running there in real-time priority.

On the external serial interfaces hardware, such as adapters USB->RS232/422/485, you may meet the problems of high latency associated with the feature of hardware implementation or its driver. To solve this problem you need study the configuration of the equipment or adjust the large waiting time — symbol time!

In the like way you can determine an optimal connection time, that is: set the connection time to the default value for this speed (sets when changing the speed in the address), remove the "Wait timeout", send a request. If the answer is come then we take the measured response time of the device, double and set the value as the connection time. An unreasonable excess of the connection time will lead to high expectations in the absence of the device, as well as to trigger the protective timeouts of the internal procedures!

At.png On the market there are USB->Serial converters that work only with terminals, that is, they can transmit and process only ASCII characters and can not be switched to binary mode. Known instances of such converters: PL2303TA (Y-105).

4.1 Virtual/local serial interfaces

Often for local checking, without physical hardware, you may need the ports pair connected each other. For the ports creation and more other operations on serial stream you can use utility socat. For example, to create two linked ports you need call a command which will create and print their addresses:

socat -d -d pty,raw,echo=0,perm=0666 pty,raw,echo=0,perm=0666
#2013/07/02 16:37:29 socat[10402] N PTY is /dev/pts/6
#2013/07/02 16:37:30 socat[10402] N PTY is /dev/pts/7
#2013/07/02 16:37:30 socat[10402] N starting data transfer loop with FDs [3,3] and [5,5]

4.2 Serial interfaces transferring through Ethernet network

In some cases, it is useful to transfer the serial interface port of the remote machine to the local port, for example, to poll the devices connected to the serial interface of the remote machine. Of course, if you install OpenSCADA on the remote machine in the PLC configuration, then you can immediately process the data, pre-buffering/archiving, and so on, but sometimes the hardware can be complicated to launch OpenSCADA, where saves the ability to throw over the serial stream over the network. To solve this problem you can use the same utility socat or remserial, ser2net, which can be built and run on the remote machine. Examples of throwing over the serial port:

# Creating a socket on port 5555 on the remote computer, for the serial port /dev/ttyS0
socat tcp-l:5555,reuseaddr,fork file:/dev/ttyS0,raw
# Connecting to the socket of the reflected port of the remote machine and creating a file of the mirrored local interface.
socat -d -d pty,raw,echo=0,perm=0666 tcp:192.168.2.4:5555,mss=1400
#2013/07/04 10:09:09 socat[12947] N PTY is /dev/pts/4
#2013/07/04 10:09:09 socat[12947] N opening connection to AF=2 192.168.2.4:5555
#2013/07/04 10:09:09 socat[12947] N successfully connected from local address AF=2 192.168.2.61:33493
#2013/07/04 10:09:09 socat[12947] N starting data transfer loop with FDs [3,3] and [5,5]

In the case of "socat", and possibly other utilities, you can omit the EthernetTCP->Serial driver starting on the client side and connect OpenSCADA directly to the TCP port of the remote device.

At.png In operation via the EthernetTCP->Serial driver there is a feature that is associated with the presence of two connection timeouts: one in the driver and one in Transport.Sockets. It is important that the value of this timeout in Transport.Sockets is greater than in the driver, otherwise it is possible to shift and receive delayed replies from previous queries.

More manufacturers of industrial communication hardware produce ready converters from Ethernet to RS-232/422/485, which you can use with OpenSCADA in similar way. Here are comments and a list of the converters for what OpenSCADA working tested:

Modules/Serial/en - GFDLMarch 2024OpenSCADA 0.9.7