12:21, EEST
December 20, 2021
I have a problem with updating the variable subscription.
I noticed this behavior:
When I change the value of a variable:
the value of the subscriptions linked to the variable are updated correctly.
When I change the state of the variable value:
the status of subscriptions is not updated.
But if I create a new subscription, the subscription attributes are updated correctly (value, status),
I tried with version 4.10 and version 5.0 of the Prosys SDK.
I am using the OPC UA Expert client.
Questions:
Am I using the correct method to update the variable’s Statuscode?
Should subscriptions update when the value or state of the variable changes?
Thanks.
Best regards,
Francesco
13:03, EEST
April 3, 2012
Hi Francesco,
SDK is not designed in a way that you should modify the returned DataValue. I’m not sure can we change DataValue to be truly immutable, but it should be assumed to be as such (except in e.g. IoManagerListener where the whole API is designed so that you modify the DataValue given as parameter to the listener methods). This includes that you cannot modify any value you have given as value afterwards. Though, SDK automatically clones the DataValue to be sure, but the getValue doesn’t clone (it probably should, but I’m not sure of the perf implications so we might be unable to do that).
Basically our design relies on the UaNodes telling the items that their value has changed (the item registers a listener to the node). But if you mutate the DataValue directly, SDK has “no way of knowing” this happened, thus there is no knowledge of the change. The initial value for the item is read differently, thus that is why it appeared to work for new subscriptions.
Thus, you must always use the ‘setValue’ methods. You should be able to use null for the value or use setValue(new DataValue(StatusCode.valueOf(StatusCodes.Bad_DataUnavailable)))’ if you just want to set the statuscode (basically the non-DataValue overrides of ‘setValue’ just make DataValues internally). Then they should update always for existing subscriptions.
18:32, EEST
December 20, 2021
Hi Bjarne,
the setValue method works correctly: I can update the state of the variable.
Example:
DataValue curr = uaVariable.getValue();
DataValue dataValue= null;
if(daaConnected) {
dataValue = new DataValue(curr.getValue(), StatusCode.valueOf(StatusCodes.Uncertain), curr.getSourceTimestamp(), null);
} else {
dataValue = new DataValue(curr.getValue(), StatusCode.valueOf(StatusCodes.Bad_DataUnavailable), curr.getSourceTimestamp(), null);
}
uaVariable.setValue(dataValue);
Thanks,
Francesco
Most Users Ever Online: 1919
Currently Online:
28 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: 727
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1525
Posts: 6456
Newest Members:
ernestoportus31, martin123, rickie5305, shaylamaggard4, rickyjuarez140, jonathonmcintyre, fannielima, kristiewinkle8, rust, christamcdowallModerators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1028, Jimmy Ni: 26, Matti Siponen: 346, Lusetti: 0
Administrators: admin: 1