Copying an Array of memory tag in an array of OPC values

Hi folks,
I actually work on a project where I have to read/write a big amount of data from/in a Schneider M580 PLC.
The customer impose us a very short responsing time to do it.
At first, I tried to do it by using a “for” loop to write the data, one by one…but it asks to much time.
I try now to find a way to copy an entire block of data, for exemple the content of an array, directly in an other array of OPC tag.
Both function “system.tag.write” and “system.opc.writeValues” does not works.
What can I try to optimise the writing time of multiple variables?

system.opc.(read|write)Values() with large lists of target items that are consecutive in controller memory will be optimized by the driver into bulk reads/writes, if allowed by the protocol and the controller. If you can’t go fast enough using these calls, check for network latency (PLC protocols are crushed by even a little latency), and check for bottlenecks on the controller side. I’m not familiar with the M580, but if it is a really busy processor, it might not have enough spare CPU time to handle your customer’s requirements. Check your driver’s diagnostics for average and maximum response times.

Thanks for your answer…
I have a co-worker who works on the optimisation of the M580 communication speed efficiency.
But on my side, i need to find a way to send a large amount of values, in a minimum of time.
Thats why I’m looking for a way to optimise the time to send data in ignition. Writing 1000 datas one by one in a “for” loop takes about 600ms. I’m currently searching to send it with a method which allow me to send a block of data, like sendind an entire array or else…

Sending a block is best accomplished with system.opc.writeValues. The driver will do its best to optimize and write contiguous registers in the same request.

Ok, but when i try to use system.opc.writevalues by using Array type data I obtain this kind of error :
Java Traceback:

at org.python.core.Py.JavaError(Py.java:495)

at org.python.core.Py.JavaError(Py.java:488)

at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)

at com.inductiveautomation.ignition.common.script.ScriptManager$ReflectedInstanceFunction.__call__(ScriptManager.java:431)

at org.python.core.PyObject.__call__(PyObject.java:422)

at org.python.core.PyObject.__call__(PyObject.java:426)

at org.python.pycode._pyx341.f$0(<buffer>:31)

at org.python.pycode._pyx341.call_function(<buffer>)

at org.python.core.PyTableCode.call(PyTableCode.java:165)

at org.python.core.PyCode.call(PyCode.java:18)

at org.python.core.Py.runCode(Py.java:1275)

at org.python.core.Py.exec(Py.java:1319)

at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:215)

at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:89)

at org.python.util.InteractiveInterpreter.runsource(InteractiveInterpreter.java:70)

at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$InterpreterWorker.doInBackground(JythonConsole.java:476)

at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$InterpreterWorker.doInBackground(JythonConsole.java:464)

at javax.swing.SwingWorker$1.call(Unknown Source)

at java.util.concurrent.FutureTask.run(Unknown Source)

at javax.swing.SwingWorker.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: java.lang.ClassCastException: Cannot coerce value ‘ns=2;s=0:DevExample_1!OPC_WRITE’ into type: class [Ljava.lang.String;

at com.inductiveautomation.ignition.common.TypeUtilities.coerce(TypeUtilities.java:1299)

at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.coerce(PyArgumentMap.java:108)

at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.interpretPyArgs(PyArgumentMap.java:66)

at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.interpretPyArgs(PyArgumentMap.java:36)

at com.inductiveautomation.ignition.common.script.builtin.AbstractOPCUtilities.writeValues(AbstractOPCUtilities.java:85)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:186)

... 20 more

Traceback (most recent call last):
File “”, line 29, in
at com.inductiveautomation.ignition.common.TypeUtilities.coerce(TypeUtilities.java:1299)

at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.coerce(PyArgumentMap.java:108)

at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.interpretPyArgs(PyArgumentMap.java:66)

at com.inductiveautomation.ignition.common.script.builtin.PyArgumentMap.interpretPyArgs(PyArgumentMap.java:36)

at com.inductiveautomation.ignition.common.script.builtin.AbstractOPCUtilities.writeValues(AbstractOPCUtilities.java:85)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

java.lang.ClassCastException: java.lang.ClassCastException: Cannot coerce value ‘ns=2;s=0:DevExample_1!OPC_WRITE’ into type: class [Ljava.lang.String;

It doesn’t look like you’re calling the function with the arguments it expects, can you show your code?

system.opc.writeValues(“OFS_local”, “ns=2;s=0:DevExample_1!OPC_WRITE”, “Temp_write_2”)

Where OPC_WRITE is an OPC TAG (ARRAY) and Temp_write_2 is an MEMORY TAG (ARRAY) of the same number of element.
Here is a screen cap of the TAG explorer, I know what you are going to tell about the number of element in both array, i could reduce, but our customer ask for a very big amount of var.

Have you read the documentation for system.opc.writeValues?

https://docs.inductiveautomation.com/display/DOC79/system.opc.writeValues

It expects a list of item paths and a list of values, each value corresponding to an item path.

Further, you need to actually read the value of Temp_Write_2 first, because right now you’re trying to write the value “Temp_Write_2”.

If you’re trying to write only one tag, with an array value, you can actually try using the singular system.opc.writeValue instead.

Ok i’m a newbie in Ignition, I saw my mistake.
But it’s continue to send me the same error in the debugger.
If i try with a single write with this line :slight_smile:
system.opc.writeValue(“OFS_local”, “ns=2;s=0:DevExample_1!OPC_WRITE[1]”, 1)
It works perfectly!

With this function :
var =[system.tag.read(“Temp_write_2”).value]
print(var)
system.opc.writeValues(“OFS_local”, “ns=2;s=0:DevExample_1!OPC_WRITE”, var)

I obtain the same kind of error…

Before that the print(var) works perfectly, I obtain the value of the array Temp_write_2 in the debuger…

Your item paths need to be a list as well:

system.opc.writeValues("OFS_local", ["ns=2;s=0:DevExample_1!OPC_WRITE"], var)

or use the singular version of the call:

var = system.tag.read("Temp_write_2").value
system.opc.writeValue("OFS_local", "ns=2;s=0:DevExample_1!OPC_WRITE", var)
1 Like

This works as I want :slight_smile: :
_system.opc.writeValues(“OFS_local”, [“ns=2;s=0:DevExample_1!OPC_WRITE”], var)
The square brackets saved me!

Thanks guy! :sunglasses: