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
How to implement/extend OffNormalAlarmType
February 24, 2012
10:09, EET
Avatar
fred
Member
Members
Forum Posts: 41
Member Since:
January 27, 2012
sp_UserOfflineSmall Offline

I want to extend the OffNormalAlarmType with one of my own. The class looks like this:

public class MyOwnAlarmType extends OffNormalAlarmType {
private final NodeId MyOwnAlarmTypeId;
private LocalizedText ownVariable;

public MyOwnAlarmType(NodeManagerUaNode nmun, NodeId nodeid, String string, Locale locale) {
super(nmun, nodeid, string, locale);

MyOwnAlarmTypeId = new NodeId(getNodeManager().getNamespaceIndex(), MyNodeManagerImpl.getNextTypeNodeId());
}

public MyOwnAlarmType(NodeManagerUaNode nmun, NodeId nodeid, QualifiedName qn, LocalizedText lt) {
super(nmun, nodeid, qn, lt);

MyOwnAlarmTypeId = new NodeId(getNodeManager().getNamespaceIndex(), MyNodeManagerImpl.getNextTypeNodeId());
}

@Override
protected NodeId getDefaultTypeDefinition() {
return MyOwnAlarmTypeId;
}

@Override
protected void initEventFields() throws SecurityException, NoSuchMethodException, StatusException {
super.initEventFields();

NodeId myOwnVariableId = new NodeId(getNodeManager().getNamespaceIndex(), MyNodeManagerImpl.getNextObjectNodeId());
registerReflectiveInstanceProperty("OwnVariable", myOwnVariableId, MyNodeManager.getOwnVariableType().getNodeId());
}

public LocalizedText getOwnVariable) {
return ownVariable;
}

public void setStatusFunctional(int index) {
LocalizedText[] aStatus = MyNodeManager.getOwnVariableType().getEnumStrings();
this.ownVariable = aStatus[index];
}
}

This Alarm should be part of a class:

public class MyStatusObjectNode extends UaObjectNode {
private CacheVariable status;
private static MyOwnAlarmType myOwnAlarmType;

public MyStatusObjectNode(NodeManagerUaNode nmun, NodeId nodeid, String string, Locale locale) throws StatusException {
super(nmun, nodeid, string, locale);

initialize();
}

public MyStatusObjectNode(NodeManagerUaNode nmun, NodeId nodeid, QualifiedName qn, LocalizedText lt) throws StatusException {
super(nmun, nodeid, qn, lt);

initialize();
}

private void initialize() throws StatusException {
setTypeDefinition(MyParentNode.getStatusTypeDefinition());

int nsIdx = MyNodeManagerImpl.getNsIdx();
status = new CacheVariable(nodeManager,
new NodeId(nsIdx, MyNodeManagerImpl.getNextVariableNodeId()), "Status", Locale.ENGLISH);

status.setDataType(MyNodeManager.getOwnVariableType());
LocalizedText[] actStatus = MyNodeManager.getOwnVariableType().getEnumStrings();

status.updateValue(actStatus[MyStatusTypeNode.OK]);
addComponent(status);

MyOwnAlarmType = new MyOwnAlarmType(nodeManager,
new NodeId(nsIdx, MyNodeManagerImpl.getNextObjectNodeId()), "MyOwnAlarmType", Locale.ENGLISH);

MyOwnAlarmType.setSource(this);
MyOwnAlarmType.setInput(status);
MyOwnAlarmType.setStatusFunctional(MyStatusTypeNode.ERROR);
MyOwnAlarmType.setEnabled(true);
addComponent(MyOwnAlarmType);
}
}

When the constructor of class MyOwnAlarmType is called, the super constructor is called and raises a NullPointerException. What have I done wrong?

Thanks for any help.

Exception in thread “main” java.lang.NullPointerException
at com.prosysopc.ua.server.nodes.UaInstanceNode.registerOverridePlainMethod(Unknown Source)
at com.prosysopc.ua.server.nodes.opcua.ConditionType.initEventFields(Unknown Source)
at com.prosysopc.ua.server.nodes.opcua.AcknowledgeableConditionType.initEventFields(Unknown Source)
at com.prosysopc.ua.server.nodes.opcua.AlarmConditionType.initEventFields(Unknown Source)
at com.prosysopc.ua.server.nodes.opcua.OffNormalAlarmType.initEventFields(Unknown Source)
at abc.opcuaserver.events.MyOwnAlarmType.initEventFields(Unknown Source)
at com.prosysopc.ua.server.nodes.opcua.BaseEventType.a(Unknown Source)
at com.prosysopc.ua.server.nodes.opcua.BaseEventType.(Unknown Source)
at com.prosysopc.ua.server.nodes.opcua.ConditionType.(Unknown Source)
at com.prosysopc.ua.server.nodes.opcua.AcknowledgeableConditionType.(Unknown Source)
at com.prosysopc.ua.server.nodes.opcua.AlarmConditionType.(Unknown Source)
at com.prosysopc.ua.server.nodes.opcua.DiscreteAlarmType.(Unknown Source)
at com.prosysopc.ua.server.nodes.opcua.OffNormalAlarmType.(Unknown Source)
at abc.opcuaserver.events.MyOwnAlarmType.(Unknown Source)

February 24, 2012
11:22, EET
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1009
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

fred said


public MyOwnAlarmType(NodeManagerUaNode nmun, NodeId nodeid, String string, Locale locale) {
super(nmun, nodeid, string, locale);

MyOwnAlarmTypeId = new NodeId(getNodeManager().getNamespaceIndex(), MyNodeManagerImpl.getNextTypeNodeId());
}

public MyOwnAlarmType(NodeManagerUaNode nmun, NodeId nodeid, QualifiedName qn, LocalizedText lt) {
super(nmun, nodeid, qn, lt);

MyOwnAlarmTypeId = new NodeId(getNodeManager().getNamespaceIndex(), MyNodeManagerImpl.getNextTypeNodeId());
}

@Override
protected NodeId getDefaultTypeDefinition() {
return MyOwnAlarmTypeId;
}

@Override
protected void initEventFields() throws SecurityException, NoSuchMethodException, StatusException {
super.initEventFields();

NodeId myOwnVariableId = new NodeId(getNodeManager().getNamespaceIndex(), MyNodeManagerImpl.getNextObjectNodeId());
registerReflectiveInstanceProperty("OwnVariable", myOwnVariableId, MyNodeManager.getOwnVariableType().getNodeId());
}

When the constructor of class MyOwnAlarmType is called, the super constructor is called and raises a NullPointerException. What have I done wrong?

Thanks for any help.

Exception in thread “main” java.lang.NullPointerException
at com.prosysopc.ua.server.nodes.UaInstanceNode.registerOverridePlainMethod(Unknown Source)
at com.prosysopc.ua.server.nodes.opcua.ConditionType.initEventFields(Unknown Source)
at com.prosysopc.ua.server.nodes.opcua.AcknowledgeableConditionType.initEventFields(Unknown Source)
at com.prosysopc.ua.server.nodes.opcua.AlarmConditionType.initEventFields(Unknown Source)
at com.prosysopc.ua.server.nodes.opcua.OffNormalAlarmType.initEventFields(Unknown Source)
at abc.opcuaserver.events.MyOwnAlarmType.initEventFields(Unknown Source)
at com.prosysopc.ua.server.nodes.opcua.BaseEventType.a(Unknown Source)
at com.prosysopc.ua.server.nodes.opcua.BaseEventType.(Unknown Source)
at com.prosysopc.ua.server.nodes.opcua.ConditionType.(Unknown Source)
at com.prosysopc.ua.server.nodes.opcua.AcknowledgeableConditionType.(Unknown Source)
at com.prosysopc.ua.server.nodes.opcua.AlarmConditionType.(Unknown Source)
at com.prosysopc.ua.server.nodes.opcua.DiscreteAlarmType.(Unknown Source)
at com.prosysopc.ua.server.nodes.opcua.OffNormalAlarmType.(Unknown Source)
at abc.opcuaserver.events.MyOwnAlarmType.(Unknown Source)

The base constructor is trying to assign the TypeDefinitionId, but MyOwnAlarmTypeId is not initialized yet at this point, so getDefaultTypeDefinition() returns null. I suggest that you initialize it in getDefaultTypeDefinition() , if it is not done yet.

February 24, 2012
11:35, EET
Avatar
fred
Member
Members
Forum Posts: 41
Member Since:
January 27, 2012
sp_UserOfflineSmall Offline

Thank you this solved this issue.

However, now another exception is raised: Exception in thread “main” java.lang.RuntimeException: ExternalNode does not support getBrowseName()

Is it raised because the type of my ReflectiveInstanceProperty has no getBrowseName() method implemented?

This type extends UaDataTypeNode.

February 24, 2012
13:18, EET
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1009
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

It might be. ExternalNode is used (internally) for nodes that are referred, but which are not found from the address space.

Have you added your OwnDataType to the noed manager already?

February 27, 2012
7:57, EET
Avatar
fred
Member
Members
Forum Posts: 41
Member Since:
January 27, 2012
sp_UserOfflineSmall Offline

Jouni Aro said

It might be. ExternalNode is used (internally) for nodes that are referred, but which are not found from the address space.

Have you added your OwnDataType to the noed manager already?

I have changed the reflectiveInstanceProperty to be of boolean type, but with the same effect. The error itself is raised from super.initEvents(), thus before creating my instance property.

registerReflectiveInstanceProperty("OwnVariable", myOwnVariableId, Identifiers.Boolean);

Additional information: When I use OffNormalAlarmType instead of MyOwnAlarmType (which extends OffNormalAlarmType), it works without any error. Of course, without this OwnVariable I added to MyOwnAlarmType.

MyOwnAlarmType = new OffNormalAlarmType(nodeManager,
new NodeId(nsIdx, MyNodeManagerImpl.getNextObjectNodeId()), "MyOwnAlarmType", Locale.ENGLISH);
February 27, 2012
10:21, EET
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1009
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

Do you have the stack trace of the exception?

February 27, 2012
10:38, EET
Avatar
fred
Member
Members
Forum Posts: 41
Member Since:
January 27, 2012
sp_UserOfflineSmall Offline

Jouni Aro said

Do you have the stack trace of the exception?

Sent by email…

February 27, 2012
14:47, EET
Avatar
Jouni Aro
Moderator
Moderators
Forum Posts: 1009
Member Since:
December 21, 2011
sp_UserOfflineSmall Offline

The problem was that getDefaultTypeDefinition() was returning a new NodeId. It must return an ID to a valid UaType object that is already in the address space, when the object instances are created.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

Currently Online:
11 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 135

pramanj: 86

Francesco Zambon: 81

rocket science: 75

ibrahim: 75

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

fred: 41

Member Stats:

Guest Posters: 0

Members: 708

Moderators: 16

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1465

Posts: 6252

Newest Members:

christi10l, ahamad1, Flores Frederick, ellenmoss, harriettscherer, shanonhumphreys, KupimotoblokfuB, tamhollander5, paulinafcf, bridgette18l

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

Administrators: admin: 1