rchReceivePacket (Functionblock)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Firmware version:

1.00 / 1.00.00


This function block can be used to check if there is an incoming data packet from the  RTCU Communication Hub.

Please also see rchPacketMode for the operating mode used when receiving a packet.

This function block works similarly to gwReceivePacket.

 

Note: if more data is received than the receive buffer can hold, the remaining data is lost.

 

When Large Packet Support (LPS) is enabled, packets with up to 4064 bytes can be received.

(See function overview for more more information about LPS)

Use the rchPacketSize function to determine the maximum size of a packet that can be received from a sender.

 

 

Input:        

buffer : PTR

The address of the receive buffer.

 

maxlength : INT (1..4064)

Maximum size of the data to be received (max 4064 bytes).

 

Output:

sender : DINT

NODE ID of sending node (0=no data available or invalid parameters).

 

length : INT

Length of data received (max 4064 bytes) (0=no data available or invalid parameters).

 

Declaration:

FUNCTION_BLOCK rchReceivePacket;
VAR_INPUT
   buffer    : PTR;
   maxlength : INT;
END_VAR;
VAR_OUTPUT
   sender    : DINT;
   length    : INT;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
VAR

   incoming : rchReceivePacket;
   Buf_in   : ARRAY [1..4064] OF SINT;

   Buf_out  : ARRAY [1..4064] OF SINT;

   size     : INT;
END_VAR;
 
gsmPower(power := TRUE);
netOpen(iface:=1);
 

// Wait for hub connection

WHILE NOT rchConnected() DO

   Sleep(delay := 2000);

END_WHILE;

 

// Determine the maximum size to send

size := rchPacketSize(nodeid := 2000);

IF size = 0 THEN

   size := 480;

END_IF;

 
// Set address BEFORE the 'incoming' is called the first time!
incoming.buffer    := ADDR(Buf_in);
incoming.maxlength := size;

 
BEGIN

   ...
   // Check for incoming packets
   incoming();
   IF incoming.sender > 0 THEN
      // A packet is received
      ...
   END_IF;
   ...
   rchSendPacket(receiver := 2000, buffer := ADDR(Buf_out), length := size);
   ...
END;
END_PROGRAM;