18:30, EEST
July 8, 2019
Hello,
Searching the forums and not having much success on how to write to the element of an array.
I’m using the Prosys Simulation Server and am trying to write to the StaticArrayVariables.DoubleArray item.
Here is the method:
public void setOpcArrayValue(String tagName, int index, String tagValue, OpcDataType dataType) {
// Create the Variant object from the string values (tagName, tagValue)
Variant val = getVariantFromString(tagValue, dataType);
// Update the Kuka output map
NodeId nodeId = outputNameMap.get(tagName);
Boolean ret = client.writeValue(nodeId, val, new NumericRange(index));
}
Here is the call to the method:
opcClient.setOpcArrayValue(“DoubleArray”, 2, val.toString(), OpcDataType.Double);
I’m receiving an exception here is snippet of that:
com.prosysopc.ua.ServiceException: ServiceFault: Bad_InternalError (0x80020000) “An internal error occurred as a result of a programming or configuration error.”
Diagnostic Info: ServiceFault: Bad_InternalError (0x80020000) “An internal error occurred as a result of a programming or configuration error.”
Diagnostic Info: java.lang.ClassCastException: java.lang.Double cannot be cast to [Ljava.lang.Object;
at com.prosysopc.ua.server.v.a(SourceFile:201)
I figure it’s because the val that I create the Variant for is not a Double[], but I’m not sure how to construct this write correctly, any help would be greatly appreciated.
fyi, the outputNameMap contains the mapping between the name of the tag and the NodeId so I don’t have to look it up each write.
Thank you.
10:52, EEST
April 3, 2012
Hi,
Per the UA specification if you use the IndexRange option in the Write Call, then the value given must always be an array, even if the range would only specify a single index. We could maybe improve this in the future so the SDK would do the conversion for you. Therefore you must pass a Double[] to the Variant in this case for now.
Unless the array is large usually it has just been easier to write it always as a whole. Also some servers might not support writing to a part of the array.
P.S.
Please note that in UA only the NodeIds needs to be unique. It is very well expected that multiple “tags”/nodes have the same BrowseNames or DisplayNames. Assuming you meant that by “tagName”, then I would not recommend having that kind of mapping. Additionally it is not a good idea to use the NamespaceIndexes (“2” here), you should always store them with the NamespaceUri (the index referes to the NamespaceArray Variable below the Server node). Nothing in the specification guarantees that the order is the same after a server restart (except the 0 is always the standard namespace). Usually however they are in the same order.
20:24, EEST
July 8, 2019
Thank you for the reply, I was able to write to the array variables under the StaticArrayVariables folder in the Prosys Simulation Server.
However, I’m having issues writing to an array from a production OPC server, I’m worried that this isn’t what I expect as far as what an array is. I have a screenshot from the Prosys client but I don’t know how to attach to this topic.
Basically the node looks like this
unit/gD_OPC_Doffer
+ unit/gD_OPC_Doffer.g_aw16OPC_POS_IN_FROM_DOFFER[
+ unit/gD_OPC_Doffer.g_aw16OPC_POS_IN_FROM_DOFFER[0]
+ unit/gD_OPC_Doffer.g_aw16OPC_POS_IN_FROM_DOFFER[1]
+ unit/gD_OPC_Doffer.g_aw16OPC_POS_IN_FROM_DOFFER[2]
+ unit/gD_OPC_Doffer.g_aw16OPC_POS_IN_FROM_DOFFER[3]
+ unit/gD_OPC_Doffer.g_aw16OPC_POS_IN_FROM_DOFFER[4]
My thought was I would be able to write to the “array” using;
Boolean ret = client.writeValue(nodeId, value, new NumericRange(index));
where:
NodeId = node returned for unit/gD_OPC_Doffer.g_aw16OPC_POS_IN_FROM_DOFFER
Index = i.e. 2
value = UInt16[]
Unfortunately I’m getting the following exception;
com.prosysopc.ua.StatusException: Bad_NotWritable (0x803B0000) “The access level does not allow writing to the Node.” StatusCode=Bad_NotWritable (0x803B0000) “The access level does not allow writing to the Node.”
In the screenshot I have it shows the AccessLevel as CurrentRead, CurrentWrite and UserAccessLevel as CurrentRead, CurrentWrite.
The WriteMask value is NONE (0) and the UserWriteMask is NONE (0)
14:40, EEST
April 3, 2012
Does your production OPC server allow writing to a single index? As I mentioned not all of them do support it. So of them only support writing the complete array. Note that the text of the StatusCodes are standardized, i.e. the server only sends the code, the text comes from the SDK. The server can send additionaly DiagnosticsInfo however, assuming it can and they are turned on (Objects/Server/ServerDiagnostics/EnabledFlag). You could also try checking if the server has any logs.
Can you just try writing the entire array at once, i.e. without the NumericRange entry and the value as whole array?
The AccessLevel is correct (WriteMask controls writing to other Attributes). However, please check that the AccessLevel is actually from the same exact NodeId to where you are writing. Note that in general OPC UA does not have such “bracket” notation in NodeIds or Browse/DisplayNames specifified, that is server specific logic. i.e. all of the nodes are separate and inidivudual nodes per se, but the server probably keeps the synchronized (or the backing data is the same). There is a ModellingRule, which can specify that a node ExposesItsArray, but how the actual subnodes are named is not defined.
P.S.
If that server happens to support the OPC UA 1.04 new Attribute AccessLevelEx, it could specify does it only support writing the whole array via the WriteFullArrayOnly bit. However our grapchical client does not yet visualize 1.04 Attributes (we are working on 4.x version of that which will show them), so you will need to use UaExpert to check. Pre 1.04 there is no good way to check this.
Most Users Ever Online: 1919
Currently Online:
11 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Heikki Tahvanainen: 402
hbrackel: 144
rocket science: 88
pramanj: 86
Francesco Zambon: 83
Ibrahim: 78
Sabari: 62
kapsl: 57
gjevremovic: 49
Xavier: 43
Member Stats:
Guest Posters: 0
Members: 728
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1529
Posts: 6471
Newest Members:
Marypof5711, roycedelargie91, kourtneyquisenbe, ellis87832073466, zkxwilliemae, gabriellabachus, Deakin, KTP25Zof, Wojciech Kubala, efrennowell431Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1032, Jimmy Ni: 26, Matti Siponen: 349, Lusetti: 0
Administrators: admin: 1