Script oneshot

I have a timer on a screen. Within this timer there is a script running every cycle (actionPerformed). The script is looking at a tag on the server, and if this value == 4 then a section of the script needs to run just one time. (ONESHOT).

I’m setting a value at the end of this section to indicate that the section has run, but it takes a while for the tag to update with the new value and for me to read it on a subsequent scan. Is there a better way of handling how to “oneshot” some logic in the script language?

If you need this to be one time globally, you’ll need to implement the timer and scripting in the gateway, not on a screen. Otherwise, you can use the newValue & oldValue properties of a propertyChange event to determine if your conditions are met.

not global, so a timer on the screen works fine. newValue/oldValue properties are the property of the timer are they not? The script is pretty much running on the changes to the timer value. I have a lot of things getting calculated in this timer, and only one small section is looking for a value (tag) to change, and when it changes, I want to run a section of logic just once.

[quote][code]
#variables
data = event.source.parent.getComponent(‘Table’).data
type = data.getValueAt(row,2)
jID = data.getValueAt(row,3)
doneBit = “[default]/StationTags/PowerT/Inverter/Station1/torque1Done”

torque1Status = system.tag.read(event.source.parent.getComponent(‘Station Name’).dataPath + “torque1Status”).value

#type = 4 for torque tool operations.
if type == 4:
if torque1Status == 0:
jointData = system.db.runPrepQuery("SELECT * FROM jointid WHERE jointID = (?) ", [jID])
jData = system.dataset.toDataSet(jointData)
toolName = jData.getValueAt(0,2)
setpoint = jData.getValueAt(0,3)
batchSize = jData.getValueAt(0,4)
VIN = “this is temp vin”
myID = system.util.getClientId()
jointID = jID

	startPath = "TorqueToolStart"
	args = {"toolName":toolName, "pSet":setpoint, "batchSize":batchSize, "clientID":myID, "VIN_ID":VIN, "jointID":jointID, "doneBit":doneBit}
	id = system.sfc.startChart(startPath, args)
	
	system.tag.write(event.source.parent.getComponent('Station Name').dataPath + "torque1Status", 1)[/code]

[/quote]

So here is a stripped down version of what is going on. When “type” turns to a 4, I want to run the logic just once to start an instance of the SFC.

To attempt the oneshot I’m using the value of “torque1status”. If it is a zero I run the logic and at the end turn it to a 1. The SFC will turn it back to a zero at the end of the chart. The problem is the time it takes to both write and read to the tag. Is there a better way to handle this? Can I pause the logic on a write to insure that the write is complete before moving forward? (this is really part of another issue in the script, not here). The big issue here is that if it comes around to run again before the write has completed, then it will run a second instance of the SFC.

no additional suggestions?

Have you tried using system.tag.writeSynchronous?

[quote=“Kevin.Herron”]Have you tried using system.tag.writeSynchronous?[/quote]Can’t use that from the event dispatch thread. The UI will freeze.

Michael, your propertyChange event needs a construct something like this:if event.propertyName=='type': if event.newValue == 4 and event.oldValue != 4: # Do something once when type becomes '4' .....However, the key piece of information omitted from your initial post is that you aren’t looking at a simple property, but a dataset. And it’s a dataset on a different component. You need this script to be in the propertyChange event on the table, and look like this:if event.propertyName=='data': newType = event.newValue.getValueAt(row,2) oldType = event.oldValue.getValueAt(row,2) if newType == 4 and oldType != 4: # Do somethingSubstitute an appropriate property reference on event.source for ‘row’.