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

**URL:** <https://forum.inductiveautomation.com/t/copying-an-array-of-memory-tag-in-an-array-of-opc-values/20661>\
**Category:** Ignition\
**Tags:** ignition79, scripting\
**Created:** [November 8, 2018, 10:14am UTC](https://forum.inductiveautomation.com/t/copying-an-array-of-memory-tag-in-an-array-of-opc-values/20661 "2018-11-08T10:14:57Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![p.revollet](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/p.revollet/32/6511_2.png) [@p.revollet](https://forum.inductiveautomation.com/u/p.revollet)\
**Post date:** [November 8, 2018, 10:14am UTC](https://forum.inductiveautomation.com/t/copying-an-array-of-memory-tag-in-an-array-of-opc-values/20661/1 "2018-11-08T10:14:57Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 8, 2018, 1:51pm UTC](https://forum.inductiveautomation.com/t/copying-an-array-of-memory-tag-in-an-array-of-opc-values/20661/2 "2018-11-08T13:51:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![p.revollet](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/p.revollet/32/6511_2.png) [@p.revollet](https://forum.inductiveautomation.com/u/p.revollet)\
**Post date:** [November 8, 2018, 2:15pm UTC](https://forum.inductiveautomation.com/t/copying-an-array-of-memory-tag-in-an-array-of-opc-values/20661/3 "2018-11-08T14:15:31Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 8, 2018, 2:17pm UTC](https://forum.inductiveautomation.com/t/copying-an-array-of-memory-tag-in-an-array-of-opc-values/20661/4 "2018-11-08T14:17:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![p.revollet](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/p.revollet/32/6511_2.png) [@p.revollet](https://forum.inductiveautomation.com/u/p.revollet)\
**Post date:** [November 8, 2018, 2:41pm UTC](https://forum.inductiveautomation.com/t/copying-an-array-of-memory-tag-in-an-array-of-opc-values/20661/5 "2018-11-08T14:41:05Z")

</div>

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;

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 8, 2018, 2:42pm UTC](https://forum.inductiveautomation.com/t/copying-an-array-of-memory-tag-in-an-array-of-opc-values/20661/6 "2018-11-08T14:42:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![p.revollet](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/p.revollet/32/6511_2.png) [@p.revollet](https://forum.inductiveautomation.com/u/p.revollet)\
**Post date:** [November 8, 2018, 3:14pm UTC](https://forum.inductiveautomation.com/t/copying-an-array-of-memory-tag-in-an-array-of-opc-values/20661/7 "2018-11-08T15:14:40Z")

</div>

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.  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/a/ad4ae9b130143328b68c883eafc5a2b856f6d22f.png)

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/9/935b4cd89782a232331bb5e923e52ce0ffe55344.png)

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 8, 2018, 3:18pm UTC](https://forum.inductiveautomation.com/t/copying-an-array-of-memory-tag-in-an-array-of-opc-values/20661/8 "2018-11-08T15:18:55Z")

</div>

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

[https://docs.inductiveautomation.com/display/DOC79/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.

---

<div class="post-metadata">

**Author:** ![p.revollet](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/p.revollet/32/6511_2.png) [@p.revollet](https://forum.inductiveautomation.com/u/p.revollet)\
**Post date:** [November 8, 2018, 4:21pm UTC](https://forum.inductiveautomation.com/t/copying-an-array-of-memory-tag-in-an-array-of-opc-values/20661/9 "2018-11-08T16:21:19Z")

</div>

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 🙂  
**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…

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 8, 2018, 4:28pm UTC](https://forum.inductiveautomation.com/t/copying-an-array-of-memory-tag-in-an-array-of-opc-values/20661/10 "2018-11-08T16:28:06Z")

</div>

Your item paths need to be a list as well:

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

```

or use the singular version of the call:

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

```

---

<div class="post-metadata">

**Author:** ![p.revollet](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/p.revollet/32/6511_2.png) [@p.revollet](https://forum.inductiveautomation.com/u/p.revollet)\
**Post date:** [November 9, 2018, 8:26am UTC](https://forum.inductiveautomation.com/t/copying-an-array-of-memory-tag-in-an-array-of-opc-values/20661/11 "2018-11-09T08:26:13Z")

</div>

This works as I want 🙂 :  
**\_system.opc.writeValues(“OFS\_local”, [“ns=2;s=0:DevExample\_1!OPC\_WRITE”], var)**  
The square brackets saved me!

Thanks guy! 🕶
