![Spellman ST SERIES Скачать руководство пользователя страница 66](http://html.mh-extra.com/html/spellman/st-series/st-series_instruction-manual_1346476066.webp)
101501-565 Rev C
Page 35 of 58
6.0
SERIAL COMMANDS – RS-232
6.1
SERIAL INTERFACE PROTOCOL
Serial communications will use the following protocol:
<STX><CMD><,>ARG><,><CSUM><ETX>
Where:
<STX>
= 1 ASCII 0x02 Start of Text character
<CMD>
= 2 ASCII characters representing the command ID
<,>
= 1 ASCII 0x2C character
<ARG>
= Command Argument
<,>
= 1 ASCII 0x2C character
<CSUM>
= Checksum (see section 6.3 for details)
<ETX>
= 1 ASCII 0x03 End of Text character
6.2 COMMAND
ARGUMENTS
The format of the numbers is a variable length string. To represent the number
42, the string ‘42’, ‘042’, or ‘0042’ can be used. This being the case, commands
and responses that carry data are variable in length.
6.3 CHECKSUMS
The checksum is computed as follows:
Add the <CMD>, <,>, and <ARG> bytes into a 16 bit (or larger) word.
The bytes are added as unsigned integers.
Take the 2’s compliment (negate it).
Truncate the result down to the eight least significant bits.
Clear the most significant bit (bit 7) of the resultant byte, (bitwise AND with
0x7F).
Set the next most significant bit (bit 6) of the resultant byte (bitwise OR
with 0x40).
Using this method, the checksum is always a number between 0x40 and 0x7F.
The checksum can never be confused with the <STX> or <ETX> control
characters, since these have non-overlapping ASCII values.
If the DSP detects a checksum error, the received message is ignored – no
acknowledge or data is sent back to the host. A timeout will act as an implied
NACK.
The following is sample code, written in Visual Basic, for the generation of
checksums:
Public Function ProcessOutputString(outputString As String) As String
Dim i As Integer
Dim CSb1 As Integer
Dim CSb2 As Integer