Chapter 4 serial ports – Remote Processing RPC-30 User Manual

Page 17

Advertising
background image

CHAPTER 4

SERIAL PORTS

RPC-30

Page 15

Figure 4-3 Data packet

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
is empty.

In this mode, you have access to the full 256 bytes.
If you don' t read the b uffer an d the buffer fills, all
subsequent characters are discarded. INKEY$(n)
m a y be u se d an y w he r e in th e pr o g ra m .

3.

COM$(n) retrieves all characters in the buffer,
including < cr> ' s and other control co des. This
function is commonly used with ON COM$
multitasking statement. You can retrieve 128 of the
256 bytes in the serial buffer at one time.

SERIAL PORT FILE NUMBERS

CAM BASIC refer ences the ser ial I/O ports by file
numbers, similar to DOS. The following table shows
the corresponding file number to serial I/O por t and how
they are used w ith the various ports.

Description File

Examples

C O M 1

1

PRINT "Hello"
PRINT #1," Hello"
INPUT A$
INPUT #1,A$
A$ = INKEY$(1)

C O M 2

2

PRINT #2," Hello"
INPUT #2,A$
A$ = INKEY$(2)

COMMANDS

The following is a list of CAM BASIC commands used
for serial I/O. Var iations for many commands not listed
here. These co mma nds and func tions are ex plained in
the CAM BASIC Program ming M anual.

Comm and

Function

C L E AR C O M $

Clears serial input buffer

C O M $

Returns string from buffer

C O N F I G BA U D

Sets serial port parameters

C O N F IG C O M $

Configures port for ON
COM $(n) interrupt

INKEY$

Returns a character fr om the
serial buffer

I N P U T

Receives string from port

LIST

Outputs program listing

O N C OM $

Calls subroutine on serial
input

P R I N T

Outputs data in various
form ats

TAB

Tabs to predetermined
positions

Advertising