means that your white spacing is not consistent, i.e. you used a tab on one line and 4 spaces on another or something like that. Try deleting all of your white space and put the same number of spaces in. Also it would help if you wrapped your code in the code /code wrapping so everyone can see the spacing you used.
Yes, you’re right. Thank you
But right now i have new error :
[color=#FF0000]ERROR [TagChangeScriptManager ] [10:11:46,281]: Error executing tag change script: GlassPlant/2nd Input Goods Counter
Traceback (innermost last):
File “<TagChangeScript:GlassPlant/2nd Input Goods Counter>”, line 5, in ?
NameError: dateDiff
at org.python.core.Py.NameError(Py.java)
at org.python.core.PyFrame.getglobal(PyFrame.java)
at org.python.core.PyFrame.getname(PyFrame.java)
at org.python.pycode._pyx35.f$0(<TagChangeScript:GlassPlant/2nd Input Goods Counter>:5)
at org.python.pycode._pyx35.call_function(<TagChangeScript:GlassPlant/2nd Input Goods Counter>)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyCode.call(PyCode.java)
at org.python.core.Py.runCode(Py.java)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:395)
at com.inductiveautomation.ignition.common.script.TagChangeScriptManager$TagChangeScriptHandler$Runner.run(TagChangeScriptManager.java:175)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)[/color]
Is there any solution other than using dateDiff function, to compute time elapsed between two date string?
#Create two calendar instances
cal1=Calendar.getInstance()
cal2=Calendar.getInstance()
if newValue.value==1: #Set cal1 to the tag holding the last time input was true.
cal1.setTime(system.tag.getTagValue(“Test/LastTrue”))
#Set cal2 to the current timestamp
cal2.setTime(newValue.timestamp)
#Find difference in seconds
Elapsed=float(cal2.getTimeInMillis()-cal1.getTimeInMillis())/1000
#Update LastTrue timestamp to current one.
system.tag.writeToTag("Test/LastTrue",cal2.getTime())
#Write elapsed time results to tag (float)
system.tag.writeToTag("Test/Elapsed",Elapsed)
[/code]
I used a momentary button in the attached window to turn Input on and off to test. Window.vwin (3.96 KB)
We typically try to shy away from listing out the things that can’t be done. It is not just that expression function that can’t be used in Gateway Scripts - none of the expression functions can be used in Gateway Scripts. Additionally, it’s not just Gateway Scripts that expression functions can’t be used, but any scripts anywhere. Expressions also can’t be used in any SQL calls, nor can they be used in many other places. Which is why it is typically easier for us to list the places that a function can be used, which in this case is in an expression. I also want to mention that in the future, you can reach the training department at training@inductiveautomation.com for any inquiries into the manual.