serFrameReceiveDone (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

All

Firmware version:

1.00 / 1.00.00


serFrameReceiveDone is called when the buffer from the serFrameReceiver function block is ready to receive new data. This is typically when the program is finished using the data and is awaiting a new frame on the serial port.

It is very important that this function is called with the same port number as the serFrameReceiver functionblock.

 

 

Input:

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

This selects which serial port to use.

 

Returns:

None.

 

Declaration:

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

 

 

Example:

INCLUDE rtcu.inc
 
VAR_OUTPUT
  led     : BOOL; | Indicates that a serial frame has been received
END_VAR;
 
PROGRAM test;
 
VAR
  RX       : serFrameReceiver;
  rxbuffer : ARRAY[0..63] of SINT; // Declare a buffer for receiving frames from the serial port
  txbuffer : ARRAY[0..63] of SINT; // Declare a buffer for sending frames to the serial port
  portNum : SINT := 0;                   // Select which port to use for the communication        
END_VAR;
 
// Open the serial port, set baudrate, parity and number of bits
serOpen(port:=portNum, baud:=9600, bit:=8, parity:=0);
// Enable receiving from the serial port, data will be stored in 'rxbuffer', start of frame is a <CR> and end of frame is a <LF>
RX(port:=portNum, enable:=TRUE, frame:=ADDR(rxbuffer), maxSize:=SIZEOF(rxbuffer), sof:=16#0D, eof:=16#0A);
 
// Send the string <CR>ABC<CR><LF> using a buffer
txbuffer[0]:=16#0D; // <CR>
txbuffer[1]:=16#41; // 'A'
txbuffer[2]:=16#42; // 'B'
txbuffer[3]:=16#43; // 'C'
txbuffer[4]:=16#0D; // <CR>
txbuffer[5]:=16#0A; // <LF>
serSendData(port:=portNum, data:=ADDR(txbuffer), size:=6);
 
// Send a <CR>
serSendChar(port:=portNum, ch:=16#0D);
// Send the string 'Hello world'
serSendString(port:=portNum, str:="Hello world");
// Send a <CR>
serSendChar(port:=portNum, ch:=16#0D);
// Send a <LF>
serSendChar(port:=portNum, ch:=16#0A);
 
BEGIN
  // Allow the receive functionblock to be updated
  RX();
  // Check if a frame has been received (at least a <CR> and a <LF> has been received)
  IF RX.ready THEN
     // Indicate a frame has been received, data is available in 'rxbuffer', length in 'RX.size'
     led:=NOT led;
     // Here we do something with the frame that has been received
     // ..
     // ..
     // ..
     // Release the buffer for the receiver as we are now finished with the received data
    serFrameReceiveDone(port:=portNum);
  END_IF;
END;
 
END_PROGRAM;