Modbus TCP Server writing when value changes

kallileo

Lifetime Supporting Member
Join Date
Jun 2008
Location
Thessaloniki, Macedonia, Hellas
Posts
353
I have a custom IO board with Modbus TCP server running on it.
Modbus function codes implemented are for reading discrete input and inputs registers as well as read/write single holding register and single coils.

I'm going to use Codesys as Modbus TCP client to poll the inputs cyclically every 100ms which is the default setting.
I don't see a point doing the same for writing to holding registers and coils (physical relays on the board) so I think it would better to write to a coil only when the mapped variable changes from 0 to 1 or from 1 to 0 and not write continuously.
There is a "Trigger" option in Codesys Modbus channel setup that can be set to "Rising edge" of another variable that triggers the write on the coil or holding register.

I'm just not sure when exactly and how to activate rising edge to write the coil.

I guess something similar is happening in HMI software when a numeric value is entered into a label and it is transferred to the PLC only when the value changes.
 
Maybe it will be useful to someone in future.
I made the Modbus coil be set/reset according to the state of GVL.Output0 variable using Rising edge mode so the coil isn't written continuously in Cyclic mode.

Code:
//Copy Modbus mapped input variable to app variable
GVL.Input0 := GVL.CoilIn;

//Check app variable
R_TRIG_0(CLK:=GVL.Output0);
F_TRIG_0(CLK:=GVL.Output0);

//Mapped trigger variable for rising edge write
writeTriggerCoil := R_TRIG_0.Q OR F_TRIG_0.Q;

//Write to mapped Modbus output variable on rising edge
IF writeTriggerCoil THEN
	IF GVL.Input0 THEN
		GVL.CoilOut := FALSE;
	ELSE
		GVL.CoilOut := TRUE;
	END_IF
END_IF
 

Similar Topics

So I am working on a project and I am having problems trying to get this all to work. I had it working but lately I have been getting a fault on...
Replies
13
Views
4,863
Hi, Do you guys know of any marine (ABS or DNV) approved modbus TCP solution for Rockwell Controllogix? Our system: Redundant 1756-L72 - Act as...
Replies
1
Views
2,066
I tried to use AdvancedHMI as a Modubius Client and it does poll the data from a Modbus server. But I am unable to use AdvancedHMI as a server...
Replies
10
Views
3,060
Installed Peak V3.0 Modbus/TCP slave/server simulator on Windows 10 box. Configured a couple registers and attempted to read from it with a box...
Replies
2
Views
2,382
does anyone have good experience with the sorcery of using a Panelview with Firmware at V9.0 and KEPserver V5.19 ? i do have the right...
Replies
1
Views
1,448
Back
Top Bottom