Serial ports chapter 4 – Remote Processing RPC-30 User Manual

Page 16

Advertising
background image

SERIAL PORTS

CHAPTER 4

Page 14

RPC-30

The response depends upon the nature of the command.
S u pp o se th e co m m an d M me a ns " r et ur n a d ig it al I/ O
port status". T he RPC-30 could rea d the port and
respond with AA2< cr> . The first A is an
acknowledge, that is no error s were detected in the
message. The data, A2, can be broken do wn as follows:

Bit/line

7 6 5 4 3 2 1 0

Status

1 0 1 0 0 0 1 0 = A2

Lines 1, 5 and 7 are high while the others are low.

For further information on protocols, reque st application
note AN-2.

CAM BASIC is easily programm ed as part of a network.
The following code fragment shows how this is done.

90 CONFIG BAUD 2,6,4,0,2
100 CONFIG COM$ 2,13,20,0,0
110 ON COM$ 2 GOSUB 4000

(more program initialization here)

1000 GOTO 1000 :'main program loop

4000 A$ = COM$(2)
4010 IF LEFT$(A$,3)<>">22" THEN RETURN
4020 B = ASC(MID$(A$,4,1))
4030 IF B = 77 THEN GOTO 4200

(more command parsing here)

4190 RETURN

Line 90 sets up COM 2 port for RS-485.

Line 100 and 110 set up the RPC-30 to receive
characters on the RS-485 port. It instructs CAMBASIC
to go to line 4000 when a < cr> or 20 characters have
been received.

Line 1000 is a loop. This can be the main part of your
program . Gener ally, non-time sensitive routines go
here.

Line 4000 starts the com municatio ns task rou tine. T his
line gets the string from the buffer.

The next line, 4010, checks to see if the first three
charac ters cor respond to its address. If it doesn' t, then it
simply exits the subroutine. CAM BASIC requires about
3 m il li -s e co n ds to g o f r om l in e 40 0 0 t o t he R E T U RN .

4020 converts the ASCII comm and character to a

numbe r. Depend ing upon the nu mber of comm ands, it is
usually faster to convert letter to a number then perform
a comparison against it rather than a letter.

Line 4030 begins parsing the command to go to a
particular line number.

Ear lier, the amou nt of time to ch eck an addr ess and exit
was given. T his is important if the RPC-30 is to keep up
with bus activity. This becomes a special concern when
the baud rate is at 19.2K or 38.4K baud and other nodes
are able to resp ond instantaneously to comm ands.

At 38.4K baud, a 7 byte packet (consisting of < cr> ,
address , co mma nd, and checks um) take s about 1. 8 ms to
send. If a node responds with a 4 byte message
(acknowledge, data, and < cr> ), a complete m essage
exchange between the host and a no de took place in
about 3 ms. Y ou can see that by the time the RPC-30
determ ined that the incom ing messa ge was no t for it, a
complete exchange took place an d another possibly
started.

This is a problem if you are trying to r un other tasks.
Because new messages could be coming every 3 ms and
it takes about 3 ms to determine if has been addressed,
there is no tim e left for othe r tasks or running the main
p r o gr a m .

Another time this a pr oblem w hen nodes r espond to
messages quickly (under 100 micro-seconds), you are
transmitting at 38.4K baud, and messages are always
s h or t an d co n ti nu o us . I f t he o th e r no d es c on s is t o f RP C -
3 0 ' s o nl y, t h en th e r e w i ll no t b e a p r o bl e m.

T h e re a r e a c ou p le o f s o lu ti on s to th is p ro b le m .

1.

Lower the baud r ate to 9600. Messages will now
take 4 times longer.

2.

Forc e the host to send messages ever y 10 ms.

3.

Forc e nodes to delay response s to the host by 10 ms.

Solution 2 m ay alrea dy be enfor ced by the ho sts
processing power and programming language.

Advertising