Chapter 4 serial ports, Accessing serial buffers – Remote Processing RPC-52 User Manual
Page 13
CHAPTER 4
SERIAL PORTS
Page 11
Figure 4-3 Data packet
> 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.
A response depends upon the nature of the command.
Suppose command M means "return a digital I/O port
status". The R PC-52 could read the port and r espond
with AA 2< cr> . T he first A is an acknow ledge, that is
no errors w ere detected in the message. The data, A2,
can be broken d own 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.
ACCESSING SERIAL BUFFERS
You can access C OM0 and COM 1 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.
INPUT strips bit 7. This means ASCII characters
from 0 to 127 are rec eived. The IN PUT statement
can return a maxim um string length of about 150
character s.
2.
GET function. Char acters ar e rem oved one at a
time as a numerical value. A 0 is returned when the
buffer is e mpty. Use the C OM function to
determ ine if the buffer is empty or if a 0 is a data
value.
If you don' t read the b uffer an d the buffer fills, all
subsequent characters are discarded. GET m ay be
u s ed a ny w h er e in th e pr o g ra m .
3.
COM$(n) retrieves all characters in the buffer,
including other control codes (except CR).
A C C E SS I NG C O M 0 AN D C O M 1
The port INP UT and GE T functions retrieve data using
the UIn c omm and. UI0 r outes inputs to C OM 0 while
UI1 routes inputs to the COM1 port. PRINT outputs are
set by the U On com mand. UO0 p rints out C OM 0 while
UO1 outputs COM 1.
The following show how UIn and U On work.
100
UI0
Set to COM0
110
INPUT A
Get data from COM0 port
520
UI1
Switch to COM1 port
530
INPUT B
Get data from COM1 port
800
UO0
P r in t t o C O M 0
810
P R I NT " T e m pe r at ur e : " , T
900
UO1
P r in t t o C O M 1
910
P R I N T " Se t p r e ss u re a t: " , C A
Power up default is set to COM0. UIn has no effect
upon COM $(n) function.