
SERIAL PORTS CHAPTER 4
Page 14 RPC-30
The response depends upon the nature of the command.
Suppose the command M means "return a digital I/O
port status". The RPC-30 could read the port and
respond with AA2< cr> . The first A is an
acknowledge, that is no errors 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, request 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. Generally, non-time sensitive routines go
here.
Line 4000 starts the com munications task routine. T his
line gets the string from the buffer.
The next line, 4010, checks to see if the first three
characters cor respond to its address. If it doesn' t, then it
simply exits the subroutine. CAMBASIC requires about
3 milli-seconds to go from line 4000 to the RETURN.
4020 converts the ASCII command character to a
number. 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.
Earlier, the amou nt of time to ch eck an addr ess and exit
was given. This 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 respond instantaneously to commands.
At 38.4K baud, a 7 byte packet (consisting of < cr> ,
address, command, and checksum) takes about 1. 8 ms to
send. If a node responds with a 4 byte message
(acknowledge, data, and < cr> ), a complete message
exchange between the host and a node took place in
about 3 ms. You can see that by the time the RPC-30
determ ined that the incom ing message was not for it, a
complete exchange took place and another possibly
started.
This is a problem if you are trying to run 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 other tasks or running the main
program.
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
short and continuous. If the other nodes consist of RPC-
30's only, then there will not be a problem.
There are a couple of solutions to this problem.
1. Lower the baud rate to 9600. Messages will now
take 4 times longer.
2. Force the host to send messages ever y 10 ms.
3. Force nodes to delay response s to the host by 10 ms.
Solution 2 may already be enfor ced by the ho sts
processing power and programming language.
Komentáře k této Příručce