RK512
VAR_INPUT
Send : BOOL; (* SEND command *)
Fetch : BOOL; (* FETCH command *)
DbAdr : POINTER TO BYTE; (* ADR(DB), SEND=source, FETCH=target *)
DbSize : UINT; (* SIZEOF(DB), size in byte for Send or Fetch *)
RemoteDbNr :BYTE; (* SEND=target, FETCH=source *)
NrOfBytes : UINT; (* number of bytes to send or fetch *)
ByteOffset : UINT; (* byte offset in remote DB *)
HighPriority : BOOL; (* 3964R priority *)
SwapWords : BOOL; (* swaps every two bytes in the data stream before/after transmission *)
TREA : TIME; (* Timeout for answer *)
END_VAR
VAR_OUTPUT
Busy : BOOL; (* FB is busy *)
(* send or fetch (active) mode *)
BusySendFetch : BOOL; (* FB is with SendFetchCommand busy *)
SendFetchSuccess : BOOL; (* Send or Fetch successfully finished *)
Error : BOOL; (* RK512 error *)
ErrorId : INT; (* RK512 error id *)
(* receive (passive) mode only *)
BusyReceive : BOOL; (* FB is busy with remote request *)
ReceiveSuccess : BOOL; (* DB has been received from the remote PLC *)
ReceivedDbNr : BYTE; (* Number of the DB that has been received *)
ErrorRx : BOOL; (* RK512 error. For receive mode only *)
ErrorIdRx : INT; (* RK512 error id. For receive mode only *)
Aux : RK512_Auxiliary_t; (* Additional errors for debugging *)
END_VAR
VAR_IN_OUT
TxBuffer : ComBuffer;
RxBuffer : ComBuffer;
END_VAR
Operating Modes
The RK512 function block distinguishes two quite different operating modes, passive and active operation.
In the passive mode the block waits for and answers data telegrams from the communication partner. The communication partner can transmit 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 synchronise 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
At a rising edge at the Send input data from the variable whose location is given by 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 rising edge at the Fetch input, data from the data block specified by RemoteDbNr is requested from the communication partner and saved in the variable specified by the DbAdr input. 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 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 rising edge at the Send or Fetch input switches the 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 transfer triggered by Send or Fetch has been successfully completed.
Error
Error becomes TRUE if an error occurs during a data transfer triggered by Send or Fetch.
BusyReceive
BusyReceive indicates that the RK512 function block is in receive mode, i.e. in the passive operating mode. The block changes automatically into passive mode from the idle state (Busy is FALSE) as soon as a telegram is received from the communication partner. As BusyReceive falls, 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.
Aux
Aux is a data structure containing additional error messages for diagnostic purposes.
TxBuffer
The transmit 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.