Login  •  Register


How to use SetTriggering

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

How to use SetTriggering

Postby aldomhubert » 20 Dec 2019, 01:11

Hello,
I am trying to get the SetTriggering method working with the .NET client SDK (3.0.8). I have modified the FullClient.Net40 solution so the addMonitoredItem method in C:\Program Files\UaSdkNetBundleEval\src\examples\FullClient\MonitoredItemsControl.cs

Looks like the code below (see below) and I modified the browserControl_SelectionChanged in C:\Program Files\UaSdkNetBundleEval\src\examples\FullClient\MainForm.cs looks like the code below.

As you can see, when I select a node from the UI for the first time, it creates a subscription with one monitored item. Then the next time I select a node, the code attempts to add that node as a trigger. I’ve tried all sorts of things (pass an empty list for items to remove, null and a few others), but get the same result.

The nodes I’m using to test with are all in the demo static scalar section – e.g.: nodeId = {ns=2;s=Demo.Static.Scalar.Double}

I’ve tried a bunch of things, but I keep getting BadMonitoredItemIdInvalid.

What am I doing wrong?

Thanks in advance,
Aldo

private void browserControl_SelectionChanged(TreeNode node)
{
// Read all the attributes of the selected tree node.
attributeListControl.ReadAttributes(node);

ReferenceDescription refDescr = (ReferenceDescription)node.Tag;

var bubba = node.Text;

//NodeId subNode = new NodeId(refDescr.NodeId.NamespaceIndex, refDescr.NodeId.Identifier);
NodeId subNode = new NodeId(refDescr.NodeId.Identifier.ToString(), refDescr.NodeId.NamespaceIndex);

monitoredItemsControl.addMonitoredItem(subNode);

}



public void addMonitoredItem(NodeId nodeId)
{
try
{
// Create the subscription if it does not already exist.
if (m_Subscription == null)
{
m_Subscription = new Subscription(m_Session);
m_Subscription.PublishingEnabled = m_PublishingEnabled;
m_Subscription.PublishingInterval = m_PublishingInterval;
m_Subscription.DataChanged += new DataChangedEventHandler(Subscription_DataChanged);
m_Subscription.StatusChanged += new SubscriptionStatusChangedEventHandler(Subscription_StatusChanged);
m_Subscription.Create();
}

// Add the attribute name/value to the list view.
ListViewItem item = new ListViewItem(nodeId.ToString());

// Prepare further columns.
item.SubItems.Add("250"); // Sampling interval by default.
item.SubItems.Add(String.Empty);
item.SubItems.Add(String.Empty);
item.SubItems.Add(String.Empty);
item.SubItems.Add(String.Empty);
item.SubItems.Add(String.Empty);

List<MonitoredItem> monitoredItems = new List<MonitoredItem>();
List<StatusCode> results = new List<StatusCode>();

monitoredItems.Add(new DataMonitoredItem(nodeId)
{
DiscardOldest = true,
QueueSize = 1,
SamplingInterval = 250,
UserData = item,
});

try
{
var currentmis = m_Subscription.MonitoredItems;

if(currentmis.Length > 0)
{
RequestSettings settings = new RequestSettings();
DataMonitoredItem dmi = new DataMonitoredItem(nodeId);
dmi.MonitoringMode = MonitoringMode.Reporting;
dmi.SamplingInterval = 100;
//dmi.UserData

List<MonitoredItem> nomonitoredItems = new List<MonitoredItem>();
var ret = m_Subscription.SetTriggering(dmi, currentmis, null, settings);
}
else
{
// Add the item and apply any changes to it.
results = m_Subscription.CreateMonitoredItems(monitoredItems);

//RequestSettings settings = new RequestSettings();
//DataMonitoredItem dmi = new DataMonitoredItem(nodeId);
//dmi.MonitoringMode = MonitoringMode.Reporting;
//dmi.SamplingInterval = 100;
////dmi.UserData

//List<MonitoredItem> nomonitoredItems = new List<MonitoredItem>();
//nomonitoredItems.Add(dmi);
//var ret = m_Subscription.SetTriggering(dmi, nomonitoredItems, currentmis, settings);


}




// Update status label.
OnUpdateStatusLabel("Adding monitored item succeeded for NodeId:" +
nodeId.ToString(), true);
}
catch (Exception exception)
{
item.SubItems[5].Text = results[0].ToString();

// Update status label.
OnUpdateStatusLabel("An exception occured while adding an item: " +
exception.Message, false);
}

item.Tag = monitoredItems[0];

MonitoredItemsLV.Items.Add(item);

// Fit column width to the longest item and add a few pixel:
MonitoredItemsLV.Columns[0].Width = -1;
MonitoredItemsLV.Columns[0].Width += 15;
// Fit column width to the column content:
MonitoredItemsLV.Columns[1].Width = -2;
MonitoredItemsLV.Columns[5].Width = -2;
// Fix settings:
MonitoredItemsLV.Columns[2].Width = 95;
MonitoredItemsLV.Columns[3].Width = 75;
MonitoredItemsLV.Columns[4].Width = 75;
}
catch (Exception exception)
{
// Update status label.
OnUpdateStatusLabel("An exception occured while creating a subscription: " +
exception.Message, false);
}
}
aldomhubert
Jr. Member
Jr. Member
 
Posts: 1
Joined: 17 Dec 2019, 22:19

Re: How to use SetTriggering

Postby Support Team » 13 Jan 2020, 13:13

Hello,

There is one trigger item and a list of triggered items. The standard use case is that the MonitoringMode of the trigger item is Reporting and the MonitoringMode of each triggered item is Sampling. Once the value of the trigger item changes, the whole queue of DataChanges of the triggered items get reported.

Here is some sample code that is copied from an internal test code.

Code: Select all
            NodeId int16Id = UnifiedAutomation.Demo.Model.VariableIds.Demo_Static_Scalar_Int16
                .ToNodeId(Session.NamespaceUris);
            NodeId int32Id = UnifiedAutomation.Demo.Model.VariableIds.Demo_Static_Scalar_Int32
                .ToNodeId(Session.NamespaceUris);

            List<MonitoredItem> monitoredItems = new List<MonitoredItem>();

            MonitoredItem triggerItem = new DataMonitoredItem(int16Id);
            MonitoredItem linkedItem = new DataMonitoredItem(int32Id)
            {
                MonitoringMode = MonitoringMode.Sampling,
                QueueSize = 10,
                SamplingInterval = 0
            };
            monitoredItems.Add(triggerItem);
            monitoredItems.Add(linkedItem);

            subscription.CreateMonitoredItems(monitoredItems);

            List<MonitoredItem> triggeredItems = new List<MonitoredItem>();
            triggeredItems.Add(linkedItem);
            SetTriggeringResult result = subscription.SetTriggering(triggerItem, triggeredItems, null, null);
Best regards
Unified Automation Support Team
User avatar
Support Team
Hero Member
Hero Member
 
Posts: 2439
Joined: 18 Mar 2011, 15:09


Return to .NET based OPC UA SDK

Who is online

Users browsing this forum: No registered users and 0 guests