Serial ports chapter 4 – Remote Processing RPC-2350 User Manual
Page 23
SERIAL PORTS
CHAPTER 4
4-4
Figure 4-4 Data packet
address, com mand, data, and a checksum. See figure 4-
4. The packe t is received by all devices, and ignored by
all except the one addressed.
The relationship described below between nodes and the
host is a maste r-slave. The host dir ects all
c o mm u ni ca ti on . N o de s " d o n o t s pe a k u n le ss sp o ke n to " .
Peer to peer com munication, while possible with the
RPC-2350, is not discussed here.
Ther e are m any com municatio n protoco ls. F or this
example, a protocol might look som ething like this:
> 22M B1
The pr otocol starts w ith the < cr> charac ter. This
character synchronizes all units and alerts them that the
next few characters coming down are address and data.
In this case, "> 22" is the units address. "M " is the
comm and and " B1" is the ch ecksum . T he comm and is
terminated with a < cr> character.
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-2350 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.
The following program fragment uses ON C OM$ in a
network environment. ON C OM$ gener ates an interrupt
when a < CR> is received. The interr upt program uses
INSTR function to determine if the data packet was
addressed to this card.
10 CONFIG BAUD 2,7,4,0,2
20 CONFIG COM$ 2,13,0,0,1
30 ON COM$ 2 GOSUB 1000
40 UNIT$ = ">05"
.
.
.
1000 PACKET$ = COM$(2)
1010 A = INSTR(0,PACKET$,UNIT$)
1020 IF A = 0 THEN RETURN
.
.
Line 20 sets up ON CO M$ to interrupt on a < CR> and
branch to line 1000. Line 40 sets up this card' s address.
Line 1010 checks to see if the rece ived mess age = this
card's address. If not, the subroutine ends. When there
is a match, further processing is performed.
An application program, 485TST. BAS, filters out
control codes (such as < LF> and < CR> ) at the start
of the message. Since CO NFIG COM $ set up a
communication interrupt on a < CR> , your sending
d e vi ce c an a ls o s en d a < L F > .
485TST .BA S also checks for com municatio n err ors. Its
main pur pose is to detect co mmu nication er rors but it
also acts as a good foundation for a comm unication
p r o gr a m .
485NE T. BAS is a simple networ king progra m. To test
it out, jumper W4[2-3] temporarily. After the program
is running, connect your terminal to J4. Instructions are
printed when the program is first run.
ACCESSING SERIAL BUFFERS
You can access C OM1 and COM 2 buffers in three w ays:
1.
INP UT sta tement. This re moves a ll charac ters in
the buffer up to the term inator cha racter and puts
them into a variable.
When using the INPUT statement, program
execution is susp ended until a < cr> (Enter key) is
received. W hether this is a problem depends on
your particular application.
INPU T strips bit 7 on the COM1 por t. This means
ASCII character s from 0 to 127 are received. The
INPU T statement can return a maxim um string
length of about 150 chara cters.
2.
INKEY$(n) function. Characters ar e removed one
at a time. A null string is returned when the buffer