I have a transaction group that writes data to my sql database. I would like to trigger this group to write once to my database when an unrelated opc tag goes high.
Personally, I would use a gateway tag change script and write the SQL store call within the script as opposed to using the transaction group.
(post deleted by author)
Ok, I just read a little bit about the gateway event scripsand watched a video. I right clicked on Project Library and selected New Script. The window opened to write a script, however, there was no column on the left that has the ways to trigger it. I don’t see the Startup, Update, Shutdown, Timer, Tag Change, Message, and Scheduled options that I was in the video that I watched.
Those aren't in the project library. Those are in the gateway events dialog, adjacent to the project library.
(It is recommended, for various reasons, to have the actual code in the project library as a function and called as a one-liner from the event.)
Got it,
Now, if I create the script in project library and it is named “Low_Pressure_Alarm”, what is the one-liner that I use in the gateway events that calls that function?
I have Insert Into Alarms (ID, MachineNumber,AlarmDate,AlarmNumber,AlarmData)
ID is an autonumber field. Should I leave it out? If so, do I start with a “,” in the values?
Values (,1,now(),1,opc tag)
How do I insert an opc tag for the AlarmData field?
Project library scripts, as full scripts, are only executed once, when first referenced. You are expected to use python def
to create named functions in the script, along with any global constants you might want. (Best to do any imports outside of any def
, too.)
The one-liner for a tag change event would be something like:
Low_Pressure_Alarm.someFunctionName(event, initialChange, newValue, previousValue)
(Consider naming the script more generically and creating appropriately named functions within.)
The newValue
will be the QualifiedValue for just the subscribed tag. You will need to use system.tag.readBlocking()
to retrieve the other tags you want to process.