Controlling PLC coil registers status using MODBUS TCP
Download a Free Trial Version. It allows you to try all features! Plugins can be downloaded separately here
I need to control a status of three MODBUS TCP PLC controllers and make any signal when a state of a coil regiter changes from 0 to 1 or vice versa.
Since you have 3 devices, you will have to create 3 identical configurations that will differ only in their IP addresses and the numbers of the devices. If the devices have the same MODBUS address and differ only in their IP addresses, you can create one configuration and add all three IP addresses to it.
Configuring a TCP connection with your devices.
Most probably, it is the computer that will initiate a connection to the device. So the program will run in the client mode.
Note the order of the filter modules.
How it works:
- The data query module sends MODBUS queries to the device.
- The data parser module analyzes the device respond, writes the values received from it to the VALUE1 and VALUE2 variables and passes them to the filter modules.
- The "Script Execute" filter module analyzes the status of the VALUE1 and VALUE2 variables and compares them to their previous values (if there are any). If any value changes, this module adds a new variable named ALARM whose value reflects the change of the signal (from 0 to 1 or vice versa).
- The "Events generator" module waits for the moment when the ALARM variable appears and generates the ALARM1 or ALARM2 event depending on its value.
- The "Events notification" module on the Event handling tab executes the action specified for each of the events (for instance, plays a sound or shows a message).
Configuring the parameters of querying MODBUS devices
Click "Configure" next to the "Data Query Module" list and add a data query (Action –> Add).
Data processing script
Select the "Script Execute" module in the list and click "Configure" under the module. You should specify the script in the new dialog box.
const max_values = 2;
var values:array [1..max_values] of string;
data_source_name: string = 'DATA_SOURCE_NAME';
data_source, store_name: string;
v_old, v_new: boolean;
values := 'VALUE1';
values := 'VALUE2';
if IsVariableDefined(data_source_name) then
data_source := GetVariable(data_source_name)
data_source := '?';
for i:=1 to max_values do
if IsVariableDefined(values[i]) then
v_new := GetVariable(values[i])
v_new := false;
store_name := data_source+'-'+values[i];
if IsVariableStored(store_name) then
// retrieves a stored variable
v_old := PopVariable(store_name);
if v_old<>v_new then
if v_new then
Configuring event handlers
Open the "Events notification" module configuration dialog box. Click the New Handler button. Specify the event name and its descriptions. You need to specify two handlers for two events: ALARM1 and ALARM2.
These events will appear in the tree to the left. Select an event in the tree and configure the actions that will be executed when the event occurs. You can specify individual parameters for each event handler.
Ready-to-use configuration that you can restore from the "File" menu you can download here.