本文整理汇总了C#中Subscription.AddItems方法的典型用法代码示例。如果您正苦于以下问题:C# Subscription.AddItems方法的具体用法?C# Subscription.AddItems怎么用?C# Subscription.AddItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subscription
的用法示例。
在下文中一共展示了Subscription.AddItems方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConnectionAgent
private void ConnectionAgent()
{
while (!_connectionEnd.WaitOne(0) && !Connected)
try
{
URL url = new URL(_OpcSection.Server.Name);
_Server = new Opc.Da.Server(new OpcCom.Factory(), null);
_Server.Connect(url, new ConnectData(new NetworkCredential()));
_groupRead = (Subscription)_Server.CreateSubscription(_GroupReadState);
_groupWrite = (Subscription)_Server.CreateSubscription(_GroupWriteState);
for (int i = 0; i < _OpcSection.Server.TagGroup.GetElement(_TagGroup).Tags.Count; i++)
{
_Items[i] = new Opc.Da.Item();
//_Items[i].ItemName = String.Format("{0}{1}", _OpcSection.Server.Channel, _OpcSection.Server.TagGroup.GetElement(_TagGroup).Tags[i].Name);
_Items[i].ItemName = _OpcSection.Server.Channel + "." + _OpcSection.Server.Device + "." + _OpcSection.Server.TagGroup.GetElement(_TagGroup).Tags[i].Name;
//string itmNam = String.Format("{0}]{1}", _OpcSection.Server.Channel, _OpcSection.Server.TagGroup.GetElement(_TagGroup).Tags[i].Name);
_logger.LogInfo(/*Mtd*/ ": recognized element " + _Items[i].ItemName);
}
_Items = _groupRead.AddItems(_Items);
_groupRead.DataChanged += new DataChangedEventHandler(Group_DataChanged);
}
catch (Exception ex) { _logger.LogError(ex); }
}
示例2: ConsoleSampleClient
//.........这里部分代码省略.........
config.SecurityConfiguration.ApplicationCertificate.StorePath,
config.ApplicationUri,
config.ApplicationName
);
config.SecurityConfiguration.ApplicationCertificate.Certificate = certificate;
}
haveAppCertificate = config.SecurityConfiguration.ApplicationCertificate.Certificate != null;
if (haveAppCertificate)
{
config.ApplicationUri = Utils.GetApplicationUriFromCertificate(config.SecurityConfiguration.ApplicationCertificate.Certificate);
if (config.SecurityConfiguration.AutoAcceptUntrustedCertificates)
{
config.CertificateValidator.CertificateValidation += new CertificateValidationEventHandler(CertificateValidator_CertificateValidation);
}
}
else
{
Console.WriteLine(" WARN: missing application certificate, using unsecure connection.");
}
Console.WriteLine("2 - Discover endpoints of {0}.", endpointURL);
Uri endpointURI = new Uri(endpointURL);
var endpointCollection = DiscoverEndpoints(config, endpointURI, 10);
var selectedEndpoint = SelectUaTcpEndpoint(endpointCollection, haveAppCertificate);
Console.WriteLine(" Selected endpoint uses: {0}",
selectedEndpoint.SecurityPolicyUri.Substring(selectedEndpoint.SecurityPolicyUri.LastIndexOf('#') + 1));
Console.WriteLine("3 - Create a session with OPC UA server.");
var endpointConfiguration = EndpointConfiguration.Create(config);
var endpoint = new ConfiguredEndpoint(selectedEndpoint.Server, endpointConfiguration);
endpoint.Update(selectedEndpoint);
var session = await Session.Create(config, endpoint, true, ".Net Core OPC UA Console Client", 60000, null, null);
Console.WriteLine("4 - Browse the OPC UA server namespace.");
ReferenceDescriptionCollection references;
Byte[] continuationPoint;
references = session.FetchReferences(ObjectIds.ObjectsFolder);
session.Browse(
null,
null,
ObjectIds.ObjectsFolder,
0u,
BrowseDirection.Forward,
ReferenceTypeIds.HierarchicalReferences,
true,
(uint)NodeClass.Variable | (uint)NodeClass.Object | (uint)NodeClass.Method,
out continuationPoint,
out references);
Console.WriteLine(" DisplayName, BrowseName, NodeClass");
foreach (var rd in references)
{
Console.WriteLine(" {0}, {1}, {2}", rd.DisplayName, rd.BrowseName, rd.NodeClass);
ReferenceDescriptionCollection nextRefs;
byte[] nextCp;
session.Browse(
null,
null,
ExpandedNodeId.ToNodeId(rd.NodeId, session.NamespaceUris),
0u,
BrowseDirection.Forward,
ReferenceTypeIds.HierarchicalReferences,
true,
(uint)NodeClass.Variable | (uint)NodeClass.Object | (uint)NodeClass.Method,
out nextCp,
out nextRefs);
foreach (var nextRd in nextRefs)
{
Console.WriteLine(" + {0}, {1}, {2}", nextRd.DisplayName, nextRd.BrowseName, nextRd.NodeClass);
}
}
Console.WriteLine("5 - Create a subscription with publishing interval of 1 second.");
var subscription = new Subscription(session.DefaultSubscription) { PublishingInterval = 1000 };
Console.WriteLine("6 - Add a list of items (server current time and status) to the subscription.");
var list = new List<MonitoredItem> {
new MonitoredItem(subscription.DefaultItem)
{
DisplayName = "ServerStatusCurrentTime", StartNodeId = "i=2258"
}
};
list.ForEach(i => i.Notification += OnNotification);
subscription.AddItems(list);
Console.WriteLine("7 - Add the subscription to the session.");
session.AddSubscription(subscription);
subscription.Create();
Console.WriteLine("8 - Running...Press any key to exit...");
Console.ReadKey(true);
}