Modbus RTU Slave XML Files

From Control Solutions IoTServer Documentation
Jump to navigation Jump to search

Modbus RTU Slave XML Files

Example XML File

<?xml version="1.0" encoding="ISO-8859-1"?>
<configuration>
<server_regs>
<reg addr="0" format="bit" size="1" lowfirst="1" objnum="1"/>
<reg addr="1" format="int" size="1" lowfirst="1" objnum="2"/>
<reg addr="2" format="int" size="2" lowfirst="1" objnum="3"/>
<reg addr="4" format="int" size="4" lowfirst="1" objnum="4"/>
<reg addr="8" format="int" size="1" unsigned="1" lowfirst="1" objnum="5"/>
<reg addr="9" format="int" size="2" unsigned="1" lowfirst="1" objnum="6"/>
<reg addr="11" format="int" size="4" unsigned="1" lowfirst="1" objnum="7"/>
<reg addr="15" format="real" size="2" lowfirst="1" objnum="8"/>
<reg addr="17" format="real" size="4" lowfirst="1" objnum="9"/>
</server_regs>
<remap_regs>
<map localAddr="0" remoteAddr="100"/>
<map localAddr="1" remoteAddr="101"/>
<map localAddr="2" remoteAddr="102"/>
<map localAddr="4" remoteAddr="104"/>
<map localAddr="8" remoteAddr="108"/>
<map localAddr="9" remoteAddr="109"/>
<map localAddr="11" remoteAddr="111"/>
<map localAddr="15" remoteAddr="115"/>
<map localAddr="17" remoteAddr="117"/>
</remap_regs>
</configuration>

Modbus RTU Slave <server_regs> Section

Each line in the server_regs portion of the XML file defines one locally known Modbus “register” which may actually span multiple Modbus addresses.

NOTE: Register configuration does not specify a Modbus register type. This is because all register addresses in the IoT Server can be accessed as any of the standard register types (coil, discrete input, input register, or holding register). Therefore, the value at input register address 0 and holding register address 0 will be the same value. When referenced as a coil or discrete input the same address will appear as 0 if the value is 0, or 1 if the value in anything non-zero. All local registers are 16 bits regardless of how accessed. The 16-bit value will be processed as 0 or 1 for coil or discrete input. Therefore, writing a 1 to an address as a coil will result in a 16-bit integer 1 when the same address is accessed as a holding register.

IMPORTANT: There can be only one definition of a primary register map, but there can be multiple instances of a Modbus server. The secondary servers can only remap the registers defined by the primary server. The primary definition is found in the <server_regs> section while remapping is found in the <remap_regs> section. A secondary server will disregard the <server_regs> section. The primary server can be either a Modbus RTU Slave or Modbus TCP Server.

XML attributes for each register:

addr=”n” – (Json “address”, integer) – Modbus address in the range of 0..65535. Note that Modbus address 0 is most often referred to as “Register 1” or Modicon 40001 if it is a holding register.

format=”xxx” (Json “format”, character string, and “formatCode”, integer) – Specifies the Modbus format in which data should be interpreted. Valid formats for XML and Json are shown below:

XML value Format description
“none” No format defined
“bit” Single bit (coil, discrete only)
“int” Integer (16-, 32-, or 64-bit)
“real” Floating point (single or double)
“char” ASCII character string
“mod10” Schneider Electric Mod10 format

size="n" – (Json “size”, integer) – Specifies the number of 16-bit address locations that make up this “register”. Valid sizes by register format are as follows:

Type Number of registers
Bit 1
Integer 1, 2, 4 (for 16-, 32-, 64-bit)
Real 2, 4 (for single, double precision)
Character 1..63 (registers - 2 characters per register)
Mod10 2, 3, 4

Note: The maximum size for ‘char’ is 63 registers, which means 126 characters is the maximum string length. Size is in registers, not characters.

unsigned=”n” – (Json “unsigned”, integer) – Applies only to integer, and specifies that the integer should be treated as unsigned in “n” is “1”. Integers default to signed (n=0).

lowfirst=”n” – (Json “littleEndian”, integer) – Applies to any register greater than 16 bits (except “char”), meaning the data value consists of 2 or more 16-bit registers. When lowfirst n=1, the least significant data will be found in the lowest numbered or first Modbus register address of the “register” that spans multiple addresses. When lowfirst n=0 (or omitted), the most significant data will be found in the lowest or first Modbus register address. For “char” registers, the start of the string will always be in the lowest or first Modbus address.

objnum=”n” – (Json “localObject”, integer) – Specifies the IoT Server global data object that will be provided via this Modbus register. The global object data type and Modbus register data format do not need to match. Data will be converted as applicable, including numeric to character string conversion.

Modbus RTU Slave <remap_regs> Section

Each line contains simply a local address and a remote address. The local address is expected to reference a register previously created in the server_regs part of the file (by the primary server). The remote address is any valid Modbus address that will be used to reference this local register. There may fewer remap_regs entries than server_regs entries, but generally not more.

localAddr=”n” – (Json “localAddr”, integer) – Specifies local Modbus address, namely the Modbus address established by the Register Configuration above.

remoteAddr=”n” – (Json “remoteAddr”, integer) – Specifies the address of the same register as seen by a remote client (master) querying our local Modbus device.