本文整理汇总了C#中Opc.Ua.Client.MonitoredItem类的典型用法代码示例。如果您正苦于以下问题:C# MonitoredItem类的具体用法?C# MonitoredItem怎么用?C# MonitoredItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MonitoredItem类属于Opc.Ua.Client命名空间,在下文中一共展示了MonitoredItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShowDialog
/// <summary>
/// Prompts the user to specify the browse options.
/// </summary>
public bool ShowDialog(Session session, MonitoredItem monitoredItem)
{
if (monitoredItem == null) throw new ArgumentNullException("monitoredItem");
DataChangeFilter filter = monitoredItem.Filter as DataChangeFilter;
if (filter == null)
{
filter = new DataChangeFilter();
filter.Trigger = DataChangeTrigger.StatusValue;
filter.DeadbandValue = 0;
filter.DeadbandType = (uint)(int)DeadbandType.None;
}
TriggerCB.SelectedItem = filter.Trigger;
DeadbandTypeCB.SelectedItem = (DeadbandType)(int)filter.DeadbandType;
DeadbandNC.Value = (decimal)filter.DeadbandValue;
if (ShowDialog() != DialogResult.OK)
{
return false;
}
filter.Trigger = (DataChangeTrigger)TriggerCB.SelectedItem;
filter.DeadbandType = Convert.ToUInt32(DeadbandTypeCB.SelectedItem);
filter.DeadbandValue = (double)DeadbandNC.Value;
monitoredItem.Filter = filter;
return true;
}
示例2: CreateMonitoredItem
/// <summary>
/// Creates the monitored item based on the current definition.
/// </summary>
/// <param name="session">The session.</param>
/// <returns>The monitored item.</returns>
public MonitoredItem CreateMonitoredItem(Session session)
{
// choose the server object by default.
if (AreaId == null)
{
AreaId = ObjectIds.Server;
}
// create the item with the filter.
MonitoredItem monitoredItem = new MonitoredItem();
monitoredItem.DisplayName = null;
monitoredItem.StartNodeId = AreaId;
monitoredItem.RelativePath = null;
monitoredItem.NodeClass = NodeClass.Object;
monitoredItem.AttributeId = Attributes.EventNotifier;
monitoredItem.IndexRange = null;
monitoredItem.Encoding = null;
monitoredItem.MonitoringMode = MonitoringMode.Reporting;
monitoredItem.SamplingInterval = 0;
monitoredItem.QueueSize = UInt32.MaxValue;
monitoredItem.DiscardOldest = true;
monitoredItem.Filter = ConstructFilter(session);
// save the definition as the handle.
monitoredItem.Handle = this;
return monitoredItem;
}
示例3: Show
/// <summary>
/// Displays the dialog.
/// </summary>
public void Show(MonitoredItem monitoredItem)
{
if (monitoredItem == null) throw new ArgumentNullException("monitoredItem");
Show();
BringToFront();
// remove previous subscription.
if (m_monitoredItem != null)
{
monitoredItem.Subscription.StateChanged -= m_SubscriptionStateChanged;
monitoredItem.Subscription.PublishStatusChanged -= m_PublishStatusChanged;
monitoredItem.Notification -= m_MonitoredItemNotification;
}
// start receiving notifications from the new subscription.
m_monitoredItem = monitoredItem;
m_subscription = null;
if (m_monitoredItem != null)
{
m_subscription = monitoredItem.Subscription;
m_monitoredItem.Subscription.StateChanged += m_SubscriptionStateChanged;
m_monitoredItem.Subscription.PublishStatusChanged += m_PublishStatusChanged;
m_monitoredItem.Notification += m_MonitoredItemNotification;
}
WindowMI_Click(WindowStatusMI, null);
WindowMI_Click(WindowLatestValueMI, null);
MonitoredItemsCTRL.Initialize(m_monitoredItem);
EventsCTRL.Initialize(m_subscription, m_monitoredItem);
DataChangesCTRL.Initialize(m_subscription, m_monitoredItem);
LatestValueCTRL.ShowValue(m_monitoredItem, false);
}
示例4: ShowDialog
/// <summary>
/// Displays the dialog.
/// </summary>
public object ShowDialog(object value, MonitoredItem monitoredItem)
{
m_value = Utils.Clone(value);
ValueCTRL.MonitoredItem = monitoredItem;
ValueCTRL.ShowValue(m_value);
if (ShowDialog() != DialogResult.OK)
{
return null;
}
return m_value;
}
示例5: MonitoredItem
/// <summary>
/// Initializes a new instance of the <see cref="MonitoredItem"/> class.
/// </summary>
/// <param name="template">The template used to specify the monitoring parameters.</param>
/// <param name="copyEventHandlers">if set to <c>true</c> the event handlers are copied.</param>
public MonitoredItem(MonitoredItem template, bool copyEventHandlers)
{
Initialize();
if (template != null)
{
string displayName = template.DisplayName;
if (displayName != null)
{
// remove any existing numeric suffix.
int index = displayName.LastIndexOf(' ');
if (index != -1)
{
try
{
displayName = displayName.Substring(0, index);
}
catch
{
// not a numeric suffix.
}
}
}
m_handle = template.m_handle;
m_displayName = Utils.Format("{0} {1}", displayName, m_clientHandle);
m_startNodeId = template.m_startNodeId;
m_relativePath = template.m_relativePath;
m_attributeId = template.m_attributeId;
m_indexRange = template.m_indexRange;
m_encoding = template.m_encoding;
m_monitoringMode = template.m_monitoringMode;
m_samplingInterval = template.m_samplingInterval;
m_filter = (MonitoringFilter)Utils.Clone(template.m_filter);
m_queueSize = template.m_queueSize;
m_discardOldest = template.m_discardOldest;
m_attributesModified = true;
if (copyEventHandlers)
{
m_Notification = template.m_Notification;
}
// this ensures the state is consistent with the node class.
NodeClass = template.m_nodeClass;
}
}
示例6: 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();
}
示例7: MonitoredItem_Notification
private void MonitoredItem_Notification(MonitoredItem monitoredItem, MonitoredItemNotificationEventArgs e)
{
try
{
if (e.NotificationValue == null || monitoredItem.Subscription.Session == null)
{
return;
}
JsonEncoder encoder = new JsonEncoder(
monitoredItem.Subscription.Session.MessageContext, false);
encoder.WriteNodeId("MonitoredItem", monitoredItem.ResolvedNodeId);
e.NotificationValue.Encode(encoder);
var json = encoder.Close();
var bytes = new UTF8Encoding(false).GetBytes(json);
foreach (var publisher in m_publishers)
{
try
{
publisher.Publish(new ArraySegment<byte>(bytes));
}
catch(Exception ex)
{
Utils.Trace(ex, "Failed to publish message, dropping....");
}
}
}
catch (Exception exception)
{
Utils.Trace(exception, "Error processing monitored item notification.");
}
}
示例8: ShowDialog
/// <summary>
/// Prompts the user to specify the browse options.
/// </summary>
public bool ShowDialog(Session session, MonitoredItem monitoredItem)
{
return ShowDialog(session, monitoredItem, false);
}
示例9: ShowDialog
/// <summary>
/// Prompts the user to edit the monitored item.
/// </summary>
public bool ShowDialog(Session session, MonitoredItem monitoredItem, bool isEvent)
{
if (!monitoredItem.Created)
{
NodeBTN.Session = session;
NodeBTN.SelectedNode = monitoredItem.StartNodeId;
}
// hide fields not used for events.
NodeLB.Visible = !monitoredItem.Created;
NodeTB.Visible = !monitoredItem.Created;
NodeBTN.Visible = !monitoredItem.Created;
AttributeLB.Visible = !isEvent && !monitoredItem.Created;
AttributeCB.Visible = !isEvent && !monitoredItem.Created;
IndexRangeLB.Visible = !isEvent && !monitoredItem.Created;
IndexRangeTB.Visible = !isEvent && !monitoredItem.Created;
DataEncodingLB.Visible = !isEvent && !monitoredItem.Created;
DataEncodingCB.Visible = !isEvent && !monitoredItem.Created;
MonitoringModeLB.Visible = !monitoredItem.Created;
MonitoringModeCB.Visible = !monitoredItem.Created;
SamplingIntervalLB.Visible = true;
SamplingIntervalUP.Visible = true;
QueueSizeLB.Visible = !isEvent;
QueueSizeUP.Visible = !isEvent;
DiscardOldestLB.Visible = true;
DiscardOldestCK.Visible = true;
DeadbandTypeLB.Visible = !isEvent;
DeadbandTypeCB.Visible = !isEvent;
DeadbandValueLB.Visible = !isEvent;
DeadbandValueUP.Visible = !isEvent;
TriggerTypeLB.Visible = !isEvent;
TriggerTypeCB.Visible = !isEvent;
// fill in values.
SamplingIntervalUP.Value = monitoredItem.SamplingInterval;
DiscardOldestCK.Checked = monitoredItem.DiscardOldest;
if (!isEvent)
{
AttributeCB.SelectedIndex = (int)(monitoredItem.AttributeId - 1);
IndexRangeTB.Text = monitoredItem.IndexRange;
MonitoringModeCB.SelectedItem = monitoredItem.MonitoringMode;
QueueSizeUP.Value = monitoredItem.QueueSize;
DataChangeFilter filter = monitoredItem.Filter as DataChangeFilter;
if (filter != null)
{
DeadbandTypeCB.SelectedItem = (DeadbandType)filter.DeadbandType;
DeadbandValueUP.Value = (decimal)filter.DeadbandValue;
TriggerTypeCB.SelectedItem = filter.Trigger;
}
if (!monitoredItem.Created)
{
// fetch the available encodings for the first node in the list from the server.
IVariableBase variable = session.NodeCache.Find(monitoredItem.StartNodeId) as IVariableBase;
DataEncodingCB.Items.Add(new EncodingInfo());
DataEncodingCB.SelectedIndex = 0;
if (variable != null)
{
if (session.NodeCache.IsTypeOf(variable.DataType, Opc.Ua.DataTypeIds.Structure))
{
foreach (INode encoding in session.NodeCache.Find(variable.DataType, Opc.Ua.ReferenceTypeIds.HasEncoding, false, true))
{
DataEncodingCB.Items.Add(new EncodingInfo() { EncodingName = encoding.BrowseName });
if (monitoredItem.Encoding == encoding.BrowseName)
{
DataEncodingCB.SelectedIndex = DataEncodingCB.Items.Count - 1;
}
}
}
}
}
}
else
{
AttributeCB.SelectedIndex = ((int)Attributes.EventNotifier - 1);
}
if (base.ShowDialog() != DialogResult.OK)
{
return false;
}
// update monitored item.
if (!monitoredItem.Created)
{
monitoredItem.StartNodeId = NodeBTN.SelectedNode;
monitoredItem.DisplayName = session.NodeCache.GetDisplayText(monitoredItem.StartNodeId);
monitoredItem.RelativePath = null;
monitoredItem.AttributeId = (uint)(AttributeCB.SelectedIndex + 1);
monitoredItem.MonitoringMode = (MonitoringMode)MonitoringModeCB.SelectedItem;
}
//.........这里部分代码省略.........
示例10: DoReconnectTest
/// <summary>
/// Tests the session reconnect.
/// </summary>
private bool DoReconnectTest()
{
double increment = MaxProgress/6;
double position = 0;
bool success = true;
lock (m_messages)
{
m_messages.Clear();
}
int currentKeepAlive = Session.KeepAliveInterval;
List<Subscription> subscriptions = new List<Subscription>();
KeepAliveEventHandler keepAliveHandler = new KeepAliveEventHandler(Session_Reconnect);
NotificationEventHandler notificationHandler = new NotificationEventHandler(Session_Notification);
try
{
Session.KeepAlive += keepAliveHandler;
Session.Notification += notificationHandler;
for (int publishingInterval = 1000; publishingInterval <= 10000; publishingInterval += 1000)
{
Subscription subscription = new Subscription();
subscription.MaxMessageCount = 100;
subscription.LifetimeCount = 100;
subscription.KeepAliveCount = 10;
subscription.PublishingEnabled = true;
subscription.PublishingInterval = publishingInterval;
MonitoredItem monitoredItem = new MonitoredItem();
monitoredItem.StartNodeId = VariableIds.Server_ServerStatus_CurrentTime;
monitoredItem.AttributeId = Attributes.Value;
monitoredItem.SamplingInterval = -1;
monitoredItem.QueueSize = 0;
monitoredItem.DiscardOldest = true;
subscription.AddItem(monitoredItem);
Session.AddSubscription(subscription);
subscription.Create();
subscriptions.Add(subscription);
}
m_keepAliveCount = 0;
Session.KeepAliveInterval = 1000;
Log("Setting keep alive interval to {0}ms.", Session.KeepAliveInterval);
int testDuration = 3000;
for (int ii = 0; ii < 6; ii++)
{
Session.Reconnect();
Log("Session reconnected. KeepAlives={0}", m_keepAliveCount);
if (m_errorEvent.WaitOne(testDuration, false))
{
Log("Unexpected error waiting for session keep alives. {0}", m_error.ToLongString());
return false;
}
position += increment;
ReportProgress(position);
}
}
finally
{
Session.RemoveSubscriptions(subscriptions);
Session.KeepAliveInterval = currentKeepAlive;
Session.KeepAlive -= keepAliveHandler;
Session.Notification -= notificationHandler;
}
ReportProgress(MaxProgress);
lock (m_messages)
{
foreach (KeyValuePair<uint,List<uint>> entry in m_messages)
{
entry.Value.Sort();
for (int ii = 0; ii < entry.Value.Count-1; ii++)
{
if (entry.Value[ii+1] - entry.Value[ii] > 1)
{
Log("Missing message. Subscription={0}, SequenceNumber={1}-{2}", entry.Key, entry.Value[ii]+1, entry.Value[ii+1]-1);
}
if (entry.Value[ii+1] == entry.Value[ii])
{
// Log("Duplicate message. Subscription={0}, SequenceNumber={1}", entry.Key, entry.Value[ii]);
}
}
}
//.........这里部分代码省略.........
示例11: AddSessions
/// <summary>
///
/// </summary>
private void AddSessions()
{
Browser browser = new Browser(m_Session);
browser.MaxReferencesReturned = 0;
browser.BrowseDirection = BrowseDirection.Forward;
browser.IncludeSubtypes = true;
browser.NodeClassMask = (int)NodeClass.Object;
browser.ContinueUntilDone = true;
NodeId browseid = new NodeId(Objects.Server_ServerDiagnostics_SessionsDiagnosticsSummary);
browser.ReferenceTypeId = null;
ReferenceDescriptionCollection refs = browser.Browse(browseid);
foreach(ReferenceDescription rf in refs)
{
if(m_Session.TypeTree.IsTypeOf(new ExpandedNodeId(rf.TypeDefinition), new ExpandedNodeId(ObjectTypes.SessionDiagnosticsObjectType)))
{
if(listView1.Items.IndexOfKey(rf.NodeId.ToString()) == -1)
{
ListViewItem lvi = listView1.Items.Add(rf.NodeId.ToString(), rf.DisplayName.Text.ToString(), -1);
lvi.Tag = rf.NodeId;
lvi.IndentCount = 0;
string SessionID = "SessionDiagnostics.SessionId";
string ClientName = "SessionDiagnostics.ClientName";
string ClientConnectionTime = "SessionDiagnostics.ClientConnectionTime";
ListViewItem.ListViewSubItem SessionIDSubItem = lvi.SubItems.Add("");
SessionIDSubItem.Name = rf.NodeId.Identifier.ToString() + "." + SessionID;
ListViewItem.ListViewSubItem ClientNameSubItem = lvi.SubItems.Add("");
ClientNameSubItem.Name = rf.NodeId.Identifier.ToString() + "." + ClientName;
ListViewItem.ListViewSubItem ClientConnectionTimeSubItem = lvi.SubItems.Add("");
ClientConnectionTimeSubItem.Name = rf.NodeId.Identifier.ToString() + "." + ClientConnectionTime;
MonitoredItem sessionItem = new MonitoredItem(m_Subscription.DefaultItem);
sessionItem.StartNodeId = (NodeId)rf.NodeId;
sessionItem.RelativePath = SessionID;
sessionItem.NodeClass = NodeClass.Object;
sessionItem.AttributeId = Attributes.Value;
m_Subscription.AddItem(sessionItem);
sessionItem.Notification += m_ItemNotification;
INode node = m_Session.NodeCache.Find(rf.NodeId);
TypedMonitoredItem SessionIDItem = new TypedMonitoredItem(m_Subscription.DefaultItem);
SessionIDItem.StartNodeId = (NodeId)rf.NodeId;
SessionIDItem.RelativePath = SessionID;
SessionIDItem.NodeClass = NodeClass.Variable;
SessionIDItem.AttributeId = Attributes.Value;
m_Subscription.AddItem(SessionIDItem);
SessionIDItem.Notification += m_ItemNotification;
SessionIDSubItem.Tag = SessionIDItem;
Utils.Trace("Adding: {0}, {1} as subitem in AddSessions()", SessionIDItem.StartNodeId.ToString(), SessionIDItem.RelativePath.ToString());
TypedMonitoredItem ClientNameItem = new TypedMonitoredItem(m_Subscription.DefaultItem);
ClientNameItem.StartNodeId = (NodeId)rf.NodeId;
ClientNameItem.RelativePath = ClientName;
ClientNameItem.NodeClass = NodeClass.Variable;
ClientNameItem.AttributeId = Attributes.Value;
m_Subscription.AddItem(ClientNameItem);
ClientNameItem.Notification += m_ItemNotification;
ClientNameSubItem.Tag = ClientNameItem;
Utils.Trace("Adding: {0}, {1} as subitem in AddSessions()", ClientNameItem.StartNodeId.ToString(), ClientNameItem.RelativePath.ToString());
DateTimeMonitoredItem ClientConnectionTimeItem = new DateTimeMonitoredItem(m_Subscription.DefaultItem);
ClientConnectionTimeItem.StartNodeId = (NodeId)rf.NodeId;
ClientConnectionTimeItem.RelativePath = ClientConnectionTime;
ClientConnectionTimeItem.NodeClass = NodeClass.Variable;
ClientConnectionTimeItem.AttributeId = Attributes.Value;
m_Subscription.AddItem(ClientConnectionTimeItem);
ClientConnectionTimeItem.Notification += m_ItemNotification;
ClientConnectionTimeSubItem.Tag = ClientConnectionTimeItem;
Utils.Trace("Adding: {0}, {1} as subitem in AddSessions()", ClientConnectionTimeItem.StartNodeId.ToString(), ClientConnectionTimeItem.RelativePath.ToString());
}
else
{
Utils.Trace("Key already exists in listview. rf.BrowseName: {0},rf.NodeId: {1}, rf.TypeDefinition: {2}", rf.BrowseName.ToString(), rf.NodeId.ToString(), rf.TypeDefinition.ToString());
}
}
else
{
Utils.Trace("Unknown Object rf.BrowseName: {0},rf.NodeId: {1}, rf.TypeDefinition: {2}", rf.BrowseName.ToString(), rf.NodeId.ToString(), rf.TypeDefinition.ToString());
}
}
}
示例12: CreateMonitoredItem
/// <summary>
/// Creates a new monitored item and adds it to the subscription.
/// </summary>
private MonitoredItem CreateMonitoredItem(NodeId notifierId)
{
MonitoredItem monitoredItem = new MonitoredItem();
monitoredItem.DisplayName = null;
monitoredItem.StartNodeId = notifierId;
monitoredItem.RelativePath = null;
monitoredItem.NodeClass = NodeClass.Object;
monitoredItem.AttributeId = Attributes.EventNotifier;
monitoredItem.IndexRange = null;
monitoredItem.Encoding = null;
monitoredItem.MonitoringMode = MonitoringMode.Reporting;
monitoredItem.SamplingInterval = 0;
monitoredItem.QueueSize = UInt32.MaxValue;
monitoredItem.DiscardOldest = true;
return monitoredItem;
}
示例13: Server_ReconnectComplete
/// <summary>
/// Updates the application after reconnecting to the server.
/// </summary>
private void Server_ReconnectComplete(object sender, EventArgs e)
{
try
{
m_session = ConnectServerCTRL.Session;
foreach (Subscription subscription in m_session.Subscriptions)
{
m_subscription = subscription;
break;
}
foreach (MonitoredItem monitoredItem in m_subscription.MonitoredItems)
{
m_monitoredItem = monitoredItem;
break;
}
}
catch (Exception exception)
{
ClientUtils.HandleException(this.Text, exception);
}
}
示例14: MonitoredItem_Notification
void MonitoredItem_Notification(MonitoredItem monitoredItem, MonitoredItemNotificationEventArgs e)
{
if (InvokeRequired)
{
BeginInvoke(new MonitoredItemNotificationEventHandler(MonitoredItem_Notification), monitoredItem, e);
return;
}
try
{
MonitoredItemNotification datachange = e.NotificationValue as MonitoredItemNotification;
if (datachange == null)
{
return;
}
CurrentStateTB.Text = datachange.Value.WrappedValue.ToString();
}
catch (Exception exception)
{
ClientUtils.HandleException(this.Text, exception);
}
}
示例15: 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);
}
}