The STM requires a
communication protocol to exchange commands and data with the operator
interface on the host PC, and will be known hereafter as ‘STMbus’.
Request and Response
Commands and data are
encoded into formatted message frames and sent via TCP/IP over a dedicated
ethernet link. Communication between the STM and host PC consists of pairs of
messages, a request message and a response message. Either party may
initiate a request, but every request must have an acknowledgement response
from the other.
Message Frame Format
I have decided to base the
Message Frame on ASCII-mode MODBUS (with a few differences, detailed below).
Frame Start |
Function Code |
Data Length |
Data |
LRC |
Frame End |
|
1 char, ‘:’ |
2 chars |
4 chars |
0-65535 chars |
4 chars |
2 chars, CR+LF |
Encoding
Field Description
-
Frame Start indicates the start of a
message frame and is a single colon (:).
-
Function Code indicates the action or service required. A response message sets this
to the same Function Code in the original request message. If the response
needs to indicate an error condition, the MSB of the Function Code will be set
to 1.
-
Data Length is the number of encoded bytes (chars / 2) in the Data field.
- Data
contains the parameters, arguments and other information associated with the
Function Code action.
-
LRC (Longitudinal
Redundancy Check) is an error-checking field. It is the result of a computation
performed on the bytes of the message frame before they are encoded, excluding the Frame Start and Frame End.
It is calculated by successively adding the bytes together, discarding any
carries, and then two’s complementing the result.
-
Frame End
indicates the end of the message frame, and consists of a carriage return
(0x0D) followed by a line feed (0x0A).
- The Data
Length field has been extended to 4 chars (2 bytes) and is always present in
the message frame (instead of being an optional part of the Data field).
-
The maximum
length of the Data field has been extended to 64k chars (32k bytes).
- The LRC has
been extended to 4 chars (2 bytes)