Referring the array elements one by one ends up generating a lot of write commands. At least, this is what I'm seeing working with the Modbus KEP OPC Server. If I build a tags list for the OPC write values command, the server process them one by one. If I use the OPC write value command and the right type array of values, it writes them all in one command.
The problem is that I'm not able to create the right type array. I can see that I'm not the only one.
Maybe you can clarify it to me. It seems that the Python array class is not fully implemented. It's there but it's not doing what it's supossed to do.
When I read from the OPC server
lstQValues = system.opc.readValue("KepServer", "ns=2;s=Channel.Device.DataArray")
print lstQValues.value
array(java.lang.short, [101, 202, 303, 404,...
I get a short array but most properties and methods are not implemented. But the array class
I tried to get the type code to use it to produce an array of the same type.
print lstQValues.ArrayType
print lstQValues.typecode
both commands fail.
When I try to create the array
from array import array
lstWrtValues = array('i', [1,2,3,4,5,6,7])
print lstWrtValues
I get something that looks like it but it's not recognized by the OPC server as a short array.
array('i', [1, 2, 3, 4,...
When I write using it
system.opc.writeValue("KepServer", "ns=2;s=Channel.Device.DataArray", lstWrtValues)
I get a Bad_TypeMismath error.
I tried other integer types, 'I', 'h', 'H', all of them fail. The weird thing is that the array class seems to work, at least parts of it. Method count works, append works, reverse doesn't seem to do anything. It's like the typecode is ignored and the array ends up being a regular list.
One workaround I found is to use the same array I get from the OPC server, populate it and send it back.
lstQValues = system.opc.readValue("KepServer", "ns=2;s=Channel.Device.DataArray")
lstWrtValues = lstQValues.value
lstWrtValues[0] = 1
lstWrtValues[1] = 2
lstWrtValues[2] = 3
lstWrtValues[3] = 4
lstWrtValues[4] = 5
system.opc.writeValue("KepServer", "ns=2;s=Channel.Device.DataArray", lstWrtValues)
It works and it does the right thing, all registers get written in one function 16 command. But it makes no sense. I should be able to create the array I need.
The change you mention for the next major release includes a full implementation of the array class?