Chennai
Chennai
Singapore
Mumbai
Switzerland
+91 44 4091 2000 Mon - Fri 09:00 - 18:30 766/1, TEZ, Sakthi Towers 1, Anna salai, Chennai 600 002.
+6584181583 Mon - Fri 09:00 - 18:30 68 Circular Road, #02-01, 049422, Singapore.
+91 98848 35702 Mon - Fri 09:00 - 18:30 5, Powai Lake Heights, Mumbai 400 072
+41 (0)91 225 81 00 Mon - Fri 09:00 - 18:30 Equvera - ISV Techno SAGL, Via Ligornetto 6A, 6855 Stabio, Switzerland
Ceritified
ISO 9001:2018
The Best
#1 in India
#1 in Europe
#1 in Asian-pacific
Number #1
AUTOMATION SOLUTION PROVIDER
Talk to an Expert

Controlling PLC coil registers status using MODBUS TCP

CONTROLLING PLC COIL REGISTERS STATUS USING MODBUS TCP

TASK

I need to control the status of three MODBUS TCP PLC controllers and make any signal when a state of a coil register changes from 0 to 1 or vice versa.

HOW TO

Since you have three devices, you will have to create three 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.

CONFIGURE 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.

TCP settings

SELECTING MODULES

Selecting modules

Note the order of the filter modules.

1

How it works:

  1. The data query module sends MODBUS queries to the device.
  2. The data parser module analyzes the device response, writes the values received from it to the VALUE1 and VALUE2 variables, and passes them to the filter modules.
  3. 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).
  4. The “Events generator” module waits for the moment when the ALARM variable appears and generates the ALARM1 or ALARM2 event depending on its value.
  5. 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).

MODBUS query

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.

Data processing script

Script text:

const max_values = 2; var values:array [1..max_values] of string; data_source_name: string = 'DATA_SOURCE_NAME'; data_source, store_name: string; i: integer; v_old, v_new: boolean; begin values[1] := 'VALUE1'; values[2] := 'VALUE2'; if IsVariableDefined(data_source_name) then data_source := GetVariable(data_source_name) else data_source := '?'; for i:=1 to max_values do begin if IsVariableDefined(values[i]) then v_new := GetVariable(values[i]) else v_new := false; store_name := data_source+'-'+values[i]; if IsVariableStored(store_name) then // retrieves a stored variable begin v_old := PopVariable(store_name); if v_old<>v_new then begin SetVariable('PLACE', store_name); if v_new then SetVariable('ALARM', '1') else SetVariable('ALARM', '2') end; end; PushVariable(store_name, v_new); end; end.

GENERATING EVENTS

Generating events

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.

Adding event handler

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.

Configuring event handler

Ready-to-use configuration that you can restore from the “File” menu you can download here
.

RELATED ARTICLES: CONTROLLING PLC COIL REGISTERS STATUS USING MODBUS TCP

MODBUS RTU, MODBUS ASCII, MODBUS/TCP

BACNET/IP

IEC 62056-21