hi everyone i would like to know if there is any way to change a string or int variable to time, I currently have something like this
Contador = system.tag.read(dateFormat(addSeconds(midnight(now()),"[.]MemTimeDiff","HH:mm:ss"))
hi everyone i would like to know if there is any way to change a string or int variable to time, I currently have something like this
Contador = system.tag.read(dateFormat(addSeconds(midnight(now()),"[.]MemTimeDiff","HH:mm:ss"))
Youâre mixing Jython and the expression language here. Where are you trying to use this? Also, either way, the conversion from string to time would need to be applied to the tag value, rather than trying to read the value of the the string to time conversion as your code above does.
I want it to save the data in a database
if currentValue.value == False and currentValue.value != previousValue.value and not initialChange:
INS = "INSERT INTO PAROS ( Linea, Maquina, TipoParo, TiempoParo, Fecha) VALUES ( ?, ?, ?, ?, ?)"
Contador = system.tag.read(dateFormat(addSeconds(midnight(now()),"[.]MemTimeDiff","HH:mm:ss"))
Fecha = system.date.now()
system.db.runPrepUpdate(INS,[ "Item", "Prueba", "Prueba", Contador.value, Fecha],"TOY")
dateFormat(addSeconds(midnight(now(
[.]MemTimeDiff
with the full path to the tagâsomething like the example in the next point. EDIT: You actually can use this here, as others have pointed out.
.value
before trying to manipulate it:system.tag.read("[default]MemTimeDiff").value
system.tag.read
as in your example. Youâll end up with something like the following (untested).timeDiff = system.tag.read("[default]MemTimeDiff").value
Contador = system.date.format(system.date.addSeconds(system.date.midnight(system.date.now()), timeDiff), "HH:mm:ss")
@witman this topic will help at least clarify the relative tagpath (tl;dr Itâs a tag event script)
You actually can use relative paths in Jython for example in a tag change script
I get an error back
([default]CONTEO DE FALLA/Falla safety fance open 1, valueChanged) Error executing tag event script: Traceback (most recent call last): File "tagevent:valueChanged", line 6, in valueChanged AttributeError: 'com.inductiveautomation.ignition.common.script.Imm' object has no attribute 'data'
com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "", line 6, in valueChanged AttributeError: 'com.inductiveautomation.ignition.common.script.Imm' object has no attribute 'data'
at org.python.core.Py.AttributeError(Py.java:173)
at org.python.core.PyObject.noAttributeError(PyObject.java:930)
at org.python.core.PyObject.getattr(PyObject.java:925)
at org.python.pycode._pyx97434703.valueChanged$1(:9)
at org.python.pycode._pyx97434703.call_function()
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyBaseCode.call(PyBaseCode.java:301)
at org.python.core.PyFunction.function___call__(PyFunction.java:376)
at org.python.core.PyFunction.call(PyFunction.java:371)
at org.python.core.PyFunction.call(PyFunction.java:361)
at org.python.core.PyFunction.call(PyFunction.java:356)
at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:649)
at com.inductiveautomation.ignition.common.sqltags.scripts.TagScriptManager$FunctionInvokerImpl.run(TagScriptManager.java:493)
at com.inductiveautomation.ignition.common.sqltags.scripts.AbstractTagScript.invoke(AbstractTagScript.java:33)
at com.inductiveautomation.ignition.common.sqltags.scripts.TagScriptManager$Task.invoke(TagScriptManager.java:442)
at com.inductiveautomation.ignition.common.sqltags.scripts.TagScriptManager$TagScriptDispatcher.run(TagScriptManager.java:405)
at com.inductiveautomation.ignition.common.execution.impl.BasicExecutionEngine$ThrowableCatchingRunnable.run(BasicExecutionEngine.java:518)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.python.core.PyException: Traceback (most recent call last): File "", line 6, in valueChanged AttributeError: 'com.inductiveautomation.ignition.common.script.Imm' object has no attribute 'data'
... 24 common frames omitted
this is the code
if currentValue.value == False and currentValue.value != previousValue.value and not initialChange:
INS = "INSERT INTO PAROS (Linea, Maquina, TipoParo, TiempoParo, Fecha) VALUES (?, ?, ?, ?, ?)"
timeDiff = system.tag.read("[.]MemTimeDiff").value
Contador = system.date.format(system.date.addSeconds(system.date.midnight(system.data.now()), timeDiff), "HH:mm:ss")
Fecha = system.date.now()
system.db.runPrepUpdate(INS,["Item","Prueba","Prueba",Contador.value,Fecha],"TOPY_MW")
You have a typo in your code.
You have data
when you should have date
if currentValue.value == False and currentValue.value != previousValue.value and not initialChange:
INS = "INSERT INTO PAROS (Linea, Maquina, TipoParo, TiempoParo, Fecha) VALUES (?, ?, ?, ?, ?)"
timeDiff = system.tag.read("[.]MemTimeDiff").value
Contador = system.date.format(system.date.addSeconds(system.date.midnight(system.date.now()), timeDiff), "HH:mm:ss")
Fecha = system.date.now()
system.db.runPrepUpdate(INS,["Item","Prueba","Prueba",Contador.value,Fecha],"TOPY_MW")
([default]CONTEO DE FALLA/Falla safety fance open 1,
valueChanged) Error executing tag event script:
Traceback (most recent call last): File
"tagevent:valueChanged", line 6, in valueChanged
TypeError: addSeconds(): 2nd arg can't be coerced
to int
It doesn't like timeDiff
, is that tag of type string? You can make the timeDiff
tag of type int or maybe use
int(system.tag.read("[.]MemTimeDiff").value)
is already saving time.
only instead of saving 40 min. save me 40 seconds.
if currentValue.value == False and currentValue.value != previousValue.value and not initialChange:
INS = "INSERT INTO PAROS (Linea, Maquina, TipoParo, TiempoParo, Fecha) VALUES (?, ?, ?, ?, ?)"
timeDiff = int(system.tag.read("[.]../MemTimeDiff").value)
Contador = system.date.format(system.date.addSeconds(system.date.midnight(system.date.now()), timeDiff), "HH:mm:ss")
Fecha = system.date.now()
system.db.runPrepUpdate(INS,["Item","Prueba","Prueba",Contador,Fecha],"TOPY_MW")
Is [.]../MemTimeDiff
minutes? If so, you need to add minutes, not seconds:
Contador = system.date.format(system.date.addMinutes(system.date.midnight(system.date.now()), timeDiff), "HH:mm:ss")