beautypg.com

Rpbasic-52 programming guide – Remote Processing BASIC 52 User Manual

Page 38

background image

RPBASIC-52 PROGRAMMING GUIDE

2-19

COM$

Syntax:

$(n) = COM$( port)
Where: port = 0 or 1 , the seri al com mun icatio n port. port may be la rger. Check yo ur hardware

manua l.

Function:

Return either a ll characters or up to a in specified se rial port.

Mode:

Run

Use:

$(0) = COM$(0)

Cards:

All

D E S C R IP T I ON

Characte rs in the specified com municatio ns port buffer are put into the string (on the left side of the = ) until
one of three con ditions occur: 1) Th ere are no m ore characters to e xtract. 2) A cha racter is
encountered. 3) The maximum number of characters specified in the STRING statement is reached.

This statement is useful when the application cannot risk using an INPUT statement. The INPUT statement
waits until a is returned before continuing execution.

Unlike the IN PUT sta tement, the va lue of all characters, ex cept a (AS CII 0DH ) are returned. All
control characters and characters with ASCII values above 128 are returned.

NOTE: COM$ works only when it is assigning another string variable. A BAD SYNT AX error is returned

when it is part of a PRINT, IF-THEN, ASC, or other command or function. Use this function only as
shown in SYNTAX above.

RELATED

G E T , I N PU T , O N C O M $

ERRORS

B A D S Y N T A X

Any parameters left out

B A D A R G U M E N T When port > 1 or card limit or negative

EXAMPLE

The follow ing exam ple prints the num ber of characters in th e buffer as they are e ntered. Wh en 10 charac ters
have been received, the string is printed.

10 STRING 100,20 : CLEAR COM(0)
15 PRINT "Enter characters."
20 A=COM(0)
30 B=COM(0)
40 IF A=B THEN 30
50 PRINT "Number of characters in buffer:",B, CR ,
55 A=B
60 IF B<10 THEN 30
70 $(0)=COM$(0)
75 PRINT
80 PRINT "Received string =",$(0)
100 PRINT "Characters left in buffer=",COM(0)
110 GOTO 20

When you enter a before the 10th charac ter, the string to the is returned . Note that there are still
some ch aracters left in the buffer. W hen 10 chara cters are entered w ithout a , characters are put into
the strin g until th e buffe r is em ptied o r the m axim um n umb er of strin g char acters set by S TRI NG is reac hed.
To see how this works, chang e line 60 to IF B <25 TH EN 30. T he numb er of characters left in the buffer will
always be 5, unless a was entered.