RECEIVE BUFFER

4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next

version 6.8.3 (Modified)


RECEIVE BUFFER (receiveVar)

ParameterTypeDescription
receiveVarVariableVariable to receive data

Description

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 9.x serial port buffer is limited in size to 10 Kbytes. Under Mac OS X, its 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.

Note: There are 4D plug-ins that enable you to increase the size of the serial buffer.

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, Variables.


4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next