Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed Topic RSS sp_TopicIcon
HELP Subscription update
September 21, 2023
12:21, EEST
Avatar
Francesco Zambon
Member
Members
Forum Posts: 83
Member Since:
December 20, 2021
sp_UserOfflineSmall Offline

I have a problem with updating the variable subscription.

I noticed this behavior:
When I change the value of a variable:

uaVariable.setValue(new DataValue(new Variant(0), StatusCode.GOOD, new DateTime(), new DateTime()));

the value of the subscriptions linked to the variable are updated correctly.

When I change the state of the variable value:

uaVariable.getValue().setStatusCode(StatusCode.valueOf(StatusCodes.Bad_DataUnavailable));

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

September 21, 2023
13:03, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1028
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

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.

September 21, 2023
18:32, EEST
Avatar
Francesco Zambon
Member
Members
Forum Posts: 83
Member Since:
December 20, 2021
sp_UserOfflineSmall Offline

Hi Bjarne,

the setValue method works correctly: I can update the state of the variable.

Example:

UaVariable uaVariable = (UaVariable) uaNode;
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

Forum Timezone: Europe/Helsinki

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, christamcdowall

Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1028, Jimmy Ni: 26, Matti Siponen: 346, Lusetti: 0

Administrators: admin: 1