Rpbasic-52 programming guide – Remote Processing BASIC 52 User Manual
Page 12

RPBASIC-52 PROGRAMMING GUIDE
1-9
There a re many co mmunica tion protoc ols. For this
example, the protoc ol looks something like this:
>03MB1
The pro tocol starts with the
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 d ata packe t.
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
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
comma nd handle r. Line 100 0 gets the da ta packet.
Line 1010 determines if it is meant for this card.
Commands are sorted, or parsed out beginning at line
1020. F or this examp le, comma nds are assu med to
begin with the letter 'A'. By subtracting the ASCII
value of A, we set up the O N GO TO struc ture to
quickly hand le each com mand type . This samp le
assumes 5 commands. If more are desired, another
ON GO TO 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 b e 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 follow ing 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 issu e comm ands base d on invalid
assumptions. Lines that were set before may not be
set.
This pro gram is written so that no com mand is