P3964R

P3964R 1:

VAR_INPUT
    TXstart  : BOOL; (* Start signal, edge triggered *)
    RXstart  : BOOL; (* Start signal, edge triggered *)
    Priority : BOOL; (* 3964 priority *)
    TXcount  : INT; (* Number of data bytes in TxData *)
END_VAR
VAR_OUTPUT
    Busy       : BOOL;  (* Block active *)
    TXbusy     : BOOL; (* Sending now *)
    TXready    : BOOL; (* Sending finished *)
    RXbusy     : BOOL; (* Receiving now *)
    RXready    : BOOL; (* Receiving finished *)
    RXcount    : INT; (* Number of data bytes in TxData *)
    Error      : BOOL; (* Error *)
    ErrorID    : INT; (* Error number *)
    ErrorState : STRING(80); (* Internal error state *)
END_VAR
VAR_IN_OUT
    TXbuffer : COMbuffer; (* Intermediate buffer for hardware *) 
    RXbuffer : COMbuffer; (* Intermediate buffer for hardware *) 
    TXdata   : P3964buffer; (* Application data (to be sent) *)
    RXdata   : P3964buffer; (*Application data (to be received) *)
END_VAR

Connection to Hardware

The P3964R function block handles the 3964R protocol. The background communication, which is handled by a separate block (PcComControl, KL6Control and KL6Control5B) decides on the hardware interface used. The associated data buffers, Txbuffer and Rxbuffer, are passed to the P3964R block.

Sending

Send data are entered into the Txdata send data buffer by the PLC. The number of data bytes entered is passed on in Txcount, and then Txstart is set to TRUE. Txstart is edge-triggered, so that before a new attempt to send is made, the block must be called with Txstart=FALSE. While sending, Txbusy=TRUE. Once the data has been successfully transferred, Txready changes to TRUE.

Receiving

RxStart is set to TRUE to receive data. After a complete data set has been received, the Rxready output goes TRUE and Rxcount data bytes are ready in the receive data buffer Rxdata. Rxstart is also edge-triggered. While receiving, Rxbusy=TRUE.

Interrupt reception

The P3964R block can be used in either send or receive mode. It is worthwhile switching the block to receive when transmission is not taking place. As long as the block is in receive mode, but no start character has been received from the other end, a rising edge at Txstart can interrupt the reception and initiate the sending of data. After the transfer the block goes into its initial state (Busy=FALSE), and is only switched over to receive by a new edge at Rxstart.

Priority

In a 3964R data connection, either end may send at any time. If both ends attempt to send at the same time, there is a collision. In that case, the end with the lower priority goes into receive mode, while the end with the higher priority sends again. For this reason, when priority is low the RxReady output can be TRUE, even though data are to be sent. The data in RxData may then require evaluation. The setting of the priority at the two ends is to be agreed.

Error

In the event of an error the block goes into its initial state (Busy=FALSE), and the Error output goes TRUE. The ErrorId returns the error code. ErrorState provides information about the state in which the error occurred when the internal protocol structure is known.