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: 81
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: 983
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: 81
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: 518

Currently Online:
8 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 135

pramanj: 86

Francesco Zambon: 81

rocket science: 77

Ibrahim: 76

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

TimK: 41

Member Stats:

Guest Posters: 0

Members: 683

Moderators: 16

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1467

Posts: 6261

Newest Members:

digitechroshni, LouieWreve, Kickbiche, karrimacvitie5, graciela2073, sagarchau, elviralangwell4, Donnavek, Eddiefauth, DonaldPooma

Moderators: Jouni Aro: 1010, Otso Palonen: 32, Tuomas Hiltunen: 5, Pyry: 1, Petri: 0, Bjarne Boström: 983, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Jimmy Ni: 26, Teppo Uimonen: 21, Markus Johansson: 42, Niklas Nurminen: 0, Matti Siponen: 321, Lusetti: 0, Ari-Pekka Soikkeli: 5

Administrators: admin: 1