What to know
The Codesys V2.3 internal plc provides the support for the communication with Modbus TCP Ethernet I/Os.
The System provide the possibilities to select the Devices from 3 producers: Beckhoff, Wago and Weidmuller, and provides also a generic model called STD_MODBUS.
The Modbus physical addressing of the I/O resources for the 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 the 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 the 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 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
- //set access control (for multi master fault tolerant systems) 0=disabled, 1=read-only, 2=full access (default)
- //set CoilModbusOffset start address of digital outputsin Modbus Slave
- //set InputModbusOffset start address of digital inputs in Modbus Slave
- //set HRegModbusOffset start address of analogue outputs in Modbus Slave
- //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 iPLC
Type: application/octet-stream
Name: Generic_ModbusETH_IO.pro