4D v16.3

RECEIVE BUFFER

Home

 
4D v16.3
RECEIVE BUFFER

RECEIVE BUFFER 


 

RECEIVE BUFFER ( receiveVar ) 
Parameter Type   Description
receiveVar  Text variable in Variable to receive data

RECEIVE BUFFER reads the serial port that was previously opened with SET CHANNEL. The serial port has a buffer that fills with characters until a command reads from the buffer. RECEIVE BUFFER gets the characters from the serial buffer, put them into receiveVar then clears the buffer. If there are no characters in the buffer, then receiveVar will contain nothing.

On Windows
The Windows serial port buffer is limited in size to 10 Kbytes. This means that the buffer can overflow. When it is full and new characters are received, the new characters replace the oldest characters. The old characters are lost; therefore, it is essential that the buffer is read quickly when new characters are received.

On Mac OS
The Mac OS X serial port buffer capacity is, in theory, unlimited (depending on the available memory). If the buffer is full and new characters are received, the new characters replace the oldest characters. The old characters are lost; therefore, it is essential that the buffer is read quickly when new characters are received.

RECEIVE BUFFER is different from RECEIVE PACKET in that it takes whatever is in the buffer and then immediately returns. RECEIVE PACKET waits until it finds a specific character or until a given number of characters are in the buffer.

During the execution of RECEIVE BUFFER, the user can interrupt the reception by pressing Ctrl-Alt-Shift (Windows) or Command-Option-Shift (Macintosh). This interruption generates an error -9994 that you can catch with an error-handling method installed using ON ERR CALL.

Example  

The project method LISTEN TO SERIAL PORT uses RECEIVE BUFFER to get text from the serial port and accumulate it into a an interprocess variable:

  ` LISTEN TO SERIAL PORT
  ` Opening the serial port
 SET CHANNEL(201;Speed 9600+Data bits 8+Stop bits one+Parity none)
 <>IP_Listen_Serial_Port:=True
 While(<>IP_Listen_Serial_Port)
    RECEIVE BUFFER($vtBuffer)
    If((Length($vtBuffer)+Length(<>vtBuffer))>MAXTEXTLEN)
       <>vtBuffer:=""
    End if
    <>vtBuffer:=<>vtBuffer+$Buffer
 End while

At this point, any other process can read the interprocess ◊vtBuffer to work with the data coming from the serial port.

To stop listening to the serial port, just execute:

  ` Stop listening to the serial port
 ◊IP_Listen_Serial_Port:=False

Note that access to the interprocess ◊vtBuffer variable should be protected by a semaphore, so that processes will not conflict. See the command Semaphore for more information.



See also 

ON ERR CALL
RECEIVE PACKET
Semaphore
SET CHANNEL
USE CHARACTER SET
Variables

 
PROPERTIES 

Product: 4D
Theme: Communications
Number: 172

This command modifies the Error system variable

 
HISTORY 

Modified: 4D v6.8.3

 
ARTICLE USAGE

4D Language Reference ( 4D v16)
4D Language Reference ( 4D v16.1)
4D Language Reference ( 4D v16.2)
4D Language Reference ( 4D v16.3)