RK512

The function block RK512 basically distinguishes two operation modes, passive and active operation.
In the passive mode the function block waits for and answers data telegrams 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 function block RK512 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 operation 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 data traffic, 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.
Inputs
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
Name | Type | Description |
---|---|---|
Send | BOOL | 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 | BOOL | 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 | POINTER TO BYTE | DbAdr is the memory address of a PLC variable determined by the ADR function. e.g.: 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 | UINT | DbSize is the size of the PLC variable at DbAdr in bytes, determined by the SIZEOF() function. e.g.: |
RemoteDbNr | BYTE | 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 | UINT | NrOfBytes contains the number of data bytes to be transferred. The number can be less than or equal to the variable size DbSize. |
ByteOffset | UINT | 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 | BOOL | 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 | BOOL | 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 | TIME | Each telegram from a communication partner is acknowledged with an answer telegram. The time required for this acknowledgement is monitored with respect to the TREA timeout period. TREA might be about 15 seconds. |
Inputs/outputs
VAR_IN_OUT
TxBuffer : ComBuffer;
RxBuffer : ComBuffer;
END_VAR
Name | Type | Description |
---|---|---|
TxBuffer | The send data buffer | |
RxBuffer | The receive data buffer |
Outputs
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 : RK512_Error_t; (* 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 : RK512_Error_t; (* RK512 error id. For receive mode only *)
Aux : RK512_Auxiliary_t; (* Additional errors for debugging *)
END_VAR
Name | Type | Description |
---|---|---|
Busy | BOOL | 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 | BOOL | 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 | BOOL | SendFetchSuccess indicates that a data transmission triggered by Send or Fetch has been successfully completed. |
Error | BOOL | Error becomes TRUE if an error occurs during a data transmission triggered by Send or Fetch. |
ErrorId | RK512_Error_t | ErrorId provides an error number if an error occurs. |
BusyReceive | BOOL | 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 | BOOL | 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 | BYTE | As soon as ReceiveSuccess becomes TRUE, ReceivedDbNr indicates the number of the data block that has been received. |
ErrorRx | BOOL | The ErrorRx signal indicates that an error has occurred during data reception in passive mode. |
ErrorIdRx | RK512_Error_t | If an error occurs in passive mode, ErrorIdRx indicates the error number. |
Aux | RK512_Auxiliary_t | Aux is a data structure containing additional error messages for diagnostic purposes. |
DBconfig()- Method for data block configuration
The RK512 function block has two operating modes. In passive mode it receives data and request telegrams from a communication partner who is addressing data blocks by means of its data block number. Numbered data blocks are not known to IEC-1131, and therefore initially also not to TwinCAT. In TwinCAT, data blocks are variables of various types such as arrays or data structures (STRUCT).
In order to define a numbered data block, the method DBconfig belonging to the RK512 function block as called with all the necessary parameters during the initialisation phase. The method is called once for each data block that is to be addressed by communication partners. This configuration is not needed for the active operating mode (send and fetch).
In the active operating mode variable contents can be sent to or fetched from communication partners, independently of this data block configuration. In active mode the data block number refers to the partner device, and only needs to be known there.
Parameter
Name | Description |
---|---|
DbAdr | DbAdr is the memory address of a PLC variable that is to be defined as a data block. The address is determined using the ADR function. |
DbSize | DbSize is the size of the PLC variable at DbAdr in bytes, determined by the SIZEOF function. |
RemoteDbNr | RemoteDbNr contains the number of the data block at the communication partner. |
TxBuffer | The send data buffer TxBuffer is of type COMbuffer. This parameter is not needed by the configuration, but must however be passed as an IN_OUT parameter. |
RxBuffer | The receive data buffer RxBuffer is of type COMbuffer. This parameter is not needed by the configuration, but must however be passed as an IN_OUT parameter. |
Sample
VAR
(* declare some DB
(* the type of data doesn't matter but the
(* size shouldn't be larger than 128 bytes *)
DB1 : ARRAY[1..64] OF WORD; (* exemplary type of db *)
DB5 : ARRAY[1..64] OF WORD; (* exemplary type of db *)
DB10 : ARRAY[1..64] OF WORD; (* exemplary type of db *)
(* input and output data for the RK512 function block *)
RK512com : RK512;
initialized : BOOL;
END_VAR
IF NOT initialized THEN
RK512com.DBconfig( RemoteDbNr:=5, DbAdr:=ADR(DB5), DbSize:=SIZEOF(DB5), TxBuffer:=TxBuffer, RxBuffer:=RxBuffer );
RK512com.DBconfig( RemoteDbNr:=10, DbAdr:=ADR(DB10), DbSize:=SIZEOF(DB10), TxBuffer:=TxBuffer, RxBuffer:=RxBuffer );
initialized := TRUE;
END_IF
The initialization in this sample has the effect that the communication partner may read or write data blocks 5 and 10. Any attempt to access another data block is considered as an error and is refused.
Requirements
Development environment | Target platform | PLC libraries to include |
---|---|---|
TwinCAT v3.1.4012 | PC or CX (ARM, x86, x64) | Tc2_SerialCom |