Location3 (data type and function code)
- Last UpdatedSep 16, 2024
- 9 minute read
Location3 specifies the data type and the function code of the PI Point. The data type is an integer value specifying whether the register values in a PLC are interpreted as integers, floats, binary coded decimals, etc. The function code is an integer value that refers to either a corresponding Modbus function code or a custom non-standard function code not supported by the Modbus standards. Since Location3 consists of two different values, the following formula is used to compute the actual value of the Location3 attribute:
Location3 = (data type * 100) + function code
Example: For function code 4 (read input register) and data type 2 (4-digit BCD), Location3 would be 204.
The rest of this section describes all of the data types and function codes in detail, and which combinations of the two values are a valid Location3 attribute.
Data Types
This interface supports a number of integer, floating point, and binary coded decimal data types which can be used with one or more of the supported function codes for reading and writing coils, discrete inputs, and registers. The validation topic in this section describes which function codes are valid with each data type.
The table below describes each of the data types supported by this interface:
|
Data Type |
Comments |
|---|---|
|
1 |
16-bit Integer For real and integer PI points, the 16-bit register is interpreted as a signed integer (-32768 to 32767). |
|
2 |
4-Digit Binary-Coded Decimal (BCD) For input points, the 16-bit register is converted from a BCD to an integer. For output points, the value of the PI point is converted from an integer to a BCD before it is written to the register. BCD representation of integer values between 0 and 9999 are supported. If a negative value is written to a source tag of an output point, UNDER RANGE is written to the output point. If a value greater than 9999 is written to the source tag of an output point, then OVER RANGE is written to the output point. Example: The integer 1925 is represented as a BCD by the hexadecimal number 0x1925 (or by the integer 6437). Each byte of the BCD represents one digit of the integer. |
|
3 |
Log Base 2 The range of values that can be written to an output point are between 0 and 15, inclusive. There is no range checking for input points. Example: If a value of 5 is written to an output point, then 25 or 32 is written to the register. If 32 is read from a register into an input point, it is converted to a value of 5 before it is stored in the input point. |
|
4 |
Floating Point, 32 bit Values stored in the PLC are interpreted as a standard IEEE 4-byte float. For PI 3, the PI point should be configured as a float32. A PLC that understands data type 4, interprets function code 3, 4, and 6 in a nonstandard fashion. The PLC maps a single register to two different registers so that the single register can effectively store four bytes of information instead of two. |
|
5 |
Floating Point Values stored in the PLC are interpreted as a standard IEEE 4-byte float. For PI 3, the PI point should be configured as a float32. A PLC that understands data type 5, interprets function code 3, 4, and 6 in a nonstandard fashion. When data from register 5 is requested, for example, data from both registers 5 and 6 is returned. |
|
6 |
Floating Point Values stored in the PLC are interpreted as a standard IEEE 4-byte float. For PI 3, the PI point should be configured as a float32. This is the most common data type for floating points. Try this data type first. If this data type does not work, try adding the /swap6 parameter to the command line of the interface before trying a different data type. |
|
7 |
4-Byte Integer To avoid problems with OVER RANGE and UNDER RANGE, the PI Point should be configured as an int32 or a float32 in PI 3. See Data Type 1 above for further information regarding the limitations of the different PI Point types. |
|
8 |
Siemens Floating point Values stored in the PLC are interpreted as Siemens floating point format. This format is only required in very specialized cases. For PI 3, the PI point should be configured as a float32. |
|
9 |
Non-standard 4-Byte Integer To avoid problems with OVER RANGE and UNDER RANGE, the PI Point should be configured as an int32 or a float32 in PI 3. Note: This data type assumes that the data source uses 32-bit registers. See Data Type 1 above for further information regarding the limitations of the different PI Point types. |
|
11 |
16-bit Unsigned Integer Data type 11 is identical to data type 1 except that the 16-bit register is interpreted as an unsigned integer (0 to 65535) for integer PI Points. |
|
12 |
16-Digit Binary-Coded Decimal (BCD) (supported for input tags only) Four consecutive 2-byte registers are converted from a BCD to an integer. It is recommended that the integer be stored in a float64 tag to maximize the significant digits. Note, however, that a float64 tag only has 13 digits of precision, whereas a 16-digit BCD has 16-digits of precision. |
|
13 |
64-bit (8-Byte) Signed Integer (supported for input tags only) It is required that the integer be stored in a float64 tag to maximize the significant digits. However, a float64 tag only has 13 digits of precision. When data type 13 is used, the ModbusE interface combines the values from 4-consecutive 2-byte registers to come up with an 8-byte signed integer. |
|
14 |
Double precision Enron floating point. This is the double precision counterpart to data type 4. |
|
15 |
64-bit (8-Byte) Unsigned Integer (supported for input tags only) It is required that the integer be stored in a float64 tag to maximize the significant digits. However, a float64 tag only has 13 digits of precision. When data type 15 is used, the ModbusE interface combines the values from 4-consecutive 2-byte registers to come up with an 8-byte unsigned integer. |
|
16 |
Double precision floating point The interface interprets four consecutive 2-byte registers as an 8-byte floating point number. By default, the interface uses a custom byte order that places the first two bytes it receives after the following six bytes before interpreting the number as an IEEE 754 double-precision floating point number. To interpret the eight byte sequence directly as an IEEE 754 double-precision floating point number without reordering the bytes, specify the "swap" parameter in the PI point's extended descriptor (ExDesc). Alternatively, you can use the Modbus Interface Configurator to enable byte swapping for data type 16. |
|
101 to 199 |
Data types 101 to 199 are reserved for string data. Data type 101 is used to read 1-byte strings; data type 102 is used to read 2-byte strings; and so on. For example, to read a 5-byte string from an input register (Modbus function code 4) one would set the Location3 attribute to 10504 because Location3 is equal to (Data Type * 100) + Function Code. |
Function codes
This interface supports all of the standard Modbus function codes for reading coils, discrete inputs and registers. It also supports the function codes to write to a single coil or register and to write to multiple contiguous coils and registers. In addition, it supports the custom function code 65 to read HTMUX floating point values.
The table below describes each of the function codes supported by this interface:
|
Function Code |
Description |
|---|---|
|
1 |
Read Coil Status to input tag. |
|
2 |
Read Input Status to input tag. |
|
3 |
Read Holding Register to input tag. |
|
4 |
Read Input Register to input tag. |
|
5 |
Write Single Coil using output tag. |
|
6 |
Write Single Holding Register using output tag. Note: The interface will convert function code 6 to 16 when it is necessary to send floating point numbers to two consecutive registers. |
|
15 |
Write Multiple Coils using output tags. |
|
16 |
Write Multiple Registers using output tags. |
|
65 |
Read floating point value from 4-byte register. There is no data type associated with function code 65 because the interpretation of the register value is determined by the function code itself. Hence, Location3 should just be assigned a value of 65 when this function type is required. |
Byte and Word Swapping
Note: The updates to byte- and word- swapping in version 4.2.x of the interface are entirely backwards compatible. In particular, the swap ExDesc parameter and the /swap4, /swap6, /swap7, /swap13, /swap15, /swap16, and /swapstring parameters all work the same way they did in earlier versions.
In cases where the interface appears to send incorrect values to the PI Data Archive, one common cause is that the PLC in question sends the bytes representing the values in an order that is different from what the interface expects.
Unfortunately, the Modbus protocol does not explicitly define how 4- and 8-byte values are to be stored across multiple registers. As a result, different PLCs use different conventions, complicating the task of recombining the bytes that they send to form the correct value.
For compatibility with as many PLCs as possible, the interface allows the user to configure how the bytes received from a PLC are arranged to form the value that it sends to the PI Data Archive. The user can do this on a point-by-point basis via the optional swapwords and swapbytes Extended Descriptor (ExDesc) parameters:
swapwords: reverse the order of the 2-byte words (registers) that constitute a 4-byte value
swapbytes: reverse the order of the bytes within each 2-byte word
These parameters can also be combined to swap both bytes and words when writing values to the point.
To understand how these parameters work, consider the following example: suppose we have configured a PI point to read a 4-byte floating-point number from the analog input registers of our PLC at addresses 7 and 8.
|
Trouble incorrect floating-point values |
||
|---|---|---|
|
Attribute |
Value |
Interpretation |
|
PointType |
float32 |
Stored in PI as IEEE 754 32-bit floating point number. |
|
Location3 |
604 |
Read 4-byte floating-point (data type 6) from analog inputs (function code 4) |
|
Location5 |
7 |
The value to read starts at the 7th register on the PLC |
We expect the value written to this point to be approximately 102.4, but instead we see that the interface has written the value -3.882078e-6 to the PI Data Archive. It appears that the PLC is sending the bytes to the interface in an order that the interface is not currently configured to expect.
Note: To use the following troubleshooting procedure, it is important to see the full precision of the floating-point number that the interface sends to the PI Data Archive. If you are using PI System Management Tools (SMT) or PI ProcessBook to read values, temporarily set the "Display Digits" attribute of the point to -7 for 4-byte floating-point values or -15 for 8-byte floating-point values to make sure all the significant digits are visible.
To troubleshoot, we use an online tool to convert the decimal number -3.882078e-6 to hexadecimal format using the IEEE 754 standard. (Searching for "IEEE floating-point converter" yields several options.) The hexadecimal representation of this number is 0xb68242cc, where the leading " 0x" denotes that this is a hexadecimal value and each pair of digits following it represents one byte. The bytes that make up this number are therefore:
We see directly the contents of the two registers that the PLC sent the interface: b6 82 for register 7 and 42 cc for register 8. We can now experiment with reordering the bytes and words in our IEEE 754 converter to see if we can find the correct representation of our value.
|
Swapping Bytes and Words of Incorrect Value |
||
|---|---|---|
|
Swap options |
New byte order |
Interpreted as 32-bit floating-point number |
|
Original value |
b6 82 42 cc |
-3.882078e-6 |
|
If words were swapped… |
42 cc b6 82 |
102.35646 |
|
If bytes within words were swapped… |
82 b6 cc 42 |
-2.6859735e-37 |
|
If both bytes and words were swapped… |
cc 42 82 b6 |
-5.0989784e7 |
It appears that swapping the order of the 2-byte words will give the correct value, 102.35646. To make this change, specify swapwords in the point's Extended Descriptor (ExDesc).
It is usually the case that the same swapping rule must be applied to all points of the same type on the PLC in question. Additionally, for technical reasons it is more often necessary to swap words than bytes. For these reasons, the interface provides PLC-level parameters to configure word swapping for all points of a given data type on a particular PLC. For example, rather than adding swapwords to the ExDesc of every point with data type 6 on a specific PLC, the user can simply specify /swap6 for that PLC in the configuration file. Likewise, the interface also provides the /swap4, /swap7, /swap13, /swap 15, /swap16, and /swapstring parameters to swap the word order for values of data types 4 (another floating-point type), 7 (4-byte integer), 13 (8-byte signed integer), 15 (8-byte unsigned integer), and 16 (8-byte floating-point), and for string values, respectively.
Note: The swapbytes ExDesc parameter is applied in addition to the /swap# configuration file parameters. If you specify a /swap# parameter in the configuration file and swapbytes in a point ExDesc, the original value is incorrectly written to the point.