Promotic
WikipediaLinkedInYoutubeTwitterFacebook

PmModbusMr - Driver for communication by Modbus Master protocol

Before using this driver in the PROMOTIC application it is highly recommended to read the chapter: Communicaton using the PROMOTIC drivers.
 
Basic properties of the driver:
- Using this driver is bound to purchase the license: PmModbusMr. With the freeware version PmFree, or when developing the application (with development environment for tersting purposes), this component is always functional.
- The communication is done via Ethernet or via standard serial link (COM1, COM2 ...).
- The PROMOTIC application is the MASTER (i.e. it initiates the data transfer) from this communication point of view. For SLAVE communication can be used: PmModbusSl - Driver for communication by Modbus Slave protocol.
- The driver is incorporated into the PROMOTIC system by means of the PmComm object.

Driver supports the usage of both PmCommMsg and PmCommData objects. For common data transfers, it is easier to use the PmCommData object.

For easy integration of this driver into the application it is handy to use: Preconfigurations in group "Modbus protocol"

- This is a network communication, i.e. one PmComm object can communicate with multiple devices (the protocol supports multiple device addressing).
- Driver supports the TCP, RTU and ASCII transfer modes.
- It is possible to transfer standard 1-bit (bits) and 16-bits (registers) values and less standard 32-bits values of the float and long type and 64-bit values (float double precision).
- The driver can also be used for the JBUS protocol. The JBUS protocol is the subset of the Modbus RTU protocol. All implemented messages in this driver (see below) are also supported by the JBUS protocol.
 
Following Modbus data types are supported:
- b = Bit (1Bit): stored in the PLC on 1 bit. In the PROMOTIC application it is represented by the Boolean data type.
- W = Word (2Byte Unsigned Integer): stored in the PLC on 16 bits (value from 0 to 65535). In the PROMOTIC application it is represented by the Long data type.
- I = Int (2Byte Signed Integer): stored in the PLC on 16 bits (value from -32767 to +32767). In the PROMOTIC application it is represented by the Integer data type.
- L1 = Long type 1 (4Byte Signed Integer): stored in the PLC as 32 bits. In the PROMOTIC application it is represented by the Long data type. Only for messages of the 03, 04, 16 type. The binary format of this type is the same as in PC, only the bytes order is changed (reversed) (bytes order in PC:1234 and in PLC:2143). Used for example in Modicon, Wago PLCs, etc.
- L2 = Long type 2 (4Byte Signed Integer): Identical as the previous data type, only the bytes sequence is different (bytes order in PC:1234 and in PLC:4321). Used for example by the JUMO PLCs.
- L3 = Long type 3 (4Byte Signed Integer): Identical as the previous data type, only the bytes order stays the same - as in the PC (bytes order in PC:1234 and in PLC:1234).
- R = Float type 1 (4Byte - IEEE 754): stored in the PLC on 32 bits. In the PROMOTIC application it is represented by the Single data type. Only for messages of the 03, 04, 16 type. The binary format of this type is standardized by IEEE-754, so it is the same as in PC, only the byte order is changed (bytes order in PC:1234 and in PLC:2143).
- R2 = Float type 2 (4Byte - IEEE 754): Identical as the previous data type, only the bytes sequence is different (bytes order in PC:1234 and in PLC:4321). Used for example by the ABB AC500 PLCs.
- R3 = Float type 3 (4Byte - IEEE 754): Identical as the previous data type, only the bytes order stays the same - as in the PC (bytes order in PC:1234 and in PLC:1234).
- D1 = Float Double-precision type 1 (8Byte - IEEE 754): stored in the PLC on 64 bits. In the PROMOTIC application it is represented by the Double data type. Only for messages of the 03, 04, 16 type. The binary format of this type is standardized by IEEE-754, so it is the same as in PC, only the byte order is changed (bytes order in PC:12345678 and in PLC:21436587).
- D2 = Float Double-precision type 2 (8Byte - IEEE 754): Identical as the previous data type, only the bytes sequence is different (bytes order in PC:12345678 and in PLC:87654321).
- D3 = Float Double-precision type 3 (8Byte - IEEE 754): Identical as the previous data type, only the bytes order stays the same - as in the PC (bytes order in PC:12345678 and in PLC:12345678).
 

Recommended parameters values:

Recommended values for the Serial link parameters:
Number of data bits8 for RTU mode, 7 for ASCII mode
Number of stop bits1 if parity is used, 2 if parity is NO
Recommended values for the Ethernet parameters:
TCP/UDP port number502 (for MODBUS TCP/IP data type)
Ethernet transfer typeTCP (for MODBUS TCP/IP data type)
Description and recommended values for the Protocol parameters:
Protocol data typeOnly for Ethernet. Specifies the protocol data form. It is possible to set:
MODBUS TCP/IP - Standard Ethernet MODBUS communication. Compared to the standard serial link data a special header is included and it is transfered via Ethernet TCP on port 502.
The same data as for serial link - This option can be selected, for example, if the device is equipped with the serial link and it is connected to the Ethernet through the RS232/Ethernet converter. If the converter does no modifications to the transmitted data, then it is a very easy way how to communicate via Ethernet with devices not equipped with Ethernet interface.
Response receipt timeoutOnly for serial link. The recommended value is for example 2000 ms. The time (in milliseconds) the driver is waiting for the response on sending the message. If no response comes during this time, the transfer of the message is terminated (event onEndOfTransfer fires with error 24 or 66).
Transfer modeThe MODBUS protocol includes two transfer options.

In the parameters of the PmCommMsg object message, the mode can be changed (for special cases, when necessaray to communicate with multiple PLCs in different modes).

RTU - Most commonly used transfer mode, where the data is being transfered in binary form.
ASCII - The transfer mode, where the data is transfered in ASCII form. This mode is not supported for MODBUS TCP/IP.

The communication description by the PmCommData objects

The PmCommData objects can be used for this driver. For usual data transmissions it is more favourable than using the PmCommMsg object.

The variables in the PmCommData object (or even better the variables in the PmData object with ExtComm data extension) can be of arbitrary number, type and order. The driver uses optimalised internal communication messages for reading the data from the device.

All variables are read (if the Data refresh enabled configurator is enabled). When writing to the variable, only the single value is sent (if the Auto write when writing to item configurator is enabled).

 
Description of the ItemID configurator:

ItemId is the text identifier of the item that is used for addressing the value in the device. The ItemID configurator tells the driver how to receive or send the item value. The text can be written manually, or it can be assembled in the window opened by the button to the right of the configurator. Macro expression can be used for input (it is evaluated while the application is launching).

The text can be for example "dev2.Ri33.W" representing:

dev2 = the item is in the PLC (device) with an address of 2. The devD (=default address) can be entered instead of the number and the PLC address will be determined according to the "Default PLC address" configurator.
Ri33 = is from the data area "Input registers on relative address 33. The address 33 is only relative address. During communication, the value defined in the "Area base addresses" configurator is added to this number.

A list of data areas:

- Bo = the area "Coil status / Output bits".
For data receive the Modbus function is used: FN01 (Read Coil Status, Read Output Bits).
For data write the Modbus funkce is used: FN05 (Force Single Coil, Write 1 Bit).
- BoM = the area "Coil status / Output bits".
For data receive the Modbus function is used: FN01 (Read Coil Status, Read Output Bits).
For data write the Modbus funkce is used: FN15 (Force Multiple Coils, Write n Bits).

The difference from the Bo area is only the write method (the FN15 is used instead of FN05).

- Bi = the area "Input status / Input bits".
For data receive the Modbus function is used: FN02 (Read Input Status, Read Input Bits).
Data write is not possible..
- Ro = the area "Holding/Output registers".
For data receive the Modbus function is used: FN03 (Read Holding/Output Registers).
For data write the Modbus funkce is used: FN16 (Preset Multiple Registers, Write n Registers).
- RoS = the area "Holding/Output registers".
For data receive the Modbus function is used: FN03 (Read Holding/Output Registers).
For data write the Modbus funkce is used: FN06 (Preset Single Register, Write 1 Register).

The difference from the Ro area is only the write method (the FN16 is used instead of FN06).

Caution: The function FN06 cannot write 4 and more byte values (for example data types Long and Float).

- RoB = the area "Holding/Output registers". For transfer of individual bits.
For data receive the Modbus function is used: FN03 (Read Holding/Output Registers).
For data write the Modbus funkce is used: FN22 (22-Mask Write Register).

Example: RoB38.0 is read/write of 0.bit in register 38.

- Ri = the area "Input registers.
For data receive the Modbus function is used: FN04 (Read Input Registers).
For data write the Modbus funkce is used: FN16 (Preset Multiple Registers, Write n Registers).
- RiS = the area "Input registers.
For data receive the Modbus function is used: FN04 (Read Input Registers).
For data write the Modbus funkce is used: FN06 (Preset Single Register, Write 1 Register).

The difference from the Ri area is only the write method (the FN16 is used instead of FN06).

Caution: The function FN06 cannot write 4 and more byte values (for example data types Long and Float).

W = in PLC has the data type Word
 
Description of the PmCommData > Parameters > Special Parameters configurator:
Default PLC addressThe address defined here can be used for definitions in the ItemID configurator for the variables in this object (i.e. the variables on the Data page or in the ExtComm data extensions). The address can be defined in ItemID:
- as for example dev1... - then the value will be read from the PLC with address 1.
- or devD... - the "D" character means default, and the address is taken from this configurator.

This parameter can be modified and read in runtime by the methods: SetSpecParam("SlaveAddr") and GetSpecParam("SlaveAddr").

Area base addressesHere, the addresses of the beginnings of the data areas are entered (Bo, Bi, Ro, Ri).

The addresses for these areas are preset to 0. (if the preconfiguration for a specific device is not used - see Preconfigurations / Communications / Modbus protocol). For another PLC types the addresses my be different (e.g. the addresses do not begin with 0, but with 1 or 40001, etc.).

While communicating, the "Data item address" is modified as a sum of the relative item address (defined in the ItemID identificator) and the area base address.

Max.number of variables received in one messageFor each area (Bo,Bi,Ro,Ri) the maximum number of variables to be transmitted in one communication message is defined here. These values depend on the device type to communicate with (some devices support transmissions of low register numbers in a single message, other support higher numbers) - this specification can be found in the device documentation or must be tried/tested.

The preset values are 64 for Bo and Bi, 32 for Ro and Ri (if the preconfiguration for a specific device is not used - see Preconfigurations / Communications / Modbus protocol).

The preconfigured values are very low. Increasing these values (if the device allows it) may cause higher communication speeds, because the transmitted data can be sent in a lower number of communication messages.

The communication description by the PmCommMsg objects

The PmCommMsg obejcts can be used for special communications, that cannot be executed by the PmCommData object. For example by the "XX-User defined opened function" type message it is possible to compose any Modbus message types, that are not directly supported by the driver.
 
The address of the SLAVE station from which it is read or to which it is written, must be entered in each message. This address is entered in the Data-sent page of the message in the "Slave" variable (e.g. for the Modicon, valid slave addresses are in the range of 0-247). The address 0 is used for the broadcast, i.e. for the messages received by all stations (if the Modbus protocol is used on higher network level, the broadcast may not be allowed).

Further the address of the variable in the station is entered in the Data-sent in the "Addr" variable. The address value is supposed to be from 0 by default. But some devices (e.g. Modicon, GE-Fanuc) are addressed from 1 and that's why it is necessary to enter the Addr value decreased by 1 at these stations.

The maximum number of values (states, registers) in one message differs according to the PLC device. It can be for example 32, 125, 128, 1024, etc.

 
The list and description of the communication messages:
01-Read Coil Status (Read Output Bits): This message reads n output states (1-bit values) from the specified address Addr.
02-Read Input Status (Read Input Bits): This message reads n input states (1-bit values) from the specified address Addr.
03-Read Holding Registers (Read Output Registers): This message reads n output registers (16-bits values) from the specified address Addr.
04-Read Input Registers: This message reads n input registers (16-bits values) from the specified address Addr.
05-Force Single Coil (Write 1 Bit): This message writes into one state (1-bit values) to the specified address Addr.
06-Preset Single Register (Write 1 Register): This message writes into one register (16-bits values) to the specified address Addr.
15-Force Multiple Coils (Write n Bits): This message writes into n state (1-bit values) from the specified address Addr.
16-Preset Multiple Registers (Write n Registers): This message writes into n registers (16-bits values) from the specified address Addr.
22-Mask Write Register (Modify Register Using both AND & OR Masks): This message writes defined individual bits into a single register (16-bit values) by using the AND and OR mask.
There are following variables on the Data-sent page:
Slave - Address of the slave device, i.e. PLC address.
Addr - the address of the register where the bits will be written.
AND_Mask - mask of bits to be zeroed
OR_Mask - mask of bits to be set
There is no varible on the Data-received page.
XX-User defined opened function:

User-defined Modbus message. It can be used for message types that are not otherwise supported by this driver. The user can define the complete content of the message (received or sent), but the order and data type of the DataX variables must be observed carefully.

The variables DataX (in Data-sent and in Data-received) represent data in Modbus protocol from the character Function (without this character) and up to the character CRC (for serial RTU, without his character) or up to the end of the message (for Modbus TCP/IP). For ASCII transfer mode the data is defined the same way as for RTU mode and the driver then transforms such data into ASCII form.

There are following variables on the Data-sent page:
TXLength - The size of transmitted data (in bytes). This is not the total size of the sent mesage, but just the portion that is stored in the DataX variables on this page. The value -1 means that all DataX variables on this page are to be sent.
RXLength - Maximum expected size of accepted data (in bytes). This is not the total size of the received mesage, but just the portion that will be stored in the DataX variables on the Data-received page. The value -1 means that the expected size will be calculated as the total lenght of all DataX variables on the Data-received page.

- if the size is defined less than the currently received data then an error occures and the received data is not processed.
- if the size is defined greater than the currently received data then the transfer takes longer (the system will wait for timeout), but the received data is processed.

Slave - Address of the slave device, i.e. PLC address.
Function - Number (code) of modbus function. For example 1 = Read Coil Status, 17 = Report Slave ID etc.
DataX - User-defined data that are to follow after the function number (without the control sum). There may be multiple variables (of different data types) on the page, but only those that fit into the message will be sent (i.e. according to the value in TxLength).
There are following variables on the Data-received page:
Length - The ammount of received data (in bytes). It is not the total size of the received message, but only the portion that is stored in DataX variables on this page.
Function - The number (code) of Modbus function. Normally, there should be the same value here as on the Data-sent page.
DataX - Received data. There may be multiple variables (also different data types) on this page, but only those that were in the received message will be filled.
© MICROSYS, spol. s r. o.Tavičská 845/21 703 00 Ostrava-Vítkovice