rfSend (Function)

Top  Previous  Next

Architecture:

X32 / NX32L

Device support:

AX9 pro, CX1 pro/pro-c/warp/warp-c, SX1, AX9 turbo, NX-900, LX5

Firmware version:

2.20 / 1.51.00


rfSend will send a package (see RF Functions for details) to any peer set up with the correct parameters and actively listening for a package with rfReceive.

 

A package is defined by a block of data with a given length specified with the "data" and "size" parameters. A package can contain up to 60 bytes of data.

 

The "receiver" is the ID of the peer nodes to accept the package as specified by rfOpen on the peer node. When the "receiver" parameter is 0, a broadcast package is transmitted and will be received by any peer awaiting a package with rfReceive.

Also see the RF Functions for more information.

 

When simultaneously using rfSend and rfReceive, it may occur that rfSend will be temporarily blocked until rfReceive has finished the operation. The time to actually perform a transmission is therefore variable as a "listen-before-send" technique is deployed to minimize data transmission collision which maximizes the actual data throughput.

 

 

Input:                

data : PTR

Address of the buffer that contains the data.

 

size : INT ( 0 .. 60 )  ( default 0 )

Number of bytes to send from the buffer.

 

receiver : INT ( 0 .. 254 ) ( default 0 )

Used by rfReceive on receiving device(s) to filter packages. When broadcasting to all IDs, use "0".

 

Returns: INT

0


- Success.

- 1


- RF not open. Use rfOpen to open interface.

- 4


- RF not supported on device.

- 6


- Invalid parameter.

 

 

Declaration:

FUNCTION rfSend : INT;
VAR_INPUT
  data     : PTR;       // Address of the buffer to send
  size     : INT;       // Number of bytes to send from the buffer
  receiver : INT := 0; // Receiver id, 0 = broadcast to all
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
VAR_INPUT
  send  : BOOL R_EDGE;
  echo  : BOOL;
END_VAR;
 
VAR_OUTPUT
  sending   : BOOL;
  receiving : BOOL;
  no_data   : BOOL;
END_VAR;
 
PROGRAM test;
VAR
  rc       : INT;
  data     : ARRAY[ 1 .. 60 ] OF SINT;
  size     : INT;
  msg      : STRING;
  my_id    : INT := 1;
  sender   : INT;
  broadcast: BOOL;
END_VAR;
  msg := strFormat(format := "Message from \1", v1 := my_id);
  rfOpen(id := my_id);
BEGIN
  IF sending THEN
    size := strLen(str := msg);
    strToMemory(dst := ADDR(data), str := msg, len := size);
    rc := rfSend(data := ADDR(data), size := strLen(str := msg));
    DebugFmt(message := "rfSend(...) = \1", v1 := rc);
  ELSIF receiving THEN
    rc := rfReceive(data := ADDR(data), size := SIZEOF(data), sender := sender, broadcast := broadcast);
    IF rc < 0 THEN
        no_data := NOT no_data;
    ELSE
        no_data := FALSE;
        size := rc;
        rc := rfSend(receiver := sender, data := ADDR(data), size := size);
        DebugFmt(message := "echo : rfSend(...) = \1", v1 := rc);        
    END_IF;
  END_IF;
  sending := send;
  receiving := echo;
END;
END_PROGRAM;