serSendString (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Firmware version:

1.00 / 1.00.00


serSendString will send a string out on the serial port.

 

 

Input:

port : SINT (0..127) (default 0)

Selects which serial port to use.

 

str : STRING

The string to send.

 

timeout : DINT (default -1)

The number of milliseconds to wait (Only used when hardware handshake is enabled. See serSetHandshake).

0

-

Disable timeout. The function will return immediately.

-1

-

Wait forever. The function will only return when data is send.

Supported from firmware 4.68 / R1.10.00

 

Returns: INT

1

-

Success.

-1

-

The serial port is not open.

-2

 

The serial port is no longer present.

-3

-

Timeout waiting for send.

 

Declaration:

FUNCTION  serSendString;
VAR_INPUT
   port : SINT := 0; // Port number
   str  : STRING;    // String to send
   timeout : DINT := -1;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
VAR_OUTPUT
   led      : BOOL; | Indicates that a serial frame has been received
END_VAR;
 
PROGRAM test;
 
VAR
   RX       : serFrameReceiver;
   rxbuffer : ARRAY[0..63] of SINT; // Declare a buffer for receiving frames from the serial port
   txbuffer : ARRAY[0..63] of SINT; // Declare a buffer for sending frames to the serial port
   portNum  : SINT := 0;                   // Select which port to use for the communication        
END_VAR;
 
// Open the serial port, set baudrate, parity and number of bits
serOpen(port:=portNum, baud:=9600, bit:=8, parity:=0);
// Enable receiving from the serial port, data will be stored in 'rxbuffer', start of frame is a <CR> and end of frame is a <LF>
RX(port:=portNum, enable:=TRUE, frame:=ADDR(rxbuffer), maxSize:=SIZEOF(rxbuffer), sof:=16#0D, eof:=16#0A);
 
// Send the string <CR>ABC<CR><LF> using a buffer
txbuffer[0]:=16#0D;  // <CR>
txbuffer[1]:=16#41;  // 'A'
txbuffer[2]:=16#42;  // 'B'
txbuffer[3]:=16#43;  // 'C'
txbuffer[4]:=16#0D;  // <CR>
txbuffer[5]:=16#0A;  // <LF>
serSendData(port:=portNum, data:=ADDR(txbuffer), size:=6);
 
// Send a <CR>
serSendChar(port:=portNum, ch:=16#0D);
// Send the string 'Hello world' 
serSendString(port:=portNum, str:="Hello world");
// Send a <CR>
serSendChar(port:=portNum, ch:=16#0D);
// Send a <LF>
serSendChar(port:=portNum, ch:=16#0A);
 
BEGIN
   // Allow the receive functionblock to be updated
   RX();
   // Check if a frame has been received (at least a <CR> and a <LF> has been received)
   IF RX.ready THEN
      // Indicate a frame has been received, data is available in 'rxbuffer', length in 'RX.size'
      led:=NOT led;
      // Here we do something with the frame that has been received
      // ..
      // ..
      // ..
      // Release the buffer for the receiver as we are now finished with the received data
      serFrameReceiveDone(port:=portNum);
   END_IF;
END;
 
END_PROGRAM;