
RPBASIC-52 PROGRAMMING GUIDE
2-19
COM$
Syntax: $(n) = COM$(port)
Where: port = 0 or 1, the serial com munication port. port may be larger. Check your hardware
manual.
Function: Return either all characters or up to a <CR > in specified serial port.
Mode: Run
Use: $(0) = COM$(0)
Cards: All
DESCRIPTION
Characters in the specified com munications port buffer are put into the string (on the left side of the = ) until
one of three conditions occur: 1) There are no more characters to e xtract. 2) A <C R> character 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 <CR> is returned before continuing execution.
Unlike the INPUT sta tement, the va lue of all characters, except a <CR> (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 SYNTAX 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
GET, INPUT, ON COM$
ERRORS
BAD SYNTAX Any parameters left out
BAD ARGUMENT When port > 1 or card limit or negative
EXAMPLE
The following example prints the num ber of characters in the buffer as they are entered. When 10 characters
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 <C R> before the 10th character, the string to the <C R> is returned . Note that there are still
some characters left in the buffer. W hen 10 characters are entered w ithout a <CR >, characters are put into
the string until th e buffer is emptied o r the maxim um numb er of string characters set by S TRING is reached.
To see how this works, change line 60 to IF B<25 TH EN 30. The numb er of characters left in the buffer will
always be 5, unless a <CR> was entered.
Komentáře k této Příručce