Synchronization with modbus function blocks in applicationΒΆ

Access to Modbus communication ressources must be synchronized. At a time only a single:

  • COM_MOD_MAST function block is permitted to send a request via one COM port
  • ETH_MOD_MAST/ETHx_MOD_MAST function block is permitted to send a request to one IP address

Other function block instances have to wait until the request has been completed.

Synchronizing access to the communication ressources (COM port for Modbus RTU and IP address for Modbus TCP) must be done by utilizing the following global variables:

OPENDEVMOD_ENABLED When set to TRUE the Open Device Integration library is allowed to access the communication ressource specified by OPENDEVMOD_RTU_COM or OPENDEVMOD_TCP_IP_ADDR. To allow upload or download of parameters by Automation Builder the application must set this flag when requests are pending.
OPENDEVMOD_RTU_COM The COM port to use currently for Open Device Integration is 0 when no Modbus RTU request is pending or processed.
OPENDEVMOD_TCP_IP_ADDR The IP address to use currently for Open Device Integration is 0 when no Modbus TCP request is pending or being processed.
OPENDEVMOD_RTU_ACTIVE Indicates that a Modbus RTU request is currently processed. The application must not send a request via the COM port specified by OPENDEVMOD_RTU_COM as long as this flag is TRUE.
OPENDEVMOD_TCP_ACTIVE Indicates that a Modbus TCP request is currently processed. The application must not send a request to the IP address specified by OPENDEVMOD_TCP_IP_ADDR as long as this flag is TRUE.

The following FBD program shows an example where the application reads device parameters from two devices connected to two different COM ports. After completing a request the application gives the Open Device Integration library the chance to access the COM port. The library will send a request only if a request from Automation Builder is pending. The library gives the application the chance to access the COM port after each request. Thus the Open Device Integration library and the application access the COM port alternating. It is critical crucial for the synchronization to work properly that all Modbus function blocks are processed by the same task.

../_images/d43b7835af6031580a33139013ec688d