Device Commit
The Device Commit action writes the device variables held in the trigger's internal buffers through the device manager to the device driver to the device.
When a trigger starts it execution, all variables referenced by the trigger's actions are read into internal buffers. The variables' values are read from or written to this internal buffer when the variables are referenced by any of the trigger's actions. The internal buffer is written to the devices when the trigger completes its execution. This process maximizes performance of the trigger execution.
To bypass this internal buffering, the Device Commit action forces a write of the device variables from the internal buffers through the device manager and device drivers to the devices.
Background
You can use the Device Commit action in a trigger to flush the device variable write buffer to the attached devices. As the trigger executes, all writes to a device variable are written to a buffer, and when the trigger execution ends, the buffer is flushed to the devices. This is done to maximize the performance of variable writes to the devices.
As an example, suppose you have a trigger that has two Set actions and a Wait action.
- Set D[1000] to 1
- Wait 2000 ms
- Set D[1000] to 0
Each Set action setting a value for a
device variable. When the trigger executes, D[1000] is set
to 1 in the write buffer, and the Wait
action pauses the trigger for 2000 milliseconds. When the trigger execution resumes, the second
Set action sets D[1000] to zero in the
write buffer, and then overwrites the previous value of 1
that is already in the buffer. When trigger execution ends, the buffer is flushed and
D[1000] is set to zero in the attached device. The trigger never actually writes 1 to D[1000] at any point
during execution.
Adding a Device Commit action between
the two Set actions, would enable the
value of the first Set action to be
written to the PLC.
When this trigger executes, its behavior will be different.
The trigger will set D[1000] to 1 in the write
buffer.
Then DeviceCommit will
cause the write buffer to be flushed and D[1000] will be
set to 1 in the attached device. The trigger will then wait
for 2000 milliseconds; after which time, the second
Set action will set D[1000] to zero in the
write buffer. When trigger execution ends, the trigger will
flush the write buffer and then set D[1000] to zero in the
attached device. The different behavior is that D[1000]
gets set to 1 for 2 seconds, and then set back to zero.
Device Commit considerations
Device variables are normally "written to" when they are the destination variable in an action. For example, a Set action has a source variable and a destination variable.
When a trigger starts it execution, all variables referenced by the trigger's actions are read into internal buffers. The variables' values are read from or written to this internal buffer when the variables are referenced by any of the trigger's actions. The internal buffer is written to the devices when the trigger completes its execution. This process maximizes performance of the trigger execution.
In cases where all device variables need to be written directly to the devices and not just into the internal trigger buffers, the Device Commit action is used. These cases need to take into account the overall application logic in the triggers and in the devices to understand the dynamic interaction of all parts of the application. The Device Commit action does take additional resources in terms of processing time (compared to for example a Set action), since the trigger engine and device driver must communicate down to the physical devices. This includes the communication across the network to the device.
The internal trigger buffers (for example the destination variable of a Set action) are written to the devices when the trigger completes its execution.