Skip to main content
Version: current

Modbus Commands

Description

Modbus commands are custom commands that you can setup for a Modbus device. Usually the commands are found in a Modbus specification for the device and you can insert them directly in to SAFE to use them during tests. Modbus commands can be set up for both Modbus RTU and Modbus TCP. The commands are set up in the same way for both types.

Add new Modbus command window

When pressing the + Add Command in the properties for a Modbus device the menu above appears where you can define, test and insert commands. You have multiple options for each command but at its core you can chose the name, address and function code. If you want to learn more about generel Modbus devices in SAFE click below.

Modbus RTU
Modbus TCP

Attributes

Commands+ Add Command
Command NameCommand Address
Function Code3 (Read Holding Register)
Register Type16 bit uint
Description
Factor1
Constant0

Command Name

Command Name is a custom name that you can give the command

Command Address

Command Address is the address of the command given in either a number e.g 45, or a hex number e.g 0x2D

Function Code

Function Code is the commands function specified by the number. It can be set to: 1 (Read Coils) , 2 (Read Discrete Input), 3 (Read Holding Registers), 4 (Read Input Registers), 5 (Write Single Coil), 6 (Write Single Holding Registers), 15 (Write Multiple Coils), 16 (Write Multiple Holding Registers), dependent on what the command should do.

Learn more about function codes

Register Type

Register Type specifies the type of the register. It is dependent on the function code. Using function code 3 which is read holding register the register type can be specified selecting the range of bits from 8 bits to 64 bits and the type meaning bits, uint, int, or float. bits are controlling every single bit individual.

Description

Description is a custom description that you can give the command. With e.g. the range of write intputs etc.

Factor

Factor is a propertied used when converting inputs and output values, from and to real values to modbus values. It is applicable if the register type is uint, int, or float. As Modbus values not always are the same as the flow, angle value etc. For a query a factor is multiplied with the register value after the constant property (see below) has been added:

Query example of value mapping: y = (x + constant) * factor

Constant

Constant is a propertied used when converting inputs and output values, from and to real values to modbus values. It is applicable if the register type is uint, int, or float.As Modbus values not always are the same as the flow, angle value etc. For a write the input value is divided by the factor property (see above) and the constant is subtracted.

Write example of value mapping: y = x / factor - constant