GenericEvent.Set method doesn't work

Questions regarding the use of the .NET SDK 2.0 for Server or Client development or integration into customer products ...

Moderator: uasdknet

Post Reply
alberto.piovan
Jr. Member
Jr. Member
Posts: 4
Joined: 16 Mar 2017, 15:47

GenericEvent.Set method doesn't work

Post by alberto.piovan »

Hello,

I'm running .NET SDK 2.5.3, UADemoServer, and I'm trying to understand how to set the specific fields of an event. In the DemoServer the procedure is the following one:

Code: Select all

 
GenericEvent e = new GenericEvent(Server.FilterManager);
sourceId = new NodeId(Demo.Model.Variables.Demo_Events_Trigger_SampleEvent, DefaultNamespaceIndex);
                e.Initialize(
                    null,
                    new NodeId(1005, DefaultNamespaceIndex),
                    sourceId,
                    "SampleEventNotifier",
                    EventSeverity.Medium,
                    new LocalizedText("A sample event event."));

                e.Set("2:Boolean", m_generator.GetRandom<bool>(false));
                e.Set("2:SByte", m_generator.GetRandom<sbyte>(false));
                e.Set("2:Byte", m_generator.GetRandom<byte>(false));
                e.Set("2:Int16", m_generator.GetRandom<short>(false));
                e.Set("2:UInt16", m_generator.GetRandom<ushort>(false));
                e.Set("2:Int32", m_generator.GetRandom<int>(false));
                e.Set("2:UInt32", m_generator.GetRandom<uint>(false));
                e.Set("2:Int64", m_generator.GetRandom<long>(false));
                e.Set("2:UInt64", m_generator.GetRandom<ulong>(false));
                e.Set("2:Float", m_generator.GetRandom<float>(false));
                e.Set("2:Double", m_generator.GetRandom<double>(false));
                e.Set("2:String", m_generator.GetRandom<string>(false));
                e.Set("2:ByteString", m_generator.GetRandom<byte[]>(false));
                e.Set("2:DateTime", m_generator.GetRandom<DateTime>(false));
                e.Set("2:Guid", m_generator.GetRandom<Uuid>(false));
                e.Set("2:NodeId", m_generator.GetRandom<NodeId>(false));
                e.Set("2:ExpandedNodeId", m_generator.GetRandom<ExpandedNodeId>(false));
                e.Set("2:QualifiedName", m_generator.GetRandom<QualifiedName>(false));
                e.Set("2:LocalizedText", m_generator.GetRandom<LocalizedText>(false));
                e.Set("2:ServiceResult", m_generator.GetRandom<StatusCode>(false));
                e.Set("2:XmlElement", m_generator.GetRandom<XmlElement>(false));
I have subscribed to the object that generates the events with UaExpert but when I look at the details of the event no one of the fields set with the GenericEvent.Set method is in the list, there are only the generic fields (EventID, EventType, SourceNode, SourceName, Severity, Message).
I also tried to do:

Code: Select all

var test = e.Get("2:Boolean");
immediately after the Set instruction and it returned me a null.

User avatar
Support Team
Hero Member
Hero Member
Posts: 2519
Joined: 18 Mar 2011, 15:09

Re: GenericEvent.Set method doesn't work

Post by Support Team »

Hello,

UaExpert by default subscribes only a common subset of the event fields. You have to specify the event fields you want to receive. Please see http://documentation.unified-automation ... event.html. Do not forget to click at the 'Apply' button.

There is an optimization in .NET SDK. An event field is only set, if it is subscribed. So the method Get will return a value != null if the event field is subscribed by a client.
Best regards
Unified Automation Support Team

Leo88
Jr. Member
Jr. Member
Posts: 1
Joined: 20 Mar 2020, 13:59

Re: GenericEvent.Set method doesn't work

Post by Leo88 »

Hello,

I have a problem with the SET method from GenericEvent.
The event works, is also displayed on the UaExpert.
However, the veriable "RfidScanResult", what is given to the event with e.set, does not come with ?!
At e.get comes back null.

Thank you in advanced.

attached the code

Code: Select all

        public void sendEvent()
        {
            // create the event.
            GenericEvent e = new GenericEvent(newNodeManager.autoidNodeManager.Server.FilterManager);

            e.Initialize(   null, // EventId created by SDK if null
                            new NodeId(opcfoundation.org.UA_AutoID.ObjectTypes.RfidScanEventType, newNodeManager.autoidNodeManager.NamespaceIndex),// EventType
                            nodeMain.NodeId,    
                            getName(), // SourceName
                            EventSeverity.High, // Severity
                            "ScanResult Event :-)"); // Message

            opcfoundation.org.UA_AutoID.RfidScanResult rfidScanResult = new opcfoundation.org.UA_AutoID.RfidScanResult();
            rfidScanResult.CodeType = "CODE_TYPE";
            rfidScanResult.Location = new opcfoundation.org.UA_AutoID.Location();
            rfidScanResult.Timestamp = DateTime.Now;
            opcfoundation.org.UA_AutoID.ScanData scanData = new opcfoundation.org.UA_AutoID.ScanData();
            scanData.String = "Die gelesenen Daten :-)";
            rfidScanResult.ScanData = scanData;

            rfidScanResult.Location.NMEA = "NMEA_";
            rfidScanResult.Location.Name = "NAME_";
            rfidScanResult.Location.WGS84 = new opcfoundation.org.UA_AutoID.WGS84Coordinate();
            rfidScanResult.Location.WGS84.Altitude = 52.10;
            rfidScanResult.Location.WGS84.Latitude = 9.10;

            UnifiedAutomation.UaBase.QualifiedName qualifiedName = new UnifiedAutomation.UaBase.QualifiedName(opcfoundation.org.UA_AutoID.BrowseNames.RfidScanResult, newNodeManager.autoidNodeManager.NamespaceIndex);
            String strPath = e.ToPath(qualifiedName);
            e.Set(strPath, new Variant(rfidScanResult));
            Variant var = e.Get(strPath);

            newNodeManager.autoidNodeManager.ReportEvent(e.SourceNode, e);
              
        }

Post Reply