Introduction

The design and implementation of the OptoMMP function blocks are strongly influenced by the following:

  • Common Behaviour Model
  • Modbus FB Library

Common Behaviour Model

The Common Behaviour Model is a standard means of supporting asynchronous operations within a CODESYS library.

A full implementation is available in the Common Behaviour Model Library.

The OptoMMP function blocks follow the Edge Triggered design. They specifically extend the ETrigTo function block to provide a timeout mechanism.

Modbus FB Library

OptoMMP is quite similar to the Modbus protocol. Both protocols provide an address space, and both have operations for reading or writing one or multiple addresses at a time.

The primary way to use Modbus in CODESYS is with the Modbus fieldbus support, with devices added to the project’s device tree. This is similar to adding groov I/O to the device tree.

Alternatively, a programmatic approach can be used with the Modbus FB Library. It provides a client function block that can be used by request function blocks for specific read or write operations.

The design of the OptoMMP function blocks closely follow the design of the Modbus FB library.

For example, here’s some simple Continuous Function Chart code. A BLINK function block (from the standard Util library) is pulsing the boolean variable named xLedOutput.

Pulse Example

Here are Modbus FB function blocks that write xLedOutput to a digital output (coil at address 583). The client connects and will attempt to reconnect if there’s an error and it goes offline. It sends the write request as soon as the previous one is finished.

CODESYS Modbus FB Example
Modbus FB example

Similarly, here’s the equivalent OptoMMP code. It also writes xLedOutput to a digital output (at address 0xF0221240). The client connects and will attempt to reconnect if there’s an error and it goes offline. It sends the write request as soon as the previous one is finished.

OptoMMP Example
OptoMMP Example

Next Step

Continue to the Hello, world! example.