F.A.Q.

Addressing Modbus I/O resources when using Ethernet I/O support of CODESYS V2.3 internal PLC

Written by Mark Olding | Sep 21, 2023 8:20:31 AM

What to know

CODESYS V2.3 internal PLC provides support for communication with Modbus TCP Ethernet I/Os.
It is possible to select devices from 3 producers: Beckhoff, Wago and Weidmuller, and provides also a generic model called STD_MODBUS.

Modbus physical addressing of I/O resources for predefined producers is fixed but in case you require to set a specific Modbus starting address for the I/O resources it is possible, by selecting STD_MODBUS model, to define such addresses at application side.
This can be done by using an apposite Codesys Function block called EXOR_IO_CTRL, included into the EXOR.lib library.

The below table specifies the correspondence between the I/O type and the specific Modbus resource.

I/O Modbus memory resource Data type
Analog Input Input Register 16 bit
Analog Output Holding Register 16 bit
Digital Input Input bit 1 bit
Digital Output Output Coil 1 bit

What to do

The EXOR_IO_CTRL function block must be recalled by the CODESYS application to set the Modbus addressing, the function block can be recalled for each board configured into the PLC configuration of CODESYS application.

res := EXOR_IO_CTRL( wNodeNumber , diFunctionCode , diArgument );

Below you can find a description of each parameter involved into the EXOR_IO_CTRL call.

wNodeNumber = Each board in the CODESYS V2.3 PLC Configuration editor has a progressive Node Number starting from zero; this is assigned by CODESYS and can be seen in the board “Base Parameters”. This parameter identifies the board to which the “diFunctionCode” and “diArgument” parameters will be passed

diFunctionCode

  1. //set access control (for multi master fault tolerant systems) 0=disabled, 1=read-only, 2=full access (default)
  2. //set CoilModbusOffset start address of digital outputsin Modbus Slave
  3. //set InputModbusOffset start address of digital inputs in Modbus Slave
  4. //set HRegModbusOffset start address of analogue outputs in Modbus Slave
  5. //set IRegModbusOffset start address of analogue inputs in Modbus Slave

diArgument
This parameter is passed to the specified board; its significance varies from board to board.
In this specific case the diArgument specifies the number of the Modbus starting address for the specified data area, the possible range is 0 -65535.

diIoCtrlResult
This is the return value; the function returns 0 if the execution was successful, 1 if value is out
of range, 2 if function code is unknown

In attachment you can find a simple CODESYS application that shows the use of this function block.

Applies to

eTOP400 serie, eTOP500 series, CODESYS V2.3 internal PLC.

Generic_ModbusETH_IO.zip

Type: application/octet-stream
Name: Generic_ModbusETH_IO.zip