Set a bit high if any OPC item in group changes value

I’m not sure if I’m correct in thinking I could use FSQL for this. I’d like to monitor all the set points on a machine and if any one of them changes, set a bit high.

I made a standard group with all the set points, and I also put in the “SPUpdate” bit. I set all the set point items to read-only. I then set the group to trigger if any item changes values, and then set the transaction success to set the “SPUpdate” bit to 1. But then that triggers the group again and that bit never goes low. I’m positive the way I set this up is incorrect, so I could use your expertise.

I have a feeling FSQL can do what I’m trying to do, I just can’t picture how to set it up.

Hi,

Yes, this does sound like a bit of a problem- having the status bit in the group will cause the trigger to fire each time it gets set to 0 or 1.

Unfortunately I can’t think of any quick way to get it to work with just one group… there might be a way, but all opc items get taken into account for the async change, and you can’t write to an item that’s not in the group.

Probably the easiest thing to do would be to have 2 groups and use the database to communicate between them.

Your first group would be set up as is, only without the status bit. The items are all read only, so it won’t write to the database, therefore just set its settings to “update first row” of a table called “unused” or something.

The next group has just your status bit in it. It’s set to run every 1sec or so (or as quickly as you need to feed back the status), no trigger. Set group mode to “Bi-directional, db wins”. Set it to update “custom”, with a table name of “machine_status” and a where clause of “machine_id=1”. The last part is optional, you can have it update the first row, but I’m just trying to be robust in case there are more machines. FactorySQL will create the column and the row for you anyhow, so it’s pretty easy.

Back in the first group, create an action item, and set it to “SQL Query” mode. As the expression, use:

UPDATE machine_status SET statuscode=1 WHERE machine_id=1

Of course, “statuscode” should be the actual name of the status item column.

And that’s it- by default, the action item will only run when the group is triggered. So, an item changes, the group triggers, and 1 is written to the db field. The other group synchronizes that with the plc, writing it down. The plc sets it back to 0, which gets sync’d back to the db, and it’s ready to go again.

Like I said, there might be another way to do it, but that’s what came to mind. Hope it helps.

Colby, thanks again for your extremely quick reply. You guys are always reliable.

I was thinking along the right lines. I created two groups. One to write to the DB and one to read back to the PLC. But I hadn’t thought about writing to the DB from a SQL query action item. I was writing all the set points to the table. I also had never used the “DB wins” or “OPC wins” selections before. Those make a difference. Either way, I have it working now. Works like a charm.