SerialReceive                                                                                         Function

 

SERIALRECEIVE(buffer as string or integer arrray , numChars as integer, timeout as double)

 

Description

Receives incoming data from the serial port and places it into buffer. It can be used to wait for data to arrive, or to get data once a program has been notified of incoming data by an NsbSerialIn event. It stops after receiving at least numChars characters and cancels further receipt of data if more characters are received than the BufferSize set with the SerialSet() function. This function returns a result code: see SerialOpen for a list of result codes. To clear the receive buffer, do a SerialSend("",0).

 

If SerialReceive is called as a result of an NsbSerialIn event, it will return when all the characters are read, even if numChars has not yet been received. The timeout argument is ignored. To find out how many characters are in the serial receive queue, using the SysInfo(5) function.

 

If SerialReceive is not called after an NsbSerialEvent, it will return when numChars are received or no characters are received in the timeout period in seconds. Fractions of a second are allowed. In the event of a timeout, the function will return 773, along with any data that was received in buffer.

 

If buffer is an integer array, the ASCII value of each byte (including null) will be put into an element of the array.  This allows you to receive null characters.

 

 

Example

Err=SerialReceive(inputString, 200, .5) 'non event case