We have a situation where periodically a few rows of information requires removal from a large array of UDTs on PLCs. The PLC has tags that Ignition populates that are used to identify the row to be removed. Ignition then increments the Trigger [DINT] PLC tag to start the PLC process. There are two scenarios from here:
- The PLC executes the task and updates the PLC Echo [DINT] tag to equal Tigger indicating successful completion; or
- The process will time out due to a connection, power-down, or other unknown failure resulting in Echo not being updated.
The source data for the PLC data updates comes from a database table. I would like this to run as a sequence, processing one record at a time from (1) to (6) below. The desired process is as follows:
- Ignition to execute a gateway timed script to look for required updates.
- Ignition will place the list of required updates in a module-level list.
- For each item in the list, Ignition will send a request to the PLC
3a) Write row parameters to the PLC tags viasystem.opc.writeValues()
3b) Write Trigger = Trigger + 1 viasystem.opc.writeValue()
3c) Record startTime assystem.date.now()
or alternatively use Java Instant - Ignition will read Trigger and Echo value from the OPC server item at a high frequency (~2x the timed task frequency on the PLC so about 50 ms?).
- When either (Echo == Trigger) or (
system.date.now()
- startTime) > timeoutPeriod then take the next action:
5a) If Echo == Trigger update the database row "Plc Confirm" field with a timestamp and the list item as completed, then move to the next item in the module-level list.
5b) If elapsed time is greater than the timeout limit then update the database row "Last Attempt" field with a timestamp and the list item as failed then move to the next item in the module-level list. - Write to logs with process result
The "Last Attempt" field is used in the SQL query to allow the timed script to wait for a defined period before trying that PLC again.
I am unsure how to implement: a) the tasks of reading the PLC tag values at high frequency looking for Trigger == Echo wrapped in a timeout without using sleep() or other methods that tie up the thread unnecessarily; and b) waiting for the whole sequence to complete before advancing to the next list item without "pausing" the thread. Any ansyc or later methods would need to carry enough information to update the correct database and list row.
Maybe @pturmel has some ideas on how to get this done safely? Are there any examples of a responsive/fast process using the Trigger-Echo handshake where the PLC is the side updating the Echo part of the handshake?