RK512

RK512 1:

VAR_INPUT
    Send : BOOL;               
    Fetch : BOOL;              
    DbAdr : POINTER TO BYTE;       
    DbSize : UINT;             
    RemoteDbNr :BYTE;          
    NrOfBytes : UINT;          
    ByteOffset : UINT;         
    HighPriority : BOOL;           
    SwapWords : BOOL;          
    TREA : TIME;               
END_VAR
VAR_OUTPUT
    Busy : BOOL;               
    BusySendFetch : BOOL;          
    SendFetchSuccess : BOOL;       
    Error : BOOL;              
    ErrorId : INT;             
    BusyReceive : BOOL;        
    ReceiveSuccess : BOOL;         
    ReceivedDbNr : BYTE;           
    ErrorRx : BOOL;            
    ErrorIdRx : INT;           
    Aux : RK512_Auxiliary_t;       
END_VAR
VAR_IN_OUT
    TxBuffer : ComBuffer;
    RxBuffer : ComBuffer;
END_VAR

Operation modes

The RK512 function block distinguishes two quite different operating modes, passive and active operation.

In the passive mode the function block waits for and answers data telegram from the communication partner. The communication partner can send the data blocks to the local controller, or can fetch data from it. In order for the RK512 function block to be able to accept data blocks or to return data that has been requested, it must previously be configured for passive operation by DBconfig.

In active mode, the RK512 function block either sends data blocks to the communication partner (SEND) or fetches them from it (FETCH).

As long as neither of the function block's Send or Fetch inputs switch it into active operation it waits for telegrams from communication partners, changing when appropriate into passive mode. The two operating modes can be mixed. In that case the RK512 function block attempts to synchronize the telegram traffic. Since mixed mode operation can introduce delays into the flow of data, it should be avoided if possible.

One instance of the RK512 function block serves just one serial interface. It is not possible for multiple instances to handle data traffic over the same serial interface at the same time.

Input and Output Parameters

Send

With a positive edge at the Send input, data from the variable at the DbAdr input is sent to the communication partner where it is saved in the data block whose number is given at RemoteDbNr. Send and fetch cannot be executed at the same time.

Fetch

With a positive edge at the Fetch input, data from the data block RemoteDbNr is requested from the communication partner and stored in the variable at input DbAdr. Send and fetch cannot be executed at the same time.

DbAdr

DbAdr is the memory address of a PLC variable determined by the ADR function.

e.g.: DbAdr := ADR( PLCvar );

The PLC variable can be of any type. An ARRAY OF WORD, for example, or a STRUCT data structure would be suitable.

Data from this variable is transmitted to the communication partner with a send command, and is fetched and stored in this variable with a fetch command.

DbSize

DbSize is the size of the PLC variable at DbAdr in bytes, determined by the SIZEOF function.

e.g.: DbSize := SIZEOF( PLCvar );

RemoteDbNr

RemoteDbNr contains the number of the data block at the communication partner to which the data is to be sent or from which it is to be fetched.

NrOfBytes

NrOfBytes contains the number of data bytes to be transferred. The number can be less than or equal to the variable size DbSize.

ByteOffset

The ByteOffset indicated the data byte within the communication partner's data block from where the data is to be fetched or where it is to be stored.

HighPriority

The priority is relevant to the 3964R protocol. The two communication partners should have different priorities. If it happens that the two partners transmit at the same time, there is a collision. This collision is resolved by the partner with the lower priority switching to receive mode, allowing the higher priority partner to transmit again.

SwapWords

Data blocks are usually organized by words. Depending on how the data words are stored in the memory, it may be necessary to swap data bytes within the transmitted words. If SwapWords is TRUE, the data bytes of each word in all the data telegrams are swapped.

TREA

Every telegram from a communication partner is acknowledged by an answer telegram. The time required for this acknowledgement is monitored with respect to the TREA timeout period. TREA might be about 15 seconds.

Busy

Busy becomes TRUE as soon as the function block switches into either active or passive mode, i.e. as soon as it leaves the idle state. It cannot accept a new command as long as Busy remains TRUE.

BusySendFetch

BusySendFetch becomes TRUE as soon as a positive edge at the Send or Fetch input switches the function block into active mode. Once BusySendFetch has become FALSE the transmission has been completed, and either the SendFetchSuccess or the Error output is set.

SendFetchSuccess

SendFetchSuccess indicates that a data transmission triggered by Send or Fetch has been successfully completed.

Error

Error becomes TRUE if an error occurs during a data transmission triggered by Send or Fetch.

ErrorId

ErrorId provides an error number if an error occurs.

BusyReceive

BusyReceive indicates that the RK512 function block is in receive mode, i.e. in the passive operation mode. The function block changes automatically into passive mode from the idle state (Busy is FALSE) as soon as a telegram is received from the communication partner. With falling edge at BusyReceive either ReceiveSuccess or ErrorRx is set.

ReceiveSuccess

ReceiveSuccess is set to TRUE after a data block has been successfully received from the communication partner. This signal is only relevant to passive operation. In other words, ReceiveSuccess is not set to TRUE if a data block has been actively fetched from the communication partner with Fetch.

ReceivedDbNr

As soon as ReceiveSuccess becomes TRUE, ReceivedDbNr indicates the number of the data block that has been received.

ErrorRx

The ErrorRx signal indicates that an error has occurred during data reception in passive mode

ErrorIdRx

If an error occurs in passive mode, ErrorIdRx indicates the error number.

Aux

Aux is a data structure containing additional error messages for diagnostic purposes.

TxBuffer

The send data buffer TxBuffer is of type COMbuffer. This buffer is used by the RK512 function block, and is not changed by the user.

RxBuffer

The receive data buffer RxBuffer is of type COMbuffer. This buffer is used by the RK512 function block, and is not changed by the user.