Slave Mode
Contents
- 1 Slave MODE
- 1.1 Reading values from arrays
- 1.2 Write the values to the arrays
- 1.3 Application
- 1.4 MODBUS_GET_COIL
- 1.5 MODBUS_GET_DISCRETE
- 1.6 MODBUS_GET_HOLDING
- 1.7 MODBUS_GET2_HOLDING
- 1.8 MODBUS_GET_INPUT
- 1.9 MODBUS_GET2_INPUT
- 1.10 MODBUS_SET_COIL
- 1.11 MODBUS_SET_COILS
- 1.12 MODBUS_SET_COILS_ALL
- 1.13 MODBUS_SET_DISCRETE
- 1.14 MODBUS_SET_DISCRETES
- 1.15 MODBUS_SET_DISCRETES_ALL
- 1.16 MODBUS_SET_HOLDING
- 1.17 MODBUS_SET_HOLDINGS
- 1.18 MODBUS_SET_HOLDINGS_ALL
- 1.19 MODBUS_SET2_HOLDING
- 1.20 MODBUS_SET_INPUT
- 1.21 MODBUS_SET_INPUTS
- 1.22 MODBUS_SET_INPUTS_ALL
- 1.23 MODBUS_SET2_INPUT
- 1.24 MODBUS_TCP_SLAVE
Slave MODE
MODBUS SLAVE contains 4 mapping arrays each with 9999 entries. The arrays are:
- Coils (0xxxxx) - cells of type BOOL
- Discretes Input (1xxxxx) - cells of type BOOL
- Holding Registers (4xxxxx) - cells of type WORD
- Input Registers (3xxxxx) - cells of type WORD
Lines 1..9999 correspond to the MODBUS address offset.
The default value for all cells in the arrays is NULL.
Reading values from arrays
Use the MODBUS_GET_COIL, MODBUS_GET_DISCRETE, MODBUS_GET_HOLDING, MODBUS_GET_INPUT, MODBUS_GET2_HOLDING or MODBUS_GET2_INPUT function block to locally read array values.
For remote reading of array values, use the standard MODBUS function via TCP connection.
NOTE: If you try to read a NULL value, the INVALID VALUE error is returned.
Write the values to the arrays
Use the MODBUS_SET_COIL, MODBUS_SET_DISCRETE, MODBUS_SET_HOLDING, MODBUS_SET_INPUT, MODBUS_SET2_HOLDING or MODBUS_SET2_INPUT function block to locally write array values.
Remote values can be writen to Coils and Holding arrays. For write, use standard MODBUS functions via TCP connection.
Application
MODBUS TCP SLAVE is useful if you need to provide a state of your own inputs for remote devices. For example, the switch on/off state of the button is provided for another device.
Similarly, if you need to set the status of the local relay from another device.
MODBUS_GET_COIL
Reads the appropriate COIL value from the internal modbus table of values.
| in | OfsAdr | word | register address (1-9999) | |
| out | ERR | bool | F = No error, T = occur any error | |
| out | ERR_ID | word | Error ID - see Error table | |
| out | Q | bool | return value | |
| out | R_TRIG | bool | for future use - not implemented | |
| out | W_TRIG | bool | for future use - not implemented |
MODBUS_GET_DISCRETE
Reads the appropriate DISCRETE value from the internal modbus table of values.
| in | OfsAdr | word | register address (1-9999) | |
| out | ERR | bool | F = No error, T = occur any error | |
| out | ERR_ID | word | Error ID - see Error table | |
| out | Q | bool | return value | |
| out | R_TRIG | bool | for future use - not implemented | |
| out | W_TRIG | bool | for future use - not implemented |
MODBUS_GET_HOLDING
Reads the appropriate HOLDING register value from the internal modbus table of values.
| in | OfsAdr | word | register address (1-9999) | |
| out | ERR | bool | F = No error, T = occur any error | |
| out | ERR_ID | word | Error ID - see Error table | |
| out | Q | word | return value | |
| out | R_TRIG | bool | for future use - not implemented | |
| out | W_TRIG | bool | for future use - not implemented |
MODBUS_GET2_HOLDING
Reads the two appropriate HOLDING registers value from the internal modbus table of values (lower register with higher weight).
| in | OfsAdr | word | register address (1-9999) | |
| out | ERR | bool | F = No error, T = occur any error | |
| out | ERR_ID | word | Error ID - see Error table | |
| out | Q | dword | return value | |
| out | R_TRIG | bool | for future use - not implemented | |
| out | W_TRIG | bool | for future use - not implemented |
MODBUS_GET_INPUT
Reads the appropriate INPUT register value from the internal modbus table of values.
| in | OfsAdr | word | register address (1-9999) | |
| out | ERR | bool | F = No error, T = occur any error | |
| out | ERR_ID | word | Error ID - see Error table | |
| out | Q | word | return value | |
| out | R_TRIG | bool | for future use - not implemented | |
| out | W_TRIG | bool | for future use - not implemented |
MODBUS_GET2_INPUT
Reads the two appropriate INPUT registers value from the internal modbus table of values (lower register with higher weight).
| in | OfsAdr | word | register address (1-9999) | |
| out | ERR | bool | F = No error, T = occur any error | |
| out | ERR_ID | word | Error ID - see Error table | |
| out | Q | dword | return value | |
| out | R_TRIG | bool | for future use - not implemented | |
| out | W_TRIG | bool | for future use - not implemented |
MODBUS_SET_COIL
Writes the appropriate COIL value to the internal modbus table of values.
| in | OfsAdr | word | register address (1-9999) | |
| in | VAL | bool | value to write | |
| out | ERR | bool | F = No error, T = occur any error | |
| out | ERR_ID | word | Error ID - see Error table |
MODBUS_SET_COILS
Writes the appropriate COILS value to the internal modbus table of values. In the range OfsAddrStart to OfsAddrEnd.
Always OfsAddrStart must be less than OfsAddrEnd.
| in | OfsAddrStart | word | address start (1-9999) | |
| in | OfsAddrEnd | word | address stop (1-9999) | |
| in | VAL | bool | value to vrite | |
| out | Err | bool | F = No error, T = occur any error | |
| out | Err_ID | word | Error ID - see Error table |
MODBUS_SET_COILS_ALL
Write all COILS value cross all registers 1 - 9999.
| in | VAL | bool | value to write | |
| out | ERR | bool | F = No error, T = occur any error | |
| out | ERR_ID | word | Error ID - see Error table |
MODBUS_SET_DISCRETE
Writes the appropriate DISCRETE value to the internal modbus table of values.
| in | OfsAdr | word | register address (1-9999) | |
| in | VAL | bool | value to write | |
| out | ERR | bool | F = No error, T = occur any error | |
| out | ERR_ID | word | Error ID - see Error table |
MODBUS_SET_DISCRETES
Writes the appropriate DISCRETES value to the internal modbus table of values. In the range OfsAddrStart to OfsAddrEnd.
| in | OfsAddrStart | word | address start (1-9999) | |
| in | OfsAddrEnd | word | address stop (1-9999) | |
| in | VAL | bool | value to write | |
| out | ERR | bool | F = No error, T = occur any error | |
| out | ERR_ID | word | Error ID - see Error table |
MODBUS_SET_DISCRETES_ALL
Write all DISCRETES value cross all registers 1 - 9999.
| in | VAL | word | val to write | |
| out | ERR | bool | F = No error, T = occur any error | |
| out | ERR_ID | word | Error ID - see Error table |
MODBUS_SET_HOLDING
Writes the appropriate HOLDING register value to the internal modbus table of values.
| in | OfsAdr | word | register address (1-9999) | |
| in | VAL | word | value to write | |
| out | ERR | bool | F = No error, T = occur any error | |
| out | ERR_ID | word | Error ID - see Error table |
MODBUS_SET_HOLDINGS
Writes the appropriate HOLDINGS value to the internal modbus table of values. In the range OfsAddrStart to OfsAddrEnd.
| in | OfsAddrStart | word | address start (1-9999) | |
| in | OfsAddrStop | word | address stop(1-9999) | |
| in | VAL | word | value to write | |
| out | ERR | bool | F = No error, T = occur any error | |
| out | ERR_ID | word | Error ID - see Error table |
MODBUS_SET_HOLDINGS_ALL
Write all HOLDINGS value cross all registers 1 - 9999.
| in | VAL | word | value to write | |
| out | ERR | bool | F = No error, T = occur any error | |
| out | ERR_ID | word | Error ID - see Error table |
MODBUS_SET2_HOLDING
Writes the two appropriate HOLDING registers value to the internal modbus table of values (lower register with higher weight).
| in | OfsAdr | word | register address (1-9999) | |
| in | VAL | dword | value to write | |
| out | ERR | bool | F = No error, T = occur any error | |
| out | ERR_ID | word | Error ID - see Error table |
MODBUS_SET_INPUT
Writes the appropriate INPUT register value to the internal modbus table of values.
| in | OfsAdr | word | register address (1-9999) | |
| in | VAL | word | value to write | |
| out | ERR | bool | F = No error, T = occur any error | |
| out | ERR_ID | word | Error ID - see Error table |
MODBUS_SET_INPUTS
Writes the appropriate INPUTS value to the internal modbus table of values. In the range OfsAddrStart to OfsAddrEnd.
| in | OfsAddrStart | word | address start (1-9999) | |
| in | OfsAddrStop | word | address stop (1-9999) | |
| in | VAL | word | value to write | |
| out | ERR | bool | F = No error, T = occur any error | |
| out | ERR_ID | word | Error ID - see Error table |
MODBUS_SET_INPUTS_ALL
Write all INPUTS value cross all registers 1 - 9999.
| in | VAL | word | value to write | |
| out | ERR | bool | F = No error, T = occur any error | |
| out | ERR_ID | word | Error ID - see Error table |
MODBUS_SET2_INPUT
Writes the two appropriate INPUT registers value to the internal modbus table of values (lower register with higher weight).
| in | OfsAdr | word | register address (1-9999) | |
| in | VAL | word | value to write | |
| out | ERR | bool | F = No error, T = occur any error | |
| out | ERR_ID | word | Error ID - see Error table |
MODBUS_TCP_SLAVE
This function block starts listening TCP MODBUS slave deamon on the appropriate port.
| in | Port | int | Listening TCP port (default: 502) | |
| in | UnitID | byte | device bus address (1-247) (default: 1) | |
| out | ERR | bool | F = No error, T = occur any error | |
| out | ERR_ID | word | Error ID - see Error table |