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
Setting Manufacturer in DeviceType not possible
March 3, 2021
13:04, EET
Avatar
fred
Member
Members
Forum Posts: 41
Member Since:
January 27, 2012
sp_UserOfflineSmall Offline

I have a type extending DeviceType to see its attributes like Manufaturer. Strange thing is that I have to ‘activate’ them manually (see below) as an error message says it’s an optional node when calling setManufacturer. However, looking at the code below, I can’t get the optional node to be set correctly and hope you might give me the hint on that one.
Many thanks.

//Optional properties for DeviceType
final ExpandedNodeId deviceTypeNode = new ExpandedNodeId(“http://opcfoundation.org/UA/DI/”, 1002);
conf.addOptional(UaBrowsePath.from(deviceTypeNode, UaQualifiedName.from(“http://opcfoundation.org/UA/DI/”, DeviceType.MANUFACTURER)));

March 3, 2021
13:46, EET
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1032
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

Sounds odd, most likely this misses some small detail somewhere..

If I take your question as-is, the following should just work after models are registered and loaded:

NodeManagerUaNode nm = server.getNodeManagerUaServer(); // just something to test
DeviceTypeNode device = nm.createInstance(DeviceTypeNode.class, "TESTDEVICE");
device.setManufacturer(new LocalizedText("TEST"));
server.getNodeManagerRoot().getObjectsFolder().addReference(device, ReferenceTypeIdentifiers.Organizes, false);

And I can see the value in a client application.

This is because the “Manufacturer” is a Mandatory ModellingRule’d node, basically it exists always. In OPC UA InstanceDeclrations (e.g. “Manufacturer” under DeviceType) for a TypeDefinition (e.g. “DeviceType”) have a so called ModellingRule. Those that have ModellingRule Optional are not by default instantiated.

Can you clarify how did you do the “extending” or what you mean by that? Like as-is I would assume you would have created another model, which depends on the DI model and defined a subtype for the DeviceType, but that doesn’t sync with the “see it’s attributes” text part. Note also, that in OPC UA terms, those are not Attributes, but Properties (or Components, depends on the reference type). Is it possible to show the complete code that shows the createInstance etc. calls?

The “Manufacturer” InstanceDeclaration has HasModellingRule Mandatory, thus it should have been instantiated by the SDK. This is assuming normal usage, e.g. createInstace/createNodeBuilder. And just as a clarification, just in case, the instantiation must be done that way, you cannot e.g. define a java-subclass and change the constructor to be public (or edit the codegen code). Those are called by the SDK internally (thus they are generated as protected) and only make “that node”, all subnodes, which are fetched in e.g. setters are made separately (of their own respective type) during the createInstance process internally. If if somehow are calling the constructor yourself, it would result in the error you did see. Though, most likely it is not this.

Also… seems the error message is the same also for Mandatory nodes (which the “Manufacturer” InstanceDeclration is, though “ManufacturerUri” is Optional), thus the error might be misleading here, sorry, that should be fixed in some future version of the codegen. In general under normal conditions it should be “an impossible scenario” that a Mandatory node was not instantiated.

For setting values to Optional-modellingruled subnodes, you must use code like you showed so that the actual node exists in the address space (basically codegen mostly creates syntax sugar for you). Though, since you seem to have codegenerated the models, you should be able to just use DiIds.DeviceType instead of defining that deviceTypeNode id. Some future SDK version would probably put the component/properties names as UaQualifiedName instead of raw String, but that is the way it works currently. Also, note that namespace of the component/property BrowseName could be in a differen namespace (if subtyping is involved, since it must keep the original namespace, otherwise it would create a second, different property).

March 3, 2021
15:21, EET
Avatar
fred
Member
Members
Forum Posts: 41
Member Since:
January 27, 2012
sp_UserOfflineSmall Offline

Hi,

well, TESTDEVICE works but setManufacturer() also fails in there that’s the weird behavior in the code I produced as the file DeviceType.java also lists setManufacturer() as being @Mandatory and not optional…

Figured out now that DeviceType extends ComponentType in which Manufacturer is declared being @Optional

Might this be the root cause?

public interface ComponentType extends TopologyElementType {

@Optional
LocalizedText getManufacturer();

@Optional
void setManufacturer(LocalizedText value) throws StatusException;

}

March 3, 2021
16:30, EET
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1032
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Note that I said it should work as-is and does so in our test environment. Thus there is some difference either in your code or the environment that makes it not work (or as third that I misunderstood something), or in theory a newer version of the model could have come out that breaks things (the DI model has gotten multiple versions over the years). Basically the following was not included, but basically we do the equivalent of:

server.registerModel(DiServerInformationModel.MODEL);
server.getAddressSpace().loadModel(DiServerInformationModel.getLocationURI());

before the lines I showed in the previous post. After the server starts, the Value (“”, “TEST”) can be seen e.g. in UaExpert via Root/Objects/TESTDEVICE/Manufacturer, thus that should be “it works” condition here?

The extending from ComponentType should not be an issue, that is normal, a subtype in OPC UA is allowed to override an Optional ModellingRule to Mandatory. That being said, we did have an issue way, way in the past where this kind of situation could have caused a problem since we incorrectly relied on Set iteration order (so stuff did break for Java 8 back then, since it changed), but that was fixed in SDK 2.2.2 (https://downloads.prosysopc.com/opcua/release_notes2.2.2-638.html).

Thus, what version of the SDK are you using? Also what version of Java (+what vendor)? And what version of the DI model (listed at the start of the model, e.g. Model ModelUri=”http://opcfoundation.org/UA/DI/” Version=”1.02.2″ PublicationDate=”2020-06-02T00:00:00Z”, please specify both version and the publicationdate)?

March 3, 2021
16:54, EET
Avatar
fred
Member
Members
Forum Posts: 41
Member Since:
January 27, 2012
sp_UserOfflineSmall Offline

I sent an email with some details, hope it’s not blocked….

March 3, 2021
17:11, EET
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1032
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

I can see your email, might take a while to analyze

March 3, 2021
17:13, EET
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1032
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Or maybe not, but I continue via email.

March 4, 2021
11:18, EET
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1032
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Adding a note here, that the issue was resolved by using the latest DI model.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 1919

Currently Online:
14 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:

kourtneyquisenbe, ellis87832073466, zkxwilliemae, gabriellabachus, Deakin, KTP25Zof, Wojciech Kubala, efrennowell431, wilfredostuart, caitlynfajardo

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

Administrators: admin: 1