API operation with escaped characters (AP parameter = 2)
Setting API to 2 allows escaped control characters in the API frame. Due to its increased complexity, we only recommend this API mode in specific circumstances. API 2 may help improve reliability if the serial interface to the device is unstable or malformed frames are frequently being generated.
When operating in API 2, if an unescaped 0x7E byte is observed, it is treated as the start of a new API frame and all data received prior to this delimiter is silently discarded. For more information on using this API mode, see the Escaped Characters and API Mode 2 in the Digi Knowledge base.
API escaped operating mode works similarly to API mode. The only difference is that when working in API escaped mode, the software must escape any payload bytes that match API frame specific data, such as the start-of-frame byte (0x7E). The following table shows the structure of an API frame with escaped characters:
Frame fields | Byte | Description | |
---|---|---|---|
Start delimiter | 1 | 0x7E | |
Length | 2 - 3 | Most Significant Byte, Least Significant Byte | Characters escaped if needed |
Frame data | 4 - n | API-specific structure | |
Checksum | n + 1 | 1 byte |