Overview Modbus Master



This function block configures the Modbus master function. The configuration is divided into slaves and registers. A slave here means a Modbus ID; several slaves can also use the same interface. If several interfaces are configured, they are read out one after the other.

The function block is limited to 128 register rows; if more registers are needed, they can be split across several function blocks. Each register row occupies as many outputs as are set under "Block read count".

Important: Variables must always be connected to the function blocks. When the variables are created, this happens automatically.

The following devices are already integrated as templates. Others can be configured manually.

Inverters / battery:
    Fronius Symo Gen 24 Float (TCP)
    Fronius Symo Gen 24 Float Battery (TCP)
    Fronius Symo Gen 24 Float Smart Meter (TCP)
    Fronius Verto Float (TCP)
    Fronius Verto Float Battery (TCP)
    Huawei (TCP)
    Huawei Battery (TCP)
    Huawei EMMA (TCP)
    Solaredge (TCP)
    Solaredge (TCP) + Smartmeter
    Solax (TCP) + Smartmeter
    SOFAR BTS-5K 10-10 (RTU)
    SOFAR BTS-5K 10-10 Battery (RTU)
    Sungrow SH15/20/25T (TCP)
    Wattsonic Gen3 (RTU)
    Wattsonic Gen3 Battery (RTU)
    Wenergy battery Star289 (TCP)

Wallbox:
    Wallbox KEBA KeContact P30 (TCP)
    Wallbox ABB Terra AC (TCP)
    Wallbox ABB Terra AC (RTU)
    Wallbox Siemens VersiCharge (TCP)
    Wallbox HAGER Witty Plus (TCP)
    Wallbox Alpitronic 150 (TCP)

Heat pump / boiler:
    Ochsner (RTU)
    Fröhling Lamdatronic 3200 (RTU)
    OEKOBOILER (RTU)
    KNV (TCP)
    NIBE S series (TCP)
    Templari

Air conditioning:
    Samsung MIM-B19N (RTU)

Energy meter:
    Energy meter SDM 630 (RTU)
    Energy meter DS100 (RTU)
    EMU Professional II (RTU)
    SINEAX AMx000 (TCP)
    Janitza UMG 604 (TCP)

Weather station:
    Weather station Thies (RTU)

General:
    Victron Cerbo (TCP)


Tip: SOFAR BTS-5K 10-10 with the Block Storage Optimizer

The storage system is controlled through the operating mode „Passive". The controller specifies the power and the device carries it out. Use the template SOFAR BTS-5K 10-10 Battery, which already contains all required registers, but deactivated.

The registers ending in Watt return the same measured values as their siblings, only in watts instead of kilowatts. The optimizer calculates in watts, so these rows are the ones to activate for it.
Connect measured values Grid power W ← ActivePower_PCC_Total_Watt
PV power W ← Power_PV_Total_Watt
Battery power W ← Power_Bat_Total_Watt
State of charge % ← SOC_Bat_Average

Grid power must be positive while energy is drawn from the grid. If the sign is inverted, change the factor of that row from -10 to 10.
Connect the setpoint Power setpoint W → Passive_Manual_Blo and Passive_Manual_Bup

Both registers receive the same value so that the specified power is met exactly. The factor -1 inverts the sign: the optimizer counts discharging as positive, the device counts charging as positive.
Prepare the device Write once:

Energy_Storage_Mode_Control = 3 (passive)
Passive_ManagementMode = 1 (manual)
Passive_Timeout = 60
Passive_Timeout_Action = 1

The time acts as a watchdog: if no setpoint arrives for more than 60 seconds, the device returns to its previous operating mode and controls itself again. This is why the setpoint rows are set to „Write on: cyclic" with ten seconds.
Settings in the optimizer Set maximum charging power and maximum discharging power to the rated power of the device, which is 5000 W for the BTS-5K.
Set the battery capacity to the usable capacity, so 10000 Wh for 10 kWh.
Charging and discharging efficiency about 95 %.
Only set the maximum grid charging power if the battery is to be charged from the grid during a cheap tariff.
Match the depth of discharge The device stops discharging on its own as soon as the state of charge reaches the configured depth of discharge (BatConfig_DepthOfDischarge, 90 % means the device stops at a state of charge of 10 %).

The value „minimum state of charge" in the optimizer should be a few percent above that, about 15 % in this example. Otherwise the optimizer plans a discharge that the device already refuses and the schedule does not work out.





Parameters

Disable With this parameter the block is disabled and the registers are no longer queried. This can be used for diagnostics to temporarily hide certain registers.
Modbus ID
Modbus ID (slave address) of the device, range 0 to 255.
Telegram interval Minimal telegram interval. According to the Modbus specification the minimal telegram interval is 3.5 characters and at least 1.75 ms; this is too short for some devices. This parameter is added to the standard interval.
Timeout
Time to wait for a response from the slave before an error is detected.
Protocol
Selection of the protocol

  • Modbus RTU (RS485)
  • Modbus TCP
Interface
When the protocol Modbus RTU is selected, the interface parameters are set here. Important: Via USB converters only non-critical components may be used.

Important: If several Modbus slaves are operated on one interface, all function blocks must have the same interface parameters.
IP address, port
When the protocol Modbus TCP is selected, the IP address and the port are set here; the standard port for Modbus is 502.
Register addresses Here it can be set whether the register addresses start at 0 or 1. With "start at 1", 1 is subtracted from every register address entered before the telegram is sent. This allows the addresses to be entered exactly as they are listed in the description of the device.
Registers Opens the list of registers. The same list is also opened with a right click on the block. The parameters of the list are described below.
Combine connections Only with TCP. With this option devices with the same IP address and port number are read out via a shared connection. By default all function blocks are read out via separate connections. Combining connections can be necessary with devices that only allow a limited number of simultaneous connections.

Register parameters

The list of registers is opened with the parameter "Registers" or with a right click on the block. In the toolbar of the list, rows can be added, deleted, moved and duplicated, "Template" loads the configuration of an already integrated device and "Ex-Import" exports the list to a file or imports it (see below). If "Register hex" is selected, the register addresses are displayed and entered in hexadecimal.
Active
If this option is not selected, the register is neither queried nor written.
Name
Designation of the register. The name is used when the variables are created automatically.
Register address
Register address according to the description of the slave. Whether the count starts at 0 or at 1 is set with the parameter "Register addresses".
Length
Length of the variable in bits. A Modbus register is always 16 bits (2 bytes). The length therefore defines how many consecutive registers are combined into one value:
  • 16 bit: 1 register (2 bytes)
  • 32 bit: 2 registers (4 bytes)
  • 64 bit: 4 registers (8 bytes)
With register data type "float" at least 32 bits are required, 16 bit is set to 32 bit automatically. 32 bit corresponds to a floating point number with single precision (IEEE 754), 64 bit to one with double precision.

For bit commands (coils, discrete inputs) this value is ignored. When writing registers, only 16 and 32 bits are transmitted.
Block read count
Number of variables to be read with one query (1 to 32). The variables must follow one another without gaps in the slave and all have the same length; each variable occupies its own output of the block. In this way "block read count" times "length" registers are read with one telegram.

When writing registers the number must be 1. For bit commands (coils, discrete inputs) this is the number of coils; with function code 15 the whole block is written with one telegram.
Register data type
Selection between integer and float according to the description of the slave.
Sign
Only with data type integer: selection between unsigned and signed. With 64 bits the value is always read as signed.
Variable data type
EIS type of the connected variable. By default EIS 9 (floating point 4 bytes). See common parameters for a description of the EIS types.
Byte order
  • Big Endian (ABCD): Default setting
  • Mid-Little Endian (CDAB): When reading two registers the hi/lo word is swapped.
  • Little Endian (DCBA): All bytes are swapped.
Function code
Modbus function code according to the description of the slave: 01 read coils, 02 read discrete input, 03 read holding register, 04 read input register, 05 write single coil, 06 write single register, 15 write multiple coils, 16 write multiple register.
Update variable on
  • Change: Default setting. The connected variable is only updated when the value read has changed.
  • Always: The variable is updated after every successful query, even if the value has not changed. This allows the communication to be monitored: if the update stops, the slave no longer responds. This is monitored with the function block KNX monitoring.
Applies to read commands only.
Write on
For write commands only:
  • Change: Variable is written on change.
  • On start + change: Variable is written once at startup of the controller and afterwards on every change.
  • Cyclic: Variable is written cyclically. Time from parameter interval.
Factor
Scaling factor between register and connected variable. When reading the register value is multiplied by the factor, when writing the variable value is divided by the factor. This allows the same factor to be used in both directions; for example 0.001 converts W to kW when reading and kW back to W when writing. Default value: 1.
Offset
When reading, the offset is added after the multiplication with the factor, for example to correct a temperature or meter value. Note: Unlike the factor, the offset does not act symmetrically in both directions, it is added when writing as well. For write registers the offset should therefore remain 0.
Interval
Interval at which the register is read out. For write commands only if "write on" is set to cyclic. With the value 0 the register is queried as fast as the interface allows.

CSV Import / Export

Via the Ex-Import button in the toolbar of the register list all configuration data can be exported and imported again. The format is tab-separated (TSV), UTF-8 encoded. Lines beginning with # are column headers and are ignored on import; the exported header line is written in German. The column names below are used for explanation only.

File structure:

# Protocol<TAB>IP-Address<TAB>Port<TAB>Node-ID<TAB>Register-Offset<TAB>Serial-Interface<TAB>Timeout(ms)<TAB>Telegram-Wait-Time(ms)<TAB>TCP-combine
{9 connection values}
# Active<TAB>Name<TAB>Register-Address<TAB>Length<TAB>Block-Count<TAB>Register-Data-Type<TAB>Sign<TAB>Variable-Data-Type<TAB>Byte-Order<TAB>Function-Code<TAB>Variable-Update<TAB>Write-On<TAB>Factor<TAB>Offset<TAB>Interval
{15 fields per register line}
...

Connection parameters (line 2, 9 fields)

Protocol 0 = Modbus RTU (RS485)   1 = Modbus TCP
IP-Address IP address of the slave (TCP only), e. g. 192.168.1.100. Leave empty for RTU.
Port TCP port (TCP only), default 502. Leave empty for RTU.
Node-ID Modbus slave ID, value range 0255.
Register-Offset 0 = register address starts at 0   1 = register address starts at 1
Serial-Interface Interface parameter string (RTU only), e. g. COM1,9600,8,N,1. Leave empty for TCP.
Timeout(ms) Wait time for response in milliseconds, e. g. 1000.
Telegram-Wait-Time(ms) Additional pause between telegrams in milliseconds, default 0.
TCP-combine 0 = separate connections   1 = combine connections with the same IP

Register parameters (from line 4, 15 fields per line)

Active 0 = register disabled   1 = register active
Name Designation of the register. No tab character allowed.
Register-Address Modbus register address, value range 065535.
Length Length of the variable: 1 = 16 bit (1 register)   2 = 32 bit (2 registers)   3 = 64 bit (4 registers)
Block-Count Number of variables read with one query (1–32). For write commands the value must be 1.
Register-Data-Type 0 = Integer   1 = Float
Sign 0 = Unsigned   1 = Signed (only with data type integer)
Variable-Data-Type Index of the variable type:
0 EIS 0: Constant
1 EIS 1: Switch bit (bit)
2 EIS 2: Dimming (4 bit)
3 EIS 3: Time (3 bytes)
4 EIS 4: Date (3 bytes)
5 EIS 5: Floating point (2 bytes)
6 EIS 6: Relative value 0–100% (1 byte)
7 EIS 7: Drive control (bit)
8 EIS 8: Forced control/priority (2 bit)
9 EIS 9: Floating point (4 bytes) – most common use
10 EIS 10: Counter value 16 bit (2 bytes)
11 EIS 11: Counter value 32 bit (4 bytes)
12 EIS 12: Access control (4 bytes)
13 EIS 13: ASCII character (1 byte)
14 EIS 14: Counter value (1 byte)
15 EIS 15: Character string (14/255 bytes)
16 EIS 16: Counter value (8 bytes)
17 EIS 17: Floating point (8 bytes)
Byte-Order 0 = Big Endian (ABCD) – default
1 = Mid-Little Endian (CDAB)
2 = Little Endian (DCBA)
Function-Code Real Modbus function code (not the index):
1 = Read Coils
2 = Read Discrete Input
3 = Read Holding Register
4 = Read Input Register
5 = Write Single Coil
6 = Write Single Register
15 = Write Multiple Coils
16 = Write Multiple Registers
Variable-Update 0 = only on change   1 = always (even without value change)
Write-On 0 = change   1 = start + change   2 = cyclic
Factor Scaling factor (decimal number), default 1. When reading, the register value is multiplied by the factor, when writing it is divided — the same value can therefore be used in both directions. Example: 0.001 to convert Wh to kWh when reading (and vice versa when writing).
Offset Value added to the register value (decimal number), default 0.
Interval Query interval in milliseconds. For write commands only relevant when Write-On = cyclic.

Example CSV (Fronius inverter, Modbus TCP)

# Protocol	IP-Address	Port	Node-ID	Register-Offset	Serial-Interface	Timeout(ms)	Telegram-Wait-Time(ms)	TCP-combine
1	192.168.1.100	502	1	0		1000	0	0
# Active	Name	Register-Address	Length	Block-Count	Register-Data-Type	Sign	Variable-Data-Type	Byte-Order	Function-Code	Variable-Update	Write-On	Factor	Offset	Interval
1	AC active power [W]	40092	2	1	1	0	9	0	3	0	0	1	0	5000
1	AC Lifetime Energy [kWh]	40102	2	1	1	0	9	0	3	0	0	0.001	0	60000
1	DC voltage [V]	40282	2	1	1	0	9	0	3	0	0	1	0	5000

See also common parameters of all function blocks.