
RPBASIC-52 PROGRAMMING GUIDE
1-9
There are many communication protocols. For this
example, the protocol looks something like this:
>03MB1
The protocol starts with the <cr> character. This
character synchronizes all units and alerts them that
the next few characters coming down are address and
data. In this case, ">03" is the nodes address. Next
follows a command (M). Depending upon the
command, data may or may not follow. An optional
checksum may follow. The figure below shows the
elements in a data packet.
The response depends upon the nature of the
command. Suppose the command M means "return
door switch status". The card could read the port and
respond with A1<cr>. The first letter A is an
acknowledge. Data, 1, indicates a high.
Errors are returned with the letter N (negative
acknowledge) followed by a number. The number
identifies the general error type.
The program in Appendix A can be used on any of
the RPC-3xx series cards. Refer to this program for
the following description.
The program starting at line 1000 is the network
command handler. Line 1000 gets the data packet.
Line 1010 determines if it is meant for this card.
Commands are sorted, or parsed out beginning at line
1020. For this examp le, commands are assumed to
begin with the letter 'A'. By subtracting the ASCII
value of A, we set up the ON GO TO structure to
quickly handle each com mand type. This sample
assumes 5 commands. If more are desired, another
ON GOTO can be used. The start of the statement
could read: ON OA-5 GOTO
linenum ber,linenu mber,line numb er...
Command types can be broken into two groups: The
first group performs an action such as setting a line,
outputting to the display, or begin a complex timing
process. The second group is a function, which
returns data. This data can either be raw, such as a
line status or voltage input, or processed. Processed
data can be averages, converted values (feet/minute),
operator input from a keypad, or a status report (such
as OK) to determine if the board is there and
functioning. The intent of these commands is to show
how data is converted from string to number or
number to string.
This example uses the following commands:
Command Associated Function
Data
A 1 or 0 Set line 8
B line, analog Motor speed
output 0 to
4095
C 0-1 Position from counter
D String Print to display
E (none) Power up
acknowledge
F (none) General status
Command E is very useful to implement in situations
where the host does not know if a unit reset (due to a
power surge or something). The host may make
certain assumptions about the status of a unit and
continue to issue commands based on invalid
assumptions. Lines that were set before may not be
set.
This program is written so that no com mand is
Commenti su questo manuale