rchReceivePacket (Functionblock) |
|
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;
Example: INCLUDE rtcu.inc incoming : rchReceivePacket; Buf_out : ARRAY [1..4064] OF SINT; size : INT; // 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; ... |