Format
variable1 = RECEIVE(number2)
Description
This statement will read a byte from the specified serial port. Number2
identifies which port to read (0=COM1, and 1=COM2). The byte read is
stored in variable1 (which may be an integer or string type variable).
Before executing this statement you should first check to see if there is
data waiting to be read. Executing this statement when data is not waiting
can cause your PC to "hang" until data is received at the hardware serial
port. The example below illustrates how to determine if data is waiting to
be received.
Example
OPENCOM(2,0,0,3,0)
PORTSTAT = COMSTAT(0)
DATAREADY = ZBIT(8,PORTSTAT)
IF DATAREADY = 0 THEN NODATAWAITING:
A$=RECEIVE(0)
These statements do the following. The first retrieves the status of COM1
to the variable PORTSTAT. The second checks to see if bit 8 is on,
DATAREADY will contain 1 if so, otherwise it will contain 0. Since Bit 8
is used to determine if data is waiting to be received from the port, if
DATAREADY NOT = 0 then the program will RECEIVE data from the port to
variable "A$".
Comments
Variable1 can be either a string or integer type variable. However, if
variable1 is a string, bear in mind that you cannot directly receive a NULL
(ASCII Code 0), since NULL is used to delimit the end of a string in ASIC.
However, if in the above example data was waiting at the port but A$
contained "" after the receive, you would know that the character received
was a NULL. This is not a problem if variable1 is an integer variable.
See Also
|