serGetBufferLevel (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

All

Firmware version:

1.00 / 1.00.00


This function will return the amount of space used in the serial buffer for the specific serial port. The returned value is on a scale between 0 and 1000 (permille). The exact size of the receive buffer is specified in the help section for serFrameReceiver().

 

 

Input:

port : SINT (0..127) (default 0)

Selects which serial port to use.

 

Returns: INT

This is the amount of space used in the serial buffer for that port, 0..1000 per-mille.

 

Declaration:

FUNCTION serGetBufferLevel : INT;
VAR_INPUT
  port : SINT := 0;   // Port number
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
VAR
  portNum : SINT := 0;   // Select which port to use for the communication
  bufFull : BOOL;
  i       : INT;
END_VAR;
 
BEGIN
  ...
  // Return amount of space used in serial buffer
  i := serGetBufferLevel(port:=portNum);
  IF i > 800 AND NOT bufFull THEN
    // Buffer is to full
    serSetRTS(port:=portNum,state:=ON);
     bufFull := TRUE;
     ...
  ELSIF i < 400 AND bufFull THEN
    // Buffer level OK again
    serSetRTS(port:=portNum,state:=OFF);
     bufFull := FALSE;
     ...
  END_IF;
  ...
END;
 
END_PROGRAM;