gwReceivePacket (Functionblock)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Firmware version:

1.00 / 1.00.00

Deprecated:

Use rchReceivePacket instead.


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

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

 

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 gwPacketSize 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 gwReceivePacket;
VAR_INPUT
   buffer    : PTR;
   maxlength : INT;
END_VAR;
VAR_OUTPUT
   sender    : DINT;
   length    : INT;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
VAR

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

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

   size     : INT;
END_VAR;
 
// Turn on power to the GSM module
gsmPower(power := TRUE);
gprsOpen();
 

// Wait for hub connection

WHILE NOT gwConnected() DO

   Sleep(delay := 2000);

END_WHILE;

 

// Determine the maximum size to send

size := gwPacketSize(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;
   ...
   gwSendPacket(receiver := 2000, buffer := ADDR(Buf_out), length := size);
   ...
END;
END_PROGRAM;