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
EventListener returning multiple events
June 29, 2018
10:11, EEST
Avatar
shivani12
New Member
Members
Forum Posts: 2
Member Since:
June 29, 2018
sp_UserOfflineSmall Offline

Hi Team ,

I am using opc ua java stack for connecting to OPC UA Server. I have a made a subscription to a node that is returning me Alarms as Event.
For this i have used a EventListner referring one in the SampleConsoleClient.

Ii shoud get only 8 fields in Variant[] array, but i am getting 32 fields, i.e multiples Alarm(Events ) are coming whereas Ideally i should get only one event as i have generated only one.

Please help me with the solution ASAP as i have a deadline by 2 July.

Regards,
Shivani Soni

June 29, 2018
10:36, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 983
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

Is the server made with our Java SDK as well or something else? Because the data given by the MonitoredEventItemListener.onEvent comes from the server pretty much as-is.

How is your EventFilter for the MonitoredEventItem made?

Does this happen also if you test with the SampleConsoleClient?

June 29, 2018
11:39, EEST
Avatar
shivani12
New Member
Members
Forum Posts: 2
Member Since:
June 29, 2018
sp_UserOfflineSmall Offline

Hi,

Bjarne Boström said
Hi,

Is the server made with our Java SDK as well or something else? Because the data given by the MonitoredEventItemListener.onEvent comes from the server pretty much as-is.

How is your EventFilter for the MonitoredEventItem made?

Does this happen also if you test with the SampleConsoleClient?  

HI,

My server is made of something else.

Please find the below code I am using .
EventFilter Code ———————–

protected final QualifiedName[] eventFieldNames = { new QualifiedName(“EventType”), new QualifiedName(“Message”),
new QualifiedName(“SourceName”), new QualifiedName(“Time”), new QualifiedName(“Severity”),
new QualifiedName(“ActiveState/Id”), new QualifiedName(“ConditionName”),
new QualifiedName(“ActiveState/EffectiveDisplayName”) };

———————————————————————————-
protected EventFilter createEventFilter(QualifiedName[] eventFields) {

NodeId eventTypeId = Identifiers.BaseEventType;
UnsignedInteger eventAttributeId = Attributes.Value;
String indexRange = null;
SimpleAttributeOperand[] selectClauses = new SimpleAttributeOperand[eventFields.length + 1];
for (int i = 0; i < eventFields.length; i++) {
QualifiedName[] browsePath = createBrowsePath(eventFields[i]);
selectClauses[i] = new SimpleAttributeOperand(eventTypeId, browsePath, eventAttributeId, indexRange);
}
// Add a field to get the NodeId of the event source
selectClauses[eventFields.length] = new SimpleAttributeOperand(eventTypeId, null, Attributes.NodeId, null);
EventFilter filter = new EventFilter();
// Event field selection
filter.setSelectClauses(selectClauses);

// Event filtering: the following sample creates a
// "Not OfType GeneralModelChangeEventType" filter
ContentFilterBuilder fb = new ContentFilterBuilder();

fb.add(FilterOperator.Not, new ElementOperand(UnsignedInteger.valueOf(1)));
final LiteralOperand filteredType = new LiteralOperand(new Variant(Identifiers.GeneralModelChangeEventType));
fb.add(FilterOperator.OfType, filteredType);

filter.setWhereClause(fb.getContentFilter());
return filter;
}

protected QualifiedName[] createBrowsePath(QualifiedName qualifiedName) {
if (!qualifiedName.getName().contains("/")) {
return new QualifiedName[] { qualifiedName };
}
int namespaceIndex = qualifiedName.getNamespaceIndex();
String[] names = qualifiedName.getName().split("/");
QualifiedName[] result = new QualifiedName[names.length];
for (int i = 0; i < names.length; i++) {
result[i] = new QualifiedName(namespaceIndex, names[i]);
}
return result;
}
————————————————————————————————————–

MonitoredEventClass
————————————————————————————————————————
@Component
public class OpcUAEventListner implements MonitoredEventItemListener {

@Autowired
private AlarmService service;

public static List newAlarmList;
static {
System.out.println(“IntializedcList everytime we start the app”);
newAlarmList = new CopyOnWriteArrayList();
}

@Override
public void onEvent(MonitoredEventItem event, Variant[] arg1) {
System.out.println(“————–Alarm Received from Server——————-“);
System.out.println(“Monitored EventItem”+event.getEventFilter().toString()+event.getQueueSize()+event.getSamplingInterval()+event.getFilterResult()+event.getDefaultEventFields());

for (Variant var : arg1) {

var.getValue();
System.out.println(var + “Value”);

}

—————————————————————————————————————————–

Adding Listner to MoniteredEventItem
————————————————————————-
public void readData() throws UnknownHostException, ServiceException, StatusException, URISyntaxException,
SecureIdentityException, IOException, ServiceFaultException, ServiceResultException {
connectionutil = new OPCConnectionUtil();
UaClient client = connectionutil.getUaConnection();
Subscription sub = connectionutil.createSubscription();
client.addSubscription(sub);
NodeId nodeid = getNodeIdforServer(Constants.ALARMFOLDER, client);
EventFilter filter = createEventFilter(eventFieldNames);
MonitoredEventItem eventItem = new MonitoredEventItem(nodeid, filter);

eventItem.setEventListener(new OpcUAEventListner());
sub.addItem(eventItem);
System.out.println(eventItem.getNodeId());

}

————————————————————————————————————
This is my code.
Please review and let me know

Thanks

June 29, 2018
12:48, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 983
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

Hi,

As that looks mostly the same as in the samples, it should be correct. However in practice this is what the client sends to the server and then the rest is upto to the server to send correct amount of data.

I would next need to know the raw notification that the server sends. If that is incorrect there is in practice nothing the SDK can do as the server is then not working as it should based on the OPC UA Specification.

You can add a SubscriptionNotificationListener to the Subscription, and log the complete notification on SubscriptionNotificationListener.onNotificationData (note that by itself can contain multiple ones as list of events, each of them have a separate variant array, we are interested in single array at a time here as each should be of correct length).

Alternatively the best way to know for certain is to analyze if from the network traffic with https://www.wireshark.org/. http://documentation.unified-a…..eWireshark

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 518

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

fred: 41

Member Stats:

Guest Posters: 0

Members: 681

Moderators: 16

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1467

Posts: 6261

Newest Members:

graciela2073, sagarchau, elviralangwell4, Donnavek, Eddiefauth, DonaldPooma, fidelduke938316, Jan-Pfizer, DavidROunc, fen.pang@woodside.com

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