Delay Gatway script

Hi All,
Looking for some help on delaying a Gateway event script based off of Tag Change. I am new to scripting in ignition. We are logging test data after the test completes and moves the data block to the completed test in the plc. The scan time on the length of registers takes a few seconds for all the data to populate. without a delay we miss or duplicate data from the previous test. the Code is simple here is a shortened version of what we have.

API =“Well Test data/API”).value
Gas =“Well Test data/Gas”).value
Oil =“Well Test data/OIL”).value
Water =“Well Test data/Water”).value
TestDuration =“Well Test data/TestDuration”).value
TestTime =“Well Test data/TestTime”).value
WellName =“Well Test data/WellName”).value

system.db.runPrepUpdate(“INSERT INTO Well1 (API,Gas,Oil,Water,TestDuration,TestTime,WellName) values (?,?,?,?,?,?,?)”,

I have tried using system.util.invokeLater(1000) but cant seem to get it to work

Here is the error I get
Caused by: org.python.core.PyException: Traceback (most recent call last): File “”, line 12, in AttributeError: ‘com.inductiveautomation.ignition.common.script.Imm’ object has no attribute ‘invokeLater’

system.util.invokeLater only exists in the client/designer. You should create an asynchronous thread with system.util.invokeAsync, and run your code in that if you really need a delay.

However, you probably don’t actually need a delay- if it’s a timing sensitive operation, use system.opc.readValues() to trigger a direct, blocking read from the PLC, rather than relying on the scan class to get you the values in time.

Thank you sir I will give this a try!!

I am having trouble grabbing multiple values.

Reading a single value works ok

server = “Ignition OPC-UA Server”
path = “[WightUnit]HRF102”
qualifiedValue = system.opc.readValue(server, path)
print qualifiedValue.getValue()

I have tried

server = “Ignition OPC-UA Server”
path = “[WightUnit]HRF102”,"[WightUnit]HRF104","[WightUnit]HRF106","[WightUnit]HRF108"
qualifiedValues = system.opc.readValues(server, path)
print qualifiedValues.getValues()

Error Traceback (most recent call last):
File “”, line 4, in
AttributeError: ‘array.array’ object has no attribute ‘getValues’

print [value.getValue() for value in qualifiedValues]

Thank you for your help sir!!
I also found this to work,
Values = map(lambda qv: qv.getValue(), qualifiedValues)

your solution looks cleaner!

1 Like