rchSendPacket (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Firmware version:

1.00 / 1.00.00


This function sends a packet of binary data over the RTCU Communication Hub. It will return the status of the send command. See below.

This function works similarly to gwSendPacket.

 

 
Please note that the return value from this function should always be checked. There are a number of reasons why this function could fail - too much traffic on the network for example. Therefore, always check the return value, and, based on that, have a strategy for resending a message etc.

 

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

(See function overview for more more information about LPS)

Use the rchPacketSize function to determine the maximum size of a packet that can be sent to a receiver.

 

 

Input:        

receiver : DINT

NODE ID of receiver node.

 

buffer : PTR

The address of the receive buffer.

 

length : INT (1..4064)

Length of data to send (max 4064 bytes).

 

Returns: INT

0

- Success.

1

- Destination unreachable.

2

- Timeout delivering packet.

3

- Communication channel not open/connected.

4

- Packet rejected by receiver.

5

- Unspecified error.

6

- Invalid parameter.

7

- The length of the data is too large for the receiver.

8

- Destination is busy.

Note: 128 - 255 is reserved for user-defined return codes from rchReceivePacketDone.

 

Declaration:

FUNCTION rchSendPacket : INT;
VAR_INPUT
   receiver : DINT;
   buffer   : PTR;
   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;
 
// Turn on power to the GSM module
gsmPower(power := TRUE);
netOpen(iface:=1);
 
// Wait for rch 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;