Modbus TCP Server writing when value changes

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

Does any one have any resourses (example program, documents...) that could help for configuring a Modbus TCP server on PCS7. Thanks in advance.
3
Replies
939
Views
Using a Schneider M172P. I have a Modbus RTU master configured on RS485-2 (because only -2 can be a master), and a Modbus/TCP server configured on...
1
Replies
839
Views
Hi, I am using my Siemens 1515-2PN as Server for Modbus on TCP/IP. I am using one of the built-in RJ-45 ethernet ports. Does anyone know how many...
0
Replies
730
Views
Our manufacturing floor has several machines with PLCs which are not connected to our network. Instead, the ethernet port of the PLC is connected...
9
Replies
3,569
Views
Hello everyone i do understand that you can create modbus registers to be read by a Modbus Master using the Modbus TCP Server and they are...
6
Replies
2,941
Views
Top