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. In addition to that event polling is used to transfer a dataset from the slave to the master.

Implementation of the Master

The first step is the implementation of an instance of function block RCOM_INIT that is used to initialize the RCOM communication module at the specified slot (1 in this case). To process incoming events of the slave a RCOM_REC function block is projected and called every cycle as soon as the initialization of the local Communication Module has been finished.

../_images/62932342e38c040b0a33139000eba54e

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 get the initialization state. Once output DONE is TRUE and ERR is FALSE the communication module is initialized and ready for further operation.

After a successful initialization the variable bTrigger must be manually set to start the dialing process represented by function block RCOM_DIAL. Otherwise the master waits for incoming calls of the slave to show how the automatic polling process is executed.

../_images/229eedbee38c036f0a33139000eba54e

In case of a finished dialing process triggered by the master, the RCOM initialization function blocks for cold start, warm start and normalization are started in the next steps to initialize the slave and prepare it for further request telegrams that are used for data transmission.

../_images/d0099292e38c03210a33139000eba54e

Once the normalization step has finished successfully the data transmission can be executed. In this example the first step of data transmission is the call 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 that is also described in this documentation. 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.

The next step triggers an event poll (RCOM_POLL) on the slave to check for new events that will be read from the slave’s event queue and processed by local RCOM_REC function blocks.

../_images/d64122f9e38c04590a33139000eba54e

In case of an error the, master hangs up the phone (function block RCOM_HANGUP) and waits for incoming calls or a new dialing process that is started manually.

../_images/dc480704e38c03bd0a33139000eba54e

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 two requests that will be sent by the master require corresponding implementation of the function blocks RCOM_READ_SLV and RCOM_REC which will react to incoming 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 will be 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 will be copied to word array arwDataIn[0..1]. Its address is set at input DATA of the function block.

Both function blocks are called cyclically to ensure proper reaction to the incoming telegrams. In case of data reception or the completion of a read request the output NEW of the corresponding function block is set to TRUE (until next call of the function block).

../_images/39000d1be38c05050a33139000eba54e

The variable bPutEvent can be set to TRUE to add an event that contains data for the master to the slave’s event queue with the function block RCOM_TRANSMIT. After the function block is done the program dials the master to trigger an event poll in case of a successful connection to the master.