本文整理汇总了C#中Opc.Ua.Client.Session.AddSubscription方法的典型用法代码示例。如果您正苦于以下问题:C# Session.AddSubscription方法的具体用法?C# Session.AddSubscription怎么用?C# Session.AddSubscription使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Opc.Ua.Client.Session
的用法示例。
在下文中一共展示了Session.AddSubscription方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: New
/// <summary>
/// Creates a new subscription.
/// </summary>
public Subscription New(Session session)
{
if (session == null) throw new ArgumentNullException("session");
Subscription subscription = new Subscription(session.DefaultSubscription);
if (!new SubscriptionEditDlg().ShowDialog(subscription))
{
return null;
}
session.AddSubscription(subscription);
subscription.Create();
Subscription duplicateSubscription = session.Subscriptions.FirstOrDefault(s => s.Id != 0 && s.Id.Equals(subscription.Id) && s != subscription);
if (duplicateSubscription != null)
{
Utils.Trace("Duplicate subscription was created with the id: {0}", duplicateSubscription.Id);
DialogResult result = MessageBox.Show("Duplicate subscription was created with the id: " + duplicateSubscription.Id + ". Do you want to keep it?", "Warning", MessageBoxButtons.YesNo);
if (result == System.Windows.Forms.DialogResult.No)
{
duplicateSubscription.Delete(false);
session.RemoveSubscription(subscription);
return null;
}
}
Show(subscription);
return subscription;
}
示例2: Initialize
/// <summary>
///
/// </summary>
/// <param name="Items"></param>
public void Initialize(Session session)
{
Subscription subscription = new Subscription(session.DefaultSubscription);
subscription.DisplayName = session.ToString() + ".AllSessions";
bool bResult = session.AddSubscription(subscription);
subscription.Create();
Initialize(session, subscription);
}
示例3: New
/// <summary>
/// Creates a new subscription.
/// </summary>
public async Task<Subscription> New(Session session)
{
if (session == null) throw new ArgumentNullException("session");
Subscription subscription = new Subscription(session.DefaultSubscription);
SubscriptionEditDlg subscriptionEditDlg = new SubscriptionEditDlg();
if (!await subscriptionEditDlg.ShowDialog(subscription))
{
return null;
}
session.AddSubscription(subscription);
subscription.Create();
Show(subscription);
return subscription;
}
示例4: CreateMonitoredItem
public void CreateMonitoredItem(
Session session, Subscription subscription, NodeId nodeId, MonitoringMode mode)
{
if (subscription == null)
{
subscription = session.DefaultSubscription;
if (session.AddSubscription(subscription))
subscription.Create();
}
else
{
session.AddSubscription(subscription);
}
// add the new monitored item.
MonitoredItem monitoredItem = new MonitoredItem(subscription.DefaultItem);
monitoredItem.StartNodeId = nodeId;
monitoredItem.AttributeId = Attributes.Value;
monitoredItem.DisplayName = nodeId.Identifier.ToString();
monitoredItem.MonitoringMode = mode;
monitoredItem.SamplingInterval = mode == MonitoringMode.Sampling ? 1000 : 0;
monitoredItem.QueueSize = 0;
monitoredItem.DiscardOldest = true;
monitoredItem.Notification += MonitoredItem_Notification;
subscription.AddItem(monitoredItem);
subscription.ApplyChanges();
}
示例5: Server_ConnectComplete
/// <summary>
/// Updates the application after connecting to or disconnecting from the server.
/// </summary>
private void Server_ConnectComplete(object sender, EventArgs e)
{
try
{
m_session = ConnectServerCTRL.Session;
if (m_session == null)
{
StartBTN.Enabled = false;
return;
}
// set a suitable initial state.
if (m_session != null && !m_connectedOnce)
{
m_connectedOnce = true;
}
// this client has built-in knowledge of the information model used by the server.
NamespaceTable wellKnownNamespaceUris = new NamespaceTable();
wellKnownNamespaceUris.Append(Namespaces.Methods);
string[] browsePaths = new string[]
{
"1:My Process/1:State",
"1:My Process",
"1:My Process/1:Start"
};
List<NodeId> nodes = ClientUtils.TranslateBrowsePaths(
m_session,
ObjectIds.ObjectsFolder,
wellKnownNamespaceUris,
browsePaths);
// subscribe to the state if available.
if (nodes.Count > 0 && !NodeId.IsNull(nodes[0]))
{
m_subscription = new Subscription();
m_subscription.PublishingEnabled = true;
m_subscription.PublishingInterval = 1000;
m_subscription.Priority = 1;
m_subscription.KeepAliveCount = 10;
m_subscription.LifetimeCount = 20;
m_subscription.MaxNotificationsPerPublish = 1000;
m_session.AddSubscription(m_subscription);
m_subscription.Create();
MonitoredItem monitoredItem = new MonitoredItem();
monitoredItem.StartNodeId = nodes[0];
monitoredItem.AttributeId = Attributes.Value;
monitoredItem.Notification += new MonitoredItemNotificationEventHandler(MonitoredItem_Notification);
m_subscription.AddItem(monitoredItem);
m_subscription.ApplyChanges();
}
// save the object/method
if (nodes.Count > 2)
{
m_objectNode = nodes[1];
m_methodNode = nodes[2];
}
InitialStateTB.Text = "1";
FinalStateTB.Text = "100";
StartBTN.Enabled = true;
}
catch (Exception exception)
{
ClientUtils.HandleException(this.Text, exception);
}
}
示例6: Server_ConnectComplete
/// <summary>
/// Updates the application after connecting to or disconnecting from the server.
/// </summary>
private void Server_ConnectComplete(object sender, EventArgs e)
{
try
{
m_session = ConnectServerCTRL.Session;
// check for disconnect.
if (m_session == null)
{
if (m_auditEventForm != null)
{
m_auditEventForm.Close();
m_auditEventForm = null;
}
return;
}
// set a suitable initial state.
if (m_session != null && !m_connectedOnce)
{
m_connectedOnce = true;
}
// create the default subscription.
m_subscription = new Subscription();
m_subscription.DisplayName = null;
m_subscription.PublishingInterval = 1000;
m_subscription.KeepAliveCount = 10;
m_subscription.LifetimeCount = 100;
m_subscription.MaxNotificationsPerPublish = 1000;
m_subscription.PublishingEnabled = true;
m_subscription.TimestampsToReturn = TimestampsToReturn.Both;
m_session.AddSubscription(m_subscription);
m_subscription.Create();
// must specify the fields that the form is interested in.
m_filter.SelectClauses = m_filter.ConstructSelectClauses(
m_session,
NodeId.Parse("ns=2;s=4:2"),
NodeId.Parse("ns=2;s=4:1"),
ObjectTypeIds.DialogConditionType,
ObjectTypeIds.ExclusiveLimitAlarmType,
ObjectTypeIds.NonExclusiveLimitAlarmType);
// create a monitored item based on the current filter settings.
m_monitoredItem = m_filter.CreateMonitoredItem(m_session);
// set up callback for notifications.
m_monitoredItem.Notification += m_MonitoredItem_Notification;
m_subscription.AddItem(m_monitoredItem);
m_subscription.ApplyChanges();
// send an initial refresh.
Conditions_RefreshMI_Click(sender, e);
ConditionsMI.Enabled = true;
ViewMI.Enabled = true;
}
catch (Exception exception)
{
ClientUtils.HandleException(this.Text, exception);
}
}
示例7: Server_ConnectMI_Click
/// <summary>
/// Connects to a server.
/// </summary>
private void Server_ConnectMI_Click(object sender, EventArgs e)
{
try
{
// disconnect any existing session.
Server_DisconnectMI_Click(sender, e);
InitialStateTB.Text = "1";
FinalStateTB.Text = "100";
// create the session.
EndpointDescription endpointDescription = SelectEndpoint();
EndpointConfiguration endpointConfiguration = EndpointConfiguration.Create(m_configuration);
ConfiguredEndpoint endpoint = new ConfiguredEndpoint(null, endpointDescription, endpointConfiguration);
m_session = Session.Create(
m_configuration,
endpoint,
true,
m_configuration.ApplicationName,
60000,
null,
null);
// set up keep alive callback.
m_session.KeepAliveInterval = 2000;
m_session.KeepAlive += new KeepAliveEventHandler(Session_KeepAlive);
// this client has built-in knowledge of the information model used by the server.
NamespaceTable wellKnownNamespaceUris = new NamespaceTable();
wellKnownNamespaceUris.Append(Namespaces.Methods);
string[] browsePaths = new string[]
{
"1:My Process/1:State",
"1:My Process",
"1:My Process/1:Start"
};
List<NodeId> nodes = FormUtils.TranslateBrowsePaths(
m_session,
ObjectIds.ObjectsFolder,
wellKnownNamespaceUris,
browsePaths);
// subscribe to the state if available.
if (nodes.Count > 0 && !NodeId.IsNull(nodes[0]))
{
m_subscription = new Subscription();
m_subscription.PublishingEnabled = true;
m_subscription.PublishingInterval = 1000;
m_subscription.Priority = 1;
m_subscription.KeepAliveCount = 10;
m_subscription.LifetimeCount = 20;
m_subscription.MaxNotificationsPerPublish = 1000;
m_session.AddSubscription(m_subscription);
m_subscription.Create();
MonitoredItem monitoredItem = new MonitoredItem();
monitoredItem.StartNodeId = nodes[0];
monitoredItem.AttributeId = Attributes.Value;
monitoredItem.Notification += new MonitoredItemNotificationEventHandler(MonitoredItem_Notification);
m_subscription.AddItem(monitoredItem);
m_subscription.ApplyChanges();
}
// save the object/method
if (nodes.Count > 2)
{
m_objectNode = nodes[1];
m_methodNode = nodes[2];
}
ConnectedLB.Text = "Connected";
ServerUrlLB.Text = endpointDescription.EndpointUrl;
LastKeepAliveTimeLB.Text = "---";
}
catch (Exception exception)
{
MessageBox.Show(exception.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
示例8: OnSessionCreated
/// <summary>
/// Called when a session is created with a server.
/// </summary>
private void OnSessionCreated(Session session)
{
string commonAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
string configFileName = Utils.Format(@"{0}\OPC Foundation\ComPseudoServers\{1}.internal.xml", commonAppDataPath, m_clsid);
lock (m_lock)
{
try
{
m_session = null;
m_Subscription = null;
m_AreaNodes.Clear();
m_session = session;
// load the config file.
if (File.Exists(configFileName))
{
XmlSerializer ser = new XmlSerializer(typeof(Configuration));
TextReader reader = new StreamReader(configFileName);
m_configFile = (Configuration)ser.Deserialize(reader);
reader.Close();
// set the ActualDataType property
for (int ii = 0; ii < m_configFile.Attributes.Length - 1; ii++)
{
NodeId nodeid = new NodeId(m_configFile.Attributes[ii].strDataTypeNodeId);
m_configFile.Attributes[ii].ActualDataType = DataTypes.GetSystemType(nodeid, EncodeableFactory.GlobalFactory);
}
}
else
{
InitConfigInfo(configFileName);
}
// Obtain the current server table, generate index mapping tables (client->server, server->client)
// and update the client side namespace table if necessary due to server changes
GenerateNamespaceIndexMappings(m_clsid);
// The client side namespace table may have been updated if the server namespace table
// has changed therefore save the updated client table.
SaveConfigInfo(configFileName);
// fetch type tree.
m_session.FetchTypeTree(Opc.Ua.ObjectTypeIds.BaseEventType);
m_session.FetchTypeTree(Opc.Ua.ReferenceTypeIds.References);
//Create UA Event Subscription if none configured in the registry
m_Subscription = new Opc.Ua.Client.Subscription(m_session.DefaultSubscription);
m_Subscription.PublishingEnabled = true;
m_Subscription.PublishingInterval = m_configFile.ProxySubscriptionSettings.PublishingInterval;
m_Subscription.KeepAliveCount = m_configFile.ProxySubscriptionSettings.KeepAliveCount;
m_Subscription.LifetimeCount = m_configFile.ProxySubscriptionSettings.LifetimeCount;
m_Subscription.Priority = m_configFile.ProxySubscriptionSettings.Priority;
m_Subscription.MaxNotificationsPerPublish = m_configFile.ProxySubscriptionSettings.MaxNotificationsPerPublish;
m_session.AddSubscription(m_Subscription);
m_Subscription.Create();
m_KeepAliveInterval = (int)(m_Subscription.CurrentPublishingInterval * m_Subscription.CurrentKeepAliveCount);
// Add Server object as the only monitored item to this subscription
NodeId nodeId_Server = new NodeId(Opc.Ua.Objects.Server);
MonitoredItem monitoredItem = CreateMonitoredItemForEvents(nodeId_Server);
m_Subscription.AddItem(monitoredItem);
m_Subscription.ApplyChanges();
AreaNode areaNode = new AreaNode();
areaNode.AreaName = "/";
++areaNode.RefCount;
areaNode.MonitoredItem = monitoredItem;
m_notifiers.Add(monitoredItem.ClientHandle, areaNode);
m_AreaNodes.Add("/", areaNode);
m_Subscription.Session.Call(
Opc.Ua.ObjectTypes.ConditionType,
Methods.ConditionType_ConditionRefresh,
m_Subscription.Id);
}
catch (Exception e)
{
Utils.Trace(e, "Initializing server after create.");
throw ComUtils.CreateComException(e);
}
}
}
示例9: Start
/// <summary>
/// Starts the specified session.
/// </summary>
/// <param name="session">The session.</param>
public void Start(Session session)
{
m_NotificationEventHandler = new NotificationEventHandler(Session_Notification);
session.Notification += m_NotificationEventHandler;
Subscription subscription = m_subscription = new Subscription();
subscription.PublishingInterval = m_samplingRate;
subscription.KeepAliveCount = 10;
subscription.LifetimeCount = 100;
subscription.MaxNotificationsPerPublish = 50000;
subscription.PublishingEnabled = false;
subscription.TimestampsToReturn = TimestampsToReturn.Neither;
subscription.Priority = 1;
subscription.DisableMonitoredItemCache = true;
session.AddSubscription(subscription);
subscription.Create();
DateTime start = HiResClock.UtcNow;
for (int ii = 0; ii < m_itemCount; ii++)
{
MonitoredItem monitoredItem = new MonitoredItem((uint)ii);
monitoredItem.StartNodeId = new NodeId((uint)((1<<24) + ii), 2);
monitoredItem.AttributeId = Attributes.Value;
monitoredItem.SamplingInterval = -1;
monitoredItem.Filter = null;
monitoredItem.QueueSize = 0;
monitoredItem.DiscardOldest = true;
monitoredItem.MonitoringMode = MonitoringMode.Reporting;
subscription.AddItem(monitoredItem);
}
subscription.ApplyChanges();
DateTime end = HiResClock.UtcNow;
ReportMessage("Time to add {1} items {0}ms.", (end - start).TotalMilliseconds, m_itemCount);
start = HiResClock.UtcNow;
subscription.SetPublishingMode(true);
end = HiResClock.UtcNow;
ReportMessage("Time to emable publishing {0}ms.", (end - start).TotalMilliseconds);
}
示例10: LoadItems
public void LoadItems(Session session, List<DiagnosticListViewItem> items)
{
Subscription subscription = new Subscription(session.DefaultSubscription);
bool bResult = session.AddSubscription(subscription);
subscription.DisplayName = session.ToString();
subscription.Create();
LoadItems(session, items, subscription);
}