📜 ⬆️ ⬇️

Implementing a MODBUS RTU server using the Fastwel interface module and CoDeSys software

This article describes the integration of the Fastwel programmable logic controller CPM713 from the MODBUS TCP protocol with the Weintek operator panel supporting the serial version of the MODBUS RTU / ASCII protocol using the NIM742 interface module and the CoDeSys ready-made library of the adapted Fastwel environment.

Industrial protocols based on Ethernet networks are becoming increasingly popular. The use of this technology in industrial systems has the advantages, for example, the possibility of flexible modernization and scaling of the system, ease of building architecture and low cost of creating networks [1]. However, the introduction of new technologies in the field of automated process control systems is quite slow, so many devices use traditional industrial networks based on serial buses.

When creating automated systems, it is often necessary to establish communication between devices that support various data exchange protocols or various modifications of the same protocol.
')
For example, the Fastwel CPM713 controller uses MODBUS TCP on the basis of Ethernet networks for data transfer [2]. When working with this controller, the task arose of transmitting and receiving data from the MT6100i operator panel of Weintek, which supports the serial MODBUS RTU / ASCII protocol (Fig. 1).


Figure 1. Integrating the Fastwel I / O controller with the Weintek operator panel

The use of seamless integration is always a higher priority than the use of third-party gateways. Therefore, to solve this problem, an NIM742 interface module from Fastwel was taken, which allows you to connect devices with an RS-232C interface and work with them through the CPM713 user program.

The NIM742 module together with the CPM713 controller user program implements the work of the Modbus RTU slave node. NIM742 is connected to a common line of modules and communicates with the CPM713 controller over the FBUS bus (Fig.2). To enable NIM742 to work with the MODBUS RTU protocol, the CoDeSys FastwelModbusServer.lib library, included in the Fastwel adaptation package, is used.


Figure 2. CPM71x controller with connected modules

Connecting devices


The following components and accessories were used to configure and program the CPM713 controller and the NIM742 interface module:

• ACS00019 configuration cable included with controller,
• free software package CoDeSys from 3S Smart Software Solutions with the adaptation package Fastwel CoDeSys Adaptation for working with Fastwel.

To work with the Weintek MT6100i operator panel, you need:

• connection cables for configuration, which are also included in the delivery,
• free software for configuring EasyBuilder 8000.

The interface module is connected to the operator panel with a connecting cable. This cable can be made independently using the information on the assignment of contacts presented in the instruction manual for the Weintek panel (Fig. 3). For communication with the NIM742 module, the operator panel’s COM3 [RS-232] port was used, using a three-pin data connection: TxD (transmit), RxD (receive) and GND (ground).


Figure 3. Pin assignment of the Weintek 6100i panel connector female SUB-D COM3 [RS-232]

Figure 4 shows the wiring diagram for connecting the contacts of the NIM742 module to the COM3 port of the operator panel [3, 4]. When connecting, it must be borne in mind that the TxD data interface contact of the interface module must be connected to the RxD data receiving contact of the operator panel, and the RxD data contact, respectively, to the TxD panel.


Figure 4. Connection of the NIM742 module to the COM3 port of the operator panel.

Thus, for communication between the operator panel and the NIM742 module, it is necessary to connect the TxD and RxD contacts with the 8th and 7th contacts of the SUB-D connector, and connect the module's ground with the 5th contact (Fig. 5).


Figure 5. Connection diagram of the NIM742 and the Weintek MT6100i operator panel.

Setting the operator panel


The operator panel screen form is created and configured using the free software EasyBuilder8000. When creating a new project, you must specify the model of the Weintek panel used (Fig. 6).


Figure 6. Creating a new project in EasyBuilder8000

Next, when creating a project, you need to edit the system settings and specify the list of devices with which the operator panel is associated (Fig. 7). In our case, this will be a Modbus RTU slave [5].


Figure 7. Project system settings

The following parameters are configured for the client we are using: PLC location, communication type, COM port, speed and mode of operation (Fig. 8). This data will also be indicated in the PLC work program.


Figure 8. New Device Settings

After entering all the communication parameters, you need to add on-screen controls and displays: bit indicators, switches, digital indicators, etc. Figure 9 shows the appearance of the finished test project.


Figure 9. Test panel screen project

These display and control elements are associated with MODBUS variables. The addressing of the Modbus RTU variables is specified in the Weintek Panel Connection Guide to the PLC (Fig. 10).


Figure 10. Modbus variable address table

The MODBUS protocol supports four types of variables:

• discrete input (Discrete Input, 1 bit);
• discrete output (Coil, 1 bit);
• analog input (input register, 16 bit);
• analog output (Holding Register, 16 bit).

To access a specific variable, you must also specify the address on the MODBUS network.

Depending on the type of variable, functions with codes 0x, 1x, 3x, 4x are used to access the data. The code 0x corresponds to the Coil type, which is the output variable for writing the value to the bit variable. The 1x address reads the state of the Discrete Input bit variable. The 3x address corresponds to the Input Register and is used to read the state of the analog variable. The 4x address records the Holding Register analog variable.

Thus, the address of the first switch will be 0x1 (Fig. 11), the second 0x2, and so on. The addresses of all elements of the working screen of the mimic are presented in table 1.


Fig. 11. Setting addresses to the elements of the working mnemonic scheme

Table 1. The address of the elements of the screen work scheme:



PLC program


The test project for CPM713 is based on a ready-made example for FastwelModbusServer.lib, which is part of the CoDeSys adaptation for Fastwel. This library realizes high speed of work, is universal and easy to implement, therefore when organizing data exchange via Modbus RTU protocol, it is recommended to use it. FastwelModbusServer.lib implements the functionality of the slave MODBUS RTU / ASCII network through the controller ports available to the user program. Including, for the organization of access to the MODBUS RTU network through the port of the NIM742 module.

To organize data exchange between the user application and I / O modules, you need to add the I / O system configuration according to the physical connection to the controller. In the test project, we used only the NIM742 module, and the controller configuration is shown in Figure 12.


Fig. 12. List of used modules

The FastwelModbusServer library has a single function FwModbusServerInit (), which is designed to initialize and configure the server. When calling this function, the user sets the communication parameters of the network node and describes the data areas that will be displayed on the address space of the MODBUS server. The server is initialized only from the OnInit system event handler, which initializes the Modbus server once, after power on and before the main user program is started.

The parameters of data exchange through the COM port are specified in the function itself in the field of defining local variables (Fig. 13). Here Port is the port number, BaudRate is the data rate, StopBit is the length of the stop bit, Parity is the check bit mode, ByteSize is the number of bits in a frame, NodeAddress is the device address in the Modbus network.


Fig. 13. Setting the parameters of the COM port

The data exchanged between the main program and the operator panel is specified in the user data types PLC_PRG_IN (what is received over the network) and PLC_PRG_OUT (what is sent to the network). These variables are an array of four variables of the WORD type, the DWORD double word and the real number REAL (Fig. 14).


Fig. 14. Variables for Modbus communication

After the screen form and program have been loaded into the appropriate devices, the operator panel in master mode polls the CPM713 controller. The operating screen of the operator panel in the execution mode is shown in Figure 15.


Fig. 15. The operator screen of the operator panel in the execution mode

Further, if necessary, using the CoDeSys tools, you can collect data received by the CPM713 controller over the MODBUS TCP network and redirect them to the operator panel using the MODBUS RTU protocol. Thus, using the CoDeSys tools and the NIM742 interface module, seamless integration of the MODBUS RTU and MODBUS TCP protocols can be created.

Literature

1. Orlov, S. Ethernet and industrial networks / Sergey Orlov // Journal of network solutions / LAN. - 2013. - № 9. - p. 24-31
2. FASTWEL I / O distributed input / output system. Manual. ftp.prosoft.ru/pub/Hardware/Fastwel/Fastwel_IO/Version2/Doc/FIO_UM.pdf .
3. Fastwel I / O I / O I / O modules. Programmer's Guide. ftp.prosoft.ru/pub/Hardware/Fastwel/Fastwel_IO/Version2/Doc/FIO_Modules_CoDeSys_Adaptation_UM.pdf .
4. Weintek MT-600/8000 series MT-607i, MT-8070iH / MT-6070iH. Installation Instruction
5. User Guide EasyBuilder8000.

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


All Articles