Implementation of the User Program¶
The example shows how to write a dataset with word length 2 to the slave and how to read a dataset from the slave with word length 14.
Implementation of the Master
The first step is the implementation of an instance of the function block RCOM_INIT that is used to initialize the RCOM Communication Module at the specified slot (1 in this case).
The function block must be called cyclically to ensure proper functionality of the RCOM Communication Module. The outputs DONE and ERR must be checked to retrieve the current state of initialization. Once the output DONE is TRUE and ERR is FALSE, the Communication Module is initialized and ready for further operation.
After a successful initialization the slave must go through the RCOM specific initialization sequence that consists of a cold start, a warm start and a normalization. These operations will ensure that the slave is ready to process incoming transmission requests of the master. Input NODE of all function blocks used is set to 1 to address the directly connected slave device.
Once the normalization step has finished successfully, the calls of the data transmission function blocks can be started. In this example, the first step of data transmission is the execution of a write request to transfer a data set of word length 2 to the connected slave. The function block RCOM_TRANSMIT is used to realize this operation. The data that is written to the slave is located in the word array arwDataOut[0..1]. The input DATA of the function block is set to the array’s address using the ADR operator. The input ID is set to 2 what specifies the data set number which must equal a corresponding data set on the slave side. The length of the data set is set to value 2 at input LEN.
After this step a read request will be started by using the function block RCOM_READ. The requested data set is specified at input ID (3 in this case). A corresponding data set is projected in the slave project described later. The received data is written to word array arwDataIn[0..13]. Input DATA must be set to the address of the array via the ADR operator. The length in words is specified at input LEN.
In case of an error during data transmission, the slave must be normalized to reset its state and to maintain its ability to process incoming request telegrams of the master.
Implementation of the Slave
As shown in the master implementation, the slave also requires the creation and call of an instance of the function block RCOM_INIT.
The 2 requests that are sent by the master require a corresponding implementation of the function blocks RCOM_READ_SLV and RCOM_REC which react to the read or write request telegrams of the master.
An instance of function block RCOM_READ_SLV with input ID set to 3 reacts to the read request projected in the master. The data that is read from the master is located in word array arwDataOut[0..13]. Its address is set at input DATA of the function block.
An instance of function block RCOM_REC with input ID set to 2 reacts to the incoming write request projected in the master. The data contained in the master’s telegram is copied to word array arwDataIn[0..1]. Its address is set at input DATA of the function block.