ComReceive Procedure

Reads bytes from the specified lPort COM port number.

Syntax

[ lBytesReceived = ] ComReceive ( lPort , sEOS, lTimeout [, enMode], pDst [, lBytes] )

The ComReceive procedure syntax has the following parts:

 

Name

Type

Description

lBytesReceived

Val Long

Number of bytes received. A value of -1 indicates an error has occurred.

lPort

Val Long

Serial port number (1 for COM1, etc.)

sEOS

Val BString

End Of Sequence string

lTimeout

Val Long

Timeout in milliseconds

enMode

enumAIoMode

Input receive mode. Default value is aioDefault (0). Only the default value can be combined with aioDisableBstrConvert, aioDisableComReceiveEarlyReturn.

pDst

Var Any

Receive data buffer

lBytes

Val Long

Maximum number of bytes to receive. If the default value is used (-1) the byte length of the pDst data size is used as the maximum of bytes to receive. For an empty non-fixed size string 1024 bytes is used.

Where

enumAIoMode can be one of the following values:

 

Name

Value

Description

aioDefault

0

Receive data available (Default)

aioWaitGpibSrqVxiDor

1

Receive on Srq (gpib) or on Dor (vxi)

aioGpibImmediateOrSrq

2

Receive on Immediate or Srq (gpib)

aioDisableBstrConvert

4

Disable conversion of BString to String, can be combined with one of the previous values.

aioDisableComReceiveEarlyReturn

8

Disable early return from ComReceive.

Comments

The lPort must be opened by calling the ComOpen procedure or by configuring an RS232 driver in the System.

The sEOS can be 0-2 bytes long and specifies the data bytes that signal the end of data.

The function will return if any of the following conditions is met: 1) if the number of bytes received is equal to lBytes or 2) if the timeout time (lTimeout) is expired or 3) if the terminator is received.

If sEos parameter is an empty string and aioDisableComReceiveEarlyReturn mode flag is not used (default case), the function will return immediately if characters are  found in the input buffer, and the timeout will be ignored. Using the aioDisableComReceiveEarlyReturn flag will ensure that the function will return only if the timeout is reached or all lBytes characters were received.

The function will return -1 if sEOS was specified (not empty string) but was not received. If no terminator (sEOS was specified and no data was received (timeout) the function will return 0.

Example

The following example will read from the COM2 port as the data is available into the sBuf data buffer, after reading up to 100 bytes, waiting for 1 second, with an End of Sequence string of carriage return/line feed (Default mode is used):

lBytes = ComReceive(2, "\r\n", 1000, , sBuf, 100)

The following example will return if 1 second passed or 100 bytes received:

lBytes = ComReceive(2, "", 1000, aioDisableComReceiveEarlyReturn, sBuf, 100)

See Also

ComFlush, ComSend, ComSetup