Digitel MPC Manual
Page 46 of 72
Table III-7. Serial Command Packet Description.
Field
Size
Comment
1. START character
1 character (byte)
ASCII character is ‘~’ (TILDA)
Start is the first byte in the command packet and tells remote units to start decoding a message. It should be
implemented as a #define, so that it can be changed if necessary. As a #define, the character is rarely changed
because it is hard coded into PHI remote units.
<SPACE>
2. ADDRESS
2 hex characters
Range 00 through FF
This field should be filled in with the hexadecimal representation of the integer address of the unit. The range
provides 255 unique addresses for PHI controls. Only 32 devices may reside on the same serial port due to
hardware loading limitations.
<SPACE>
3. COMMAND CODE
2 hex characters
Range 00 through FF
This field is one of 255 possible hexadecimal numbers, which is typically an index into a table of functions on the
remote unit. Commands should be implemented as #defines with integers between 0 and 255. The integer value
must be converted into ASCII hex before placement into the command packet character array. The command
code must be two hex digits, even if the first is a zero. See Table III-8.
<SPACE>
4. DATA field(s), optional
as needed
ASCII printable characters only
Data field(s) are for any commands that have a data value. For instance, a command to set a beam voltage in
some unit would probably consist of a command to set the beam voltage, along with a value of beam voltage. If
the command had more than one data value associated with it, such as setting an X and a Y value in a unit, the
command field could be followed by two data fields (X and Y) separated by a space between them. All data must
be sent in ASCII printable format (no binary or “control” characters). There is no limit on the number or size of
data fields. It is up to the remote unit designer to keep practicality in mind when determining these fields. A data
field is not required for all commands.
<SPACE>
5. CHECKSUM
2 hex characters
Computed checksum of packet
The calculated checksum must have its value in ASCII hexadecimal notation. It is calculated by adding the
decimal value of all characters in the packet (excluding start, checksum, and terminator), and then dividing the
result by 256. The integer remainder converted to two ASCII hex digits is the checksum. When a remote device
receives a packet, the passed checksum is compared with a computed checksum and if they do not match, the
device discards the packet.
6. Terminator character
2 hex characters
ASCII carriage return
This field is an ASCII carriage return placed at the end of a command packet. This character is not the newline
character “\n”, but can be used in string assign statements as “\r”. There is not a space between the checksum
and terminator field.
Decoding the command packet
A PHI remote unit operates in one of three modes. Receipt of data is interrupt driven or
otherwise multiplexed so that other tasks are performed by the unit's microprocessor. When the
unit receives a command packet, it continues monitoring for new commands while the current
one is carried out.
1.
MONITOR. The PHI unit monitors serial data traffic. When a PHI "start" character
is detected, the PHI unit changes to the RECEIVE MODE.
2.
RECEIVE. After receiving start, the unit tests subsequent characters for a valid PHI
command packet. This mode must have a count down timer associated with it, which
is a predetermined time for a valid command packet to be received. Furthermore if
another PHI start character is received while in this mode, (i.e. the first PHI start
character was actually part of a command packet for a non-PHI device) the unit
responds by going back to the beginning of the RECEIVE mode, with a fresh timer
setting. If a command packet is not received within the allowed time frame or if the
checksum does not match, the timer is disabled, the packet is discarded, and the mode