Sending and Receiving

Sending data

In the example program included, data is sent via the serial interface at one-second intervals, and the program reacts immediately to an arriving character.  

 

Possible errors

More than one character may be transmitted during one PLC cycle, provided they can be accepted by the send buffer. If the send buffer overflows, the busy output of the send block will remain TRUE after it has been called. In that case the last character is not sent, and the block must be called again with the same input data in the next PLC cycle.

 

How full a buffer is can be determined at any time (e.g. TxBuffer.Count or TxBuffer.FreeByte).  

PROGRAM MAIN
VAR
    ComControl: KL6ControlBC;
    Timer: TON;
    Receive: ReceiveByte;
    Send: SendByte;
    Rb: BYTE;
    Sb: BYTE;
END_VAR
ComControl( CoMin:=KL6InData,
            CoMout:=KL6OutData,
            TxBuffer:=TxBuffer,
            RxBuffer:=RxBuffer );

Timer(IN:=TRUE,PT:=T#1S );
IF Timer.Q THEN
    IF Sb=0 THEN
        Sb:=64;
    END IF
    Sb:=Sb+1;
    IF Sb>90 THEN
        Sb:=64;
    END IF
    Send(SendByte:=Sb, TxBuffer:=TxBuffer);
    Timer(IN:=FALSE);
END IF