# Using system.opc.writeValue vs system.opc.writeValues

**URL:** <https://forum.inductiveautomation.com/t/using-system-opc-writevalue-vs-system-opc-writevalues/63664>\
**Category:** Ignition\
**Tags:** ignition81, scripting\
**Created:** [September 1, 2022, 12:13am UTC](https://forum.inductiveautomation.com/t/using-system-opc-writevalue-vs-system-opc-writevalues/63664 "2022-09-01T00:13:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hcrowe](https://avatars.discourse-cdn.com/v4/letter/h/7feea3/32.png) [@hcrowe](https://forum.inductiveautomation.com/u/hcrowe)\
**Post date:** [September 1, 2022, 12:13am UTC](https://forum.inductiveautomation.com/t/using-system-opc-writevalue-vs-system-opc-writevalues/63664/1 "2022-09-01T00:13:51Z")

</div>

Hi all I am having issues figuring out how to use system.opc.writeValues I keep getting errors not sure if it is related to opc or the controls logic PLC I am trying to write to. Any guidance would be appreciated.

Thanks,

 ![Working Code](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/0/30e60c70ae7470a96febadc8f1e5dff3c1920e9d.png)

 ![Bad Code.PNG](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/d/dd2e185865684e0e68f868c7804a2d1743d73628.jpeg)

---

<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:** [September 1, 2022, 12:19am UTC](https://forum.inductiveautomation.com/t/using-system-opc-writevalue-vs-system-opc-writevalues/63664/2 "2022-09-01T00:19:57Z")

</div>

I think the problem is that your `PLCValuesBool` variable contains the result of `system.opc.readValues`, which is a list of _QualifiedValue_, and this is not what you should be passing into the `system.opc.writevalues` call. It wants a list of the underlying value.

Fix your post so that it uses code and code blocks instead of images of text and I’ll show you an example of how to convert the `PLCValuesBool` into something you could write back. Use the “Preformatted text” button in the post editor.

---

<div class="post-metadata">

**Author:** ![hcrowe](https://avatars.discourse-cdn.com/v4/letter/h/7feea3/32.png) [@hcrowe](https://forum.inductiveautomation.com/u/hcrowe)\
**Post date:** [September 1, 2022, 5:18pm UTC](https://forum.inductiveautomation.com/t/using-system-opc-writevalue-vs-system-opc-writevalues/63664/3 "2022-09-01T17:18:44Z")

</div>

Thanks Kevin here is the snippet

```auto
itemPathsBool = []
itemPathsReal = []
itemPathsWord = []
CLXitemPathsBool = []
CLXitemPathsReal = []
CLXitemPathsWord = []
server = "Ignition OPC UA Server"

try:
  for i in range(0, 44, 1):
    
    for j in range(0, 8, 1):
      pathBool = 'ns=1;s=[SiemensRack' + '0' + ']DB3001,X' + str(i) + '.' + str(j)
      itemPathsBool.append(pathBool)
    
  PLCValuesBool = system.opc.readValues(server, itemPathsBool)   
  for i in range(0, 11, 1):
      for j in range(0, 32, 1):
        CLXpathBool = 'ns=1;s=[Kitchen_Exp]DINT_FromSiemens[' + str(i) + '].' + str(j)
        CLXitemPathsBool.append(CLXpathBool) 
       
  #for l in range(0, len(PLCValuesBool), 1):
  Quality = system.opc.writeValues(server,CLXitemPathsBool,PLCValuesBool)
  print Quality
  #for l in range(0, len(PLCValuesBool), 1):
    
# for l in range(0, len(PLCValuesBool) - 1, 1):
# print CLXitemPathsBool[l], PLCValuesBool[l].value
    #system.opc.writeValues(server, CLXitemPathsBool[l], PLCValuesBool[l].value)
  
# for p in range(44, 56, 2):
# pathWord = 'ns=1;s=[SiemensRack' + '0' + ']DB3001,W' + str(p)
# itemPathsWord.append(pathWord) 
# PLCValuesWord = system.opc.readValues(server, itemPathsWord)   
# for q in range(0, len(PLCValuesWord), 1): 
# #print len(PLCValuesWord)
# system.tag.write('[default]Siemens_Tags/IF_ToRockWell/DB3001Word[' + str(q) + ']', PLCValuesWord[q].value)
# #print PLCValuesWord[q].value
#    
# for m in range(4004, 4208, 4):
# pathReal = 'ns=1;s=[SiemensRack' + '0' + ']DB3001,REAL' + str(m)
# itemPathsReal.append(pathReal)  
# PLCValuesReal = system.opc.readValues(server, itemPathsReal)   
# for o in range(0, len(PLCValuesReal), 1): 
# #print len(PLCValuesReal)
# system.tag.write('[default]Siemens_Tags/IF_ToRockWell/DB3001Real[' + str(o) + ']', PLCValuesReal[o].value)  
# #nano_endTime = nanoTime()
# #print "Read From PLC " + str((nano_endTime - nano_startTime)/1000000) + " milliseconds" 
  
  system.tag.write('[default]Siemens_Tags/IF_ToRockWellError', 0)       
except:
  system.tag.write('[default]Siemens_Tags/IF_ToRockWellError', 1)
  print 'ERROR'

```

---

<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:** [September 1, 2022, 5:26pm UTC](https://forum.inductiveautomation.com/t/using-system-opc-writevalue-vs-system-opc-writevalues/63664/4 "2022-09-01T17:26:01Z")

</div>

Okay, so like I said, that `PLCValuesBool` variable contains QualifiedValue objects.

Quick way to get just the underlying values:

```auto
valuesToWrite = [qv.value for qv in PLCValuesBool]

```

---

<div class="post-metadata">

**Author:** ![hcrowe](https://avatars.discourse-cdn.com/v4/letter/h/7feea3/32.png) [@hcrowe](https://forum.inductiveautomation.com/u/hcrowe)\
**Post date:** [September 1, 2022, 6:14pm UTC](https://forum.inductiveautomation.com/t/using-system-opc-writevalue-vs-system-opc-writevalues/63664/5 "2022-09-01T18:14:10Z")

</div>

@Kevin.Herron I will give this a try and thanks again for the help. I will let you know how it goes.

---

<div class="post-metadata">

**Author:** ![hcrowe](https://avatars.discourse-cdn.com/v4/letter/h/7feea3/32.png) [@hcrowe](https://forum.inductiveautomation.com/u/hcrowe)\
**Post date:** [September 1, 2022, 7:51pm UTC](https://forum.inductiveautomation.com/t/using-system-opc-writevalue-vs-system-opc-writevalues/63664/6 "2022-09-01T19:51:17Z")

</div>

@Kevin.Herron worked like charm thanks again
