Binary Text Functions
The Binary Text functions format binary data packets for use with the TCPDevice function. These functions can be used to send Modbus TCP packets to a Modbus TCP server device. When using these functions to send Modbus packets, the TCPDevice's function Packet Type parameter must be set to Modbus.
Binary Text Functions Example
This example uses two In-Sight systems named SYSTEM0 and SYSTEM1. SYSTEM0 is the Modbus Client, and SYSTEM1 is the Modbus Server.
SYSTEM0 contains the following functions in its spreadsheet:
A2=TCPDevice("SYSTEM1",502,0,4,1000)
B2=QueryDevice($A$0,A2,0,0,0,0,0,6,0,3,20,4,0,1)
A3=BLen(B2)
A4=BGetInt(B2,9,2)
A5=BGetString(B2,10,1)
SYSTEM1 contains the following value:
F4=65
When the spreadsheet on SYSTEM0 executes:
- The TCPDevice function in cell A2 establishes a TCP/IP Modbus connection with SYSTEM1.
- The QueryDevice function in cell B2 sends a Modbus Read Multiple Registers command to SYSTEM1, specifying that the data contained in F4 is to be imported by SYSTEM0 (in binary format).
The results returned in the spreadsheet of SYSTEM0 are as follows:
- A3=11, which is the length of the binary data packet imported from the Modbus Server, SYSTEM1.
- A4=65, which is the integer value contained in cell F4 on SYSTEM1.
- A5="A", which is the integer value in F4 interpreted as a string.
The actual data packets sent/received by the SYSTEM0 in the example above are:
Data |
Command Packet |
---|---|
00 |
|
00 |
|
00 |
|
00 |
|
00 |
|
06 |
Length (6 bytes) |
00 |
|
03 |
Function (Read Multiple Registers) |
20 04 |
Ref# (cell-address = F4) |
00 01 |
Word count (0001) |
Data |
Response Packet |
---|---|
00 |
|
00 |
|
00 |
|
00 |
|
00 |
|
05 |
Length (5 bytes) |
00 |
|
03 |
Function (Read Multiple Registers) |
02 |
Byte count (2 bytes) |
00 65 |
Result value (00 65 in decimal; Modbus uses Big endian) |