Spectrum Controls 1769sc-HART Modules User Manual
Page 113
Chapter 8: Programming Examples
User’s Manual 0300217-03 Rev. A
8-3
8.1.3 Swap Byte Order
This ladder sample demonstrates how to reverse the order of the bytes for a floating point
tag and then convert it to 4 consecutive SINT tags, so that it can be used in a HART
message.
If the HART message being sent or received using the pass-through
command contains floating point values, the order of the bytes
must be reversed.
Figure 8-3 (Change Byte Order)
8.1.4 Converting Unpacked ASCII to Packed ASCII
Packed ASCII is a HART-specific 6-bit character code representing a subset of the
ASCII character code set (see table below). Produced by compressing four packed
ASCII characters into three 8-bit bytes, packed ASCII strings must be a multiple of 4
characters (3 bytes) and must be padded out to the end of the data item with space
characters. For example, 4 space characters at the end of a string would appear as the 3
bytes: 0x82, 0x08 and 0x20.
Construction of Packed ASCII characters:
Constructing a packed ASCII string is a simple matter of discarding the most significant
two bits from each character and compressing the result:
1. Truncate Bits 6 and 7 of each ASCII character.
2. Pack four, 6 bit-ASCII characters into three bytes.
3. Repeat until the entire string is processed.
The algorithm can be implemented in ladder by masking and shifting four 6-bit
characters into a double word register then moving the three bytes into the packed ASCII
string.
Reconstruction of ASCII characters:
Unpacking packed ASCII strings requires flipping some bits in addition to
uncompressing the string itself. To unpack a packed ASCII string:
1. Unpack the four, 6-bit ASCII characters.
2. For each character, place the complement of bit 5 into bit 6.
3. For each character, reset bit Bit 7 to zero.
4. Repeat until the entire string is processed.
This algorithm can be implemented by loading three bytes into a 24-bit register and
shifting the four 6-bit characters into the string. Parse the resulting character to flip bit 6
!
Attention