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,
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,
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.
Thanks Kevin here is the snippet
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'
Okay, so like I said, that PLCValuesBool
variable contains QualifiedValue objects.
Quick way to get just the underlying values:
valuesToWrite = [qv.value for qv in PLCValuesBool]
@Kevin.Herron I will give this a try and thanks again for the help. I will let you know how it goes.
@Kevin.Herron worked like charm thanks again