SSS ModBus Lib Description E
SSS ModBus Lib Description E
Version 0.1
TABLE OF CONTENTS
1 GENERAL INFORMATION 2
1 General information
The MODBUS Protocol is a client-server communication protocol for the simple exchange of data
between intelligent devices. It was developed by MODICON in 1979 and has established itself as an
industrial standard.
The library MODBUS_UDP.lib was implemented for the programming system „CoDeSys“ from 3S –
Smart Software Solutions GmbH.
It is based on the documents
- MODBUS MESSAGING ON TCP/IP IMPLEMENTATION GUIDE 1.0 and
- the protocol specification „Modicon Modbus Protocol Reference Guide“,
which are both available for download on the web page www.modbus.org.
The library implements the functions
- FC1 Read Coil Status
- FC3 Read Holding Registers
- FC15 Force Multiple Coils (Write Coils)
- FC16 Preset Multiple Registers (Write Multiple Registers)
- FC11 Fetch Comm Event Counter
All other functions of the protocol specification were not implemented in this version of the library.
(They are needed fairly seldom and can partly be replaced by the implemented functions.)
The MODBUS library is based on the libraries SysLibSockets (TCP/UDP-connections) and the
SysLibCallbacks (system calls). Both are delivered along with a 3S runtime system (e.g. SoftPLC).
In order to be able to use the MODBUS library in a CoDeSys application (PLC program) it has to be
inserted in CoDeSys.
To do so open the library manager and choose “insert -> Additional library…“.
Then select the ModBus_UDP.lib. The system libs “SysLibCallback“ and “SysLibSockets“ are then
automatically inserted.
Only the function blocks and the program “CyclicReceive“ of the library may be used by the
application. All other functions are used internally by the library itself as only the library can make
sensible use of them.
- StartAddress : WORD;
- BitCount: WORD; (*Is limited to a maximum of 64 bits.*)
- Enable : BOOL.
- Data: ARRAY[0..7] of BYTE.
The POU reacts by resetting its ready output and is cyclically called by the application. If the response
corresponding to the query is received ready switches to TRUE. In case of error i.e. if the response
was an exception (an error on the device has occurred) the output error is switched to TRUE. The
exception code is then written in data [0].
The execution time of the POU has to be monitored by the application. After the POU has been
executed it has to be called once with Enable := FALSE in order to be able to recognize the next rising
edge.
the DWORD. The IP address “192.168.100.32“ for example is passed as 16#C0A86420. (C0
in hexadecimal is 192 in decimal and so on)
- The target port of the recipient used to receive the telegram. Port No. 502 is defined as the
standard port in the MODBUS protocol specification and has to be supported by all MODBUS
devices. This means the constant 502 is passed here under normal circumstances.
- Enable flag. A rising edge at this entry results in a query being sent out.
POUs parameters are passed at:
- DestAddress : DWORD;
- DestPort : WORD;
- Enable: BOOL.
The POU reacts by resetting its ready output and is cyclically called by the application. If the response
corresponding to the query is received ready switches to TRUE. In case of error i.e. if the response
was an exception (an error on the device has occurred) the output error is switched to TRUE. The
exception code is then written in status. The event counter is incremented on the device on every
successful communication event, except if the counter itself is queried. A communication event is a
query.
The execution time of the POU has to be monitored by the application. After the POU has been
executed it has to be called once with Enable := FALSE in order to be able to recognize the next rising
edge.
The example shipped with the library contains one instance per defined functionblock.
Here you can see how each of these blocks work.
To work with the project, just open it and edit the initializationvalue of the variable TheNode. Use the
IP-address of the desired communicationpartner.
The other values should be used as desired. To determine these values, refer the documentation of
the slave.
Then load the project to the PLC and write one of the flags bDoMbrwmr, bRead, bWrite, bWriteRegs,
bReadRegs or bReadEventCtr to TRUE. Then write the corresponding enableflag to TRUE and the
desired functionblock should set its Readyflag within a short time (if the communicationpartner
answers).
The example and the library were tested together with a WAGO-Ethernet-Koppler 750-842.