Hi, i'm currently reviewing the Advanced TCP/IP Data Logger software.
I'm trying to log data from a modbus tcp/ip capable device, without much success.
I don't have experience with modbus at all.
I filled in the following in the modbus tcp query and parser :
Device address 16
Function 3
First register 100
Registers to read 2
Request timeout 300
Reponse items :
Data type Floating point (32 bit)
But i'm only getting asci characters, while i should get numeric values.
If someone can help, then please !
The following info is provided by the hardware manufacturer :
3.3 Modbus Operation
The Analog Module can read using Modbus/TCP protocol. This provides a standard means of using the Analog
Module in conjunction with devices and software from other manufacturers. This section contains the information
necessary to communicate with the Analog Module using Modbus/TCP. This is not a tutorial on Modbus and it is
assumed that the reader is already familiar with Modbus. Detailed Modbus information can be found at
http://www.modbus.org.
It is important to note that when the control password in the Analog Module is enabled, Modbus/TCP
communications are disabled. This is because Modbus/TCP does not provide a mechanism for password protection.
Make sure the control password is disabled (default) before using Modbus with the Analog Module.
The Analog Module functions as a Modbus server (slave). Client (master) devices open a connection with the
Analog Module on port 502 (unless another modbus port is selected) and send commands or requests to read the state
of the analog inputs. When the Analog Module receives a command, it will perform the desired function and return a
response. The following commands are available:
Read Holding Registers (Modbus Function Code 03 (0x03)) – read analog values
Multiple commands may be sent without closing and re-opening the connection, but if no data is transferred for 50
seconds the connection will time out. To keep the connection open, a read request can be sent periodically. Two
TCP sockets are available for Modbus communications. If two masters each have a socket open (or a single master
using two sockets) and a third master attempts to open a socket for Modbus communications, the request to open a
third socket will be rejected.
3.3.1 Read Holding Registers (Modbus Function Code 03 (0x03))
This function is used to read the final values (raw values with slope and offset applied) of each input. One,
multiple, or all values can be read at the same time using this function.
Valid address/quantity combinations
Reading these registers requires that the address be in the range of 16 to 30 (0x10 and 0x1E). Also, the
address must be evenly divisible by 2. In other words, only address 0x10, 0x12, 0x14, 0x16, 0x18, 0x1A, 0x1C, and 0x1E are valid. Each value is returned as two registers in IEEE 754 floating point format.
The four data bytes are treated as two individual big endian 16-bit words with the least significant word being sent first.
In other words, the 32 bit floating point number represented as ABCD is sent as CDAB. The following table lists the address that correspond to each input.
Input Address
0 0x10
1 0x12
2 0x14
3 0x16
4 0x18
5 0x1A
6 0x1C
7 0x1E
Note: When the input value is outside the valid range (0 to 5 volts) then a really large value will be
returned, usually a hex value such as 4F80 XXXX will be returned which is roughly 4294967295 when
converted to a float using the IEEE 754 format..
Request:
Modbus/TCP
Transaction identifier (2 Bytes): 0x0001
Protocol identifier (2 Bytes): 0x0000
Length (2 Bytes): 0x0006
Unit identifier (1 Byte): 0xff
Modbus
Function code (1 Byte): 0x03 (read holding registers)
Reference number (2 Bytes): 0x0010 to 0x0016
Register count (2 bytes): 0x02 to 0x08
char write_registers_mb_request[] = {0x00, 0x01, 0x00, 0x00, 0x00, 0x06, 0
Response:
Modbus/TCP
Transaction identifier (2 Bytes): 0x0001
Protocol identifier (2 Bytes): 0x0000
Length (2 Bytes): 0x000B
Unit identifier (1 Byte): 0xff
Modbus
Function code (1 Byte): 0x03 (read holding registers)
Byte count (1 Byte): 0x08
Register values (2 Bytes): 0xffff – (register count x 2 bytes)
Modbus Error:
Function code (1 Byte): 0x83
Exception code (1 Byte): 0x01 or 0x02
Exception codes:
0x01 – Function code not supported
0x02 – Incorrect starting address / quantity of outputs combination
char write_registers_mb_request[] = {0x00, 0x01, 0x00, 0x00, 0x00, 0x0B, 0xff, 0x03, 0x08, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00};