Modbus server functions#
Modbus server can be used for reading and writing values from / to HOLDING_REGISTER type values in Fx. There are 65536 16-bit registers available (addresses 0..65535)
Registers may be accessed through ethernet using modbus TCP protocol. Valid message types are:
READ_MULTIPLE_REGISTERS (3) for reading group of registers
WRITE_MULTIPLE_REGISTERS (16) for writing group of registers
WRITE_SINGLE_REGISTER (6) for writing single register
As default the server listenes to TCP port 502 and it may be changed in firewall settings. Fx itself can read and write registers using IEC functions.
Note
Max value for INT variable in IEC compiler is 32767 and bigger values must be
written in hexadecimal format (e.g 32769 equals 16#8001)
given like this : WORD_TO_INT(32769).
Values bigger than 32767 are displayed as negative values in OpenPCS watch window. Hexadecimal display format may be selected from menu “View-Number format”.
SetModbusIntF#
- SetModbusIntF(Address:=0, Value:=0)#
- Parameters:
Address (INT) – Register number 0 .. 65535.
Value (INT) – Register value.
- Return type:
INT
- Returns:
0 =
1 =
GetModbusIntF#
- GetModbusIntF(Address:=0)#
- Parameters:
Address (INT) – Register number 0 .. 65535.
- Return type:
INT
- Returns:
Register value
Note
IEC complier interpretes values over 32767 as negative. If you want to use such value as unsigned do this. Read first value to WORD variable using GetModbusWordF and assign it to DINT variable using WORD_TO_DINT().
SetModbusWordF#
- SetModbusWordF(Address:=0, Value:=0)#
- Parameters:
Address (INT) – Register number 0 .. 65535.
Value (WORD) – Register value.
- Return type:
INT
- Returns:
0 =
1 =
GetModbusWordF#
- GetModbusWordF(Address:=0)#
- Parameters:
Address (INT) – Register number 0 .. 65535.
- Return type:
WORD
- Returns:
Register value
SetModbusDIntF#
- SetModbusDIntF(Address:=0, Value:=0)#
- Parameters:
Address (INT) – Register number 0 .. 65535.
Value (DINT) –
Register value.
Highest 16 bits are saved at Address and 16 lowest bits at Address + 1
- Return type:
INT
- Returns:
0 =
1 =
GetModbusDIntF#
- GetModbusDIntF(Address:=0)#
- Parameters:
Address (INT) – Register number 0 .. 65535.
- Return type:
DINT
- Returns:
Register value
SetModbusDWordF#
- SetModbusDWordF(Address:=0, Value:=0)#
- Parameters:
Address (INT) – Register number 0 .. 65535.
Value (DWORD) –
Register value.
Highest 16 bits are saved at Address and 16 lowest bits at Address + 1
- Return type:
INT
- Returns:
0 =
1 =
GetModbusDWordF#
- GetModbusDWordF(Address:=0)#
- Parameters:
Address (INT) – Register number 0 .. 65535.
- Return type:
DWORD
- Returns:
Register value
SetModbusRealF#
- SetModbusRealF(Address:=0, Value:=0.0, Multiplier:=0)#
- Parameters:
Address (INT) – Register number 0 .. 65535.
Value (REAL) –
Register value.
Highest 16 bits are saved at Address and 16 lowest bits at Address + 1
Multiplier (REAL) –
Multiplier used for conversion (0 = no conversion)
If Multiplier is bigger than zero then REAL value is saved to registers as DINT so that first REAL value is multiplied by Multiplier and then it is converted to DINT.
If you want to save REAL value without conversion to DINT then set Multiplier:=0. Format used at save is then IEEE Standard for Floating-Point Arithmetic (IEEE 754).
- Example:
Save DINT value 34567
SetModbusRealF(Address:=10, Value:=345.67, Multiplier:=100)
- Return type:
INT
- Returns:
0 =
1 =
GetModbusRealF#
- GetModbusRealF(Address:=0)#
- Parameters:
Address (INT) – Register number 0 .. 65535.
- Return type:
REAL
- Returns:
Register value