serialWait
Top  Previous  Next

serialWait ( [ integer Timeout ] )

Use this function to wait for a communication event on the currently open serial port. The communication event is raised in two cases:

·the number of characters in the receive buffer becomes greater or equal to the input threshold specified in serialOpent.  
·the number of characters in the transmit buffer becomes less than the output threshold specified in serialOpen.  
 
If a communication event is raised or timeout occurs, the script will continue.

Parameters
 
Timeout  
 
Integer specifying the maximum time to wait in milliseconds. If this parameter is omitted, the timeout will never occur.  

Error flags
 
ERR_OK  
 
The flag set if successful.  
 
ERR_TIMEOUT  
 
The timeout occurred.  
 
ERR_FAILED  
 
The flag set if failed.  
 
ERR_NOTFOUND  
 
No open port found  
 
Remark
 
To open and configure a serial port, use serialOpen.  
 
Example
 
This set of statements demonstrates a cycle of serial communication waiting for a triad of characters to come to a serial port and printing them in the terminal window. A triad of "0" is used to exit the cycle.  
 
serialOpen(1,"19200,N,8,1",3)  
Do  
serialWait(10000)  
if(getError()=ERR_TIMEOUT) Then   
 MsgBox ("No data in the serial port")  
 goto M1  
End If  
str=serialRead()  
Print str  
M1: Loop While str <> "000"  
serialClose()