Skip to content

03_modbus_services

César García edited this page Jul 1, 2020 · 4 revisions

3. Modbus Services

In the area of automation, MODBUS is a well-established protocol, thanks to its simplicity and support given by many device manufacturers.

In Merlot, the implementation of shared memory areas of the gateway is based on data models established in the MODBUS standar. Also is deployed a Modbus TCP/IP server to allow external devices such as HMI or SCADA access these.

While there are implementations of MODBUS protocol in Java, at this stage implement the MODBUS server using Netty libraries, in order to obtain a granular control of server operations.

Since the development lead time is presented in four parts:

3.1 Concept and architecture 3.2 Merlot Server 3.3 Merlot Device 3.4 Modbus sim utilitys 3.5 Use case

3.1 The concept and architecture

Merlot is conceived as an open platform for the development of an industrial gateway, for this purpose must have a "data area" between "application" and the "operator interface". To implement the "data area" were used the models proposed in Modbus protocol [1], a model of continuous data which you can access records associated bits are shown in figure 2, and a data model with areas separate memories for registrations and bits shown in figure 3.

03_01.png Figure 1

03_01.png Figure 2

To incorporate this model a com.ceos.merlot.modbus.api.ModbusDevice interface which represent an abstract Modbus device is created and would use as a swap area. The class that implements this com.ceos.merlot.modbus.impl.ModbusDeviceImpl (1) interface, implements the two data models embodied in the Modbus standard.

Each of the instances created from ModbusDeviceImpl is registered as a service within Merlot. Under this concept, you can have a maximum of 255 Modbus devices.

Given the dynamic nature established in OSGi, the bundle that implements the ModbusDevice interface can be created/destroyed through BluePrint (used by default) or programmatically. To facilitate access to these objects in its lifecycle is created a service referring to each of these, and its com.ceos.merlot.modbus.api.ModbusDeviceArray interface. The ModbusDeviceArrayImpl (2), implementation saves a reference through a List (own Blueprint container) and a linear arrangement of ModbusDevice type, which is updated dynamically and provides a benchmark for other applications requiring access to the devices, being index corresponds to the UID of the device, thus achieving an access O(1).

03_03.png Figure 3

To develop the server Modbus, the protocol is implemented using Netty [2]. The ModbusTCPServer (3) server uses port 502, the default in the standard. The server keeps a reference to ModbusDeviceArray (3) for access to the devices shown by ModbusDevice (4) to run the interpreter of the function code

Initially, the following Modbus function codes are validated: 1,2,3,4,15 and 16. This function tests that were carried out against a commercially available Industrial driver called "Direct-Link" SW1000SER driver model with 3.9 SP2 .

Each of the services has commands to the shell, for the inspection of memory devices or to start and stop the server.

3.2 Modbus Server

3.3 Modbus Device

3.4 Modbus Sim

Scalar Types

Object Value
Boolean boolean
Byte byte
Short short
Integer int
Long long
Byte ubyte
Short ushort
Integer uint
Long ulong
Float float
Double double
String string

Simple function

Accept the following variables:

Field Description
name Unique name for this function.
device_address Address (UID) of the internal device.
function_code 'func', fixed string.
scan_rate Scan of the function in milliseconds. Always > 100 ms.
f_modbus_address Modbus address for value returned from function.
x_modbus_address Modbus address for variable x.
y_modbus_address Modbus address for variable y.
z_modbus_address Modbus address for variable z.
function String that represents the function.
Example:
suma=12,func,1,input-register:100:float,holding-register:104:float,holding-register:108:float,holding-register:112:float,x+y+z

Random function

Accept the following variables

Field Description
name Unique name for this function.
device_address Address (UID) of the internal device.
function_code 'rand', fixed string.
scan_rate Scan of the function in milliseconds. Always > 100 ms.
f_modbus_address Modbus address for value returned from function.
x_modbus_address Modbus address for variable x.

Example:

suma=12,func,1,input-register:100:float,holding-register:104:float,holding-register:108:float,holding-register:112:float,x+y+z

Signal function

Figure. 4

Figure 5.

Figure 6.

Figure 7.

Accept the following variables:

Field Description
name Unique name for this function.
device_address Address (UID) of the internal device.
function_code 'signal', fixed string.
scan_rate Scan of the function in milliseconds. Always == 100 ms.
f_modbus_address Modbus address for value returned from function.
frequency Modbus address for variable frecuencie.
phase Modbus address for variable y.
amplitude Modbus address for variable z.
signal String that represents the signal.['square','sine','triangular','sawtooth']

Example:

sine=12,signal,100,input-register:100:float,holding-register:104:float,holding-register:108:float,holding-register:112:sine