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
Override standard condition method
December 2, 2019
15:22, EET
Avatar
Xavier
Member
Members
Forum Posts: 43
Member Since:
March 26, 2014
sp_UserOfflineSmall Offline

Hi,

I’m using SDK 4 and I would like to create my own type of Alarm but also to use your implementation of the optionnal Shelve treatment (ShelvedStateMachineTypeNode). This is working fine but now I need to extend your implementation of some methods in ShelvedStateMachineTypeNode and I don’t know how to proceed.

I’ve seen that I can set a static implementation of the method but then I won’t be able to use your implementation. And I don’t see how I could tell the SDK to use my extension of ShelvedStateMachineTypeNode…

Thank you 🙂

December 2, 2019
17:47, EET
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1032
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

Good Question…

(Sorry for the long post)

Assuming I understood you correctly, the answer depends a bit on does your Alarm type actually enhance the statemachine (information-model-wise) or do you just which to do something to our existing implementation. Because if you model your alarm you could override the ShelvingState InstanceDeclaration to a subtype of ShelvingStateMachineType, and then when you codegenerate you would get a XXXTypeNode for that (which would then extend our implementation).

If modeling is not the option, alternatively maybe you could do that via a listener like MyMethodManagerListener in the SampleConsoleServer?

As a last resort assuming you would want do the following (so that the “PING!” would show up in logs, just as an example), you could do:

@TypeDefinitionId("nsu=http://opcfoundation.org/UA/;i=2929") // IMPORTANT! this must be like this
public class MyShelvedStateMachineTypeNode extends ShelvedStateMachineTypeNode {

  private static final Logger logger = LoggerFactory.getLogger(MyShelvedStateMachineTypeNode.class);

  protected MyShelvedStateMachineTypeNode(NodeManagerUaNode nodeManager, NodeId nodeId, QualifiedName browseName,
      LocalizedText displayName) {
    super(nodeManager, nodeId, browseName, displayName);
  }

  @Override
  protected void onTimedShelve(ServiceContext serviceContext, Double shelvingTime) throws StatusException {
    super.onTimedShelve(serviceContext, shelvingTime);
    logger.info("PING!");
  }

}

And then do the following (tested within MyNodeManager of the SampleConsoleServer example):

  private void createMyOwnAlarm() throws Exception {
    // Configuration for NodeBuilder as we need Optional nodes
    TypeDefinitionBasedNodeBuilderConfiguration.Builder conf = TypeDefinitionBasedNodeBuilderConfiguration.builder();
    conf.addOptional(UaQualifiedName.standard(ShelvedStateMachineType.LAST_TRANSITION));
    conf.addOptional(UaQualifiedName.standard(AlarmConditionType.SHELVING_STATE));

    // Override TypeDefinition linking of the class
    getServer().getRegisteredClasses().registerClass(MyShelvedStateMachineTypeNode.class);

    NodeBuilder nb = createNodeBuilder(AlarmConditionTypeNode.class, conf.build());
    nb.setName("INSTANCE");
    AlarmConditionTypeNode node = nb.build();

    // Return TypeDefinition linking back to the original one
    getServer().getRegisteredClasses().registerClass(ShelvedStateMachineTypeNode.class);

    // Link the instance somewhere to the existing address space (just an example)
    getNodeManagerTable().getNodeManagerRoot().getObjectsFolder().addReference(node, ReferenceTypeIdentifiers.Organizes,
        false);
  }

.. and it should work. However note that it is a bit hacky solution, since the registered classes (from codegen) are not really designed for re-registering, thus we output warnings from that as typically that would be an error. Preferably we should find a better solution, but that should work in the meantime.

Let me know if that helped.

P.S. Generally we don’t yet have a “best way” to implement stuff to generated classes. Current ones are sort of best-effort solutions. The problem is that the subtyping only works of the leaf (UA) types (e.g. your MyXXX cannot be intersected to the inheritance tree after it is done), therefore it works only in some cases (e.g. here). The generated XXXTypeNode classes are designed that the method implementation could be put there, however as seen here they are then pretty much locked up (unless you buy the source edition). The static setters were added to help with this, however they would only work here if the SDK’s internal implementation would use them (which they normally don’t; but if yes you could delegate them), so mainly for the Standard model they could be used to implement a Method we have not yet implemented or completely override an implementation. Let’s see if we can make this better in the future.

December 4, 2019
16:02, EET
Avatar
Xavier
Member
Members
Forum Posts: 43
Member Since:
March 26, 2014
sp_UserOfflineSmall Offline

Thank you.

Your first solution by just extending the Node and using it with the condegen is working fine, I did not think it was possible to override the type of ShelvingState directly 🙂

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 1919

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

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

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

Administrators: admin: 1