My goal is to write an alarm flag back to PLC when read value is higher than a limit.
It is assumed that:
You have configured the communication settings on the device:
1. Create a new configuration from the main window using the "Green Plus" button. (fig. 1). This example shows the connection settings for MODBUS TCP. If your device uses MODBUS RTU, look here. If you've already configured the connection, then go to step #4.
Fig. 1: IP connection settings
2. Go to your configuration setting: Modules - Query Parser Filter. Select the "MODBUS TCP" or "MODBUS RTU" plugin from lists. Then click the "Setup" button.
Fig. 2: Selecting the MODBUS plugin
3. Click "Action - Add request" and add your request for reading data (fig. 3). Of course, in your application, you should configure the request parameters for your data (Offset, Registers to read, Response items).
Fig. 3: Adding the "Read" request
4. Click "Action - Add request" again and add a new request for writing data (fig. 4). The MODBUS function code should be:
Select the "Event" request method. Then specify the "WRITE" event identifier. You may use another identifier, but you should change in the next steps too.
The "Response items" group actually defines items to write. The "Default value" property defines a value to be written.
Fig. 4: Adding the "Write" request
5. Configure any of three filter plugins to generate the "WRITE" event on the necessary conditions.
5.1. Expressions - the simple plugin, but it includes all necessary operations (fig. 5, 6). The expression in this example compares the "VALUE" incoming value (from the "Read" request), and generates an event if the value is greater than 100.
Fig. 5: Expressions plugin
SEND_EVENT_IF(VALUE > 100, 'WRITE')
Fig. 6: Expression
5.2. Script execute - the most flexible plugin. It allows implementing any logic, but it requires some programming skills (fig. 7, 8). The script sends an event if the "VALUE" incoming value is greater than 100.
Fig. 7: Script Execute plugin
const name = 'VALUE'; var v: variant; begin if IsVariableDefined(name) then begin v := GetVariable(name); if v > 100 then SendEvent('WRITE'); end; end.
Fig. 8: Script
5.3. Events generator - the simplest plugin, but it operates with text data. Therefore it can only compare equal values. (fig. 9, 10).
Fig. 9: Events generator plugin
Fig. 10: The rule
6. Click the "OK" button and save all settings.
7. Now, the MODBUS plugin sends requests and parses responses for periodic requests. A filter plugin analyzes data for every request and sends an event to the MODBUS plugin when it is necessary. Keep in mind; the filter plugin cannot generate events if it did not receive data from the parser.
The "Script Execute" plugin can send one or more named values with the event signal. It allows you to specify a value and the MODBUS offset in the event.
ADDRESS - the optional MODBUS offset.
VALUE - the optional value. The MODBUS plugin searches for a response item with the "VALUE" name. If the item exists, the plugin uses the value from the event instead of the default value.
const name = 'VALUE'; var v: variant; begin if IsVariableDefined(name) then begin v := GetVariable(name); if v > 100 then SendEventEx('WRITE' ['ADDRESS', 1, 'VALUE', 2] ); end; end.