本文整理汇总了C#中Opc.Ua.Client.Session.Browse方法的典型用法代码示例。如果您正苦于以下问题:C# Session.Browse方法的具体用法?C# Session.Browse怎么用?C# Session.Browse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Opc.Ua.Client.Session
的用法示例。
在下文中一共展示了Session.Browse方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Browse
public static ReferenceDescriptionCollection Browse(Session session, BrowseDescription nodeToBrowse, bool throwOnError)
{
try
{
var descriptionCollection = new ReferenceDescriptionCollection();
var nodesToBrowse = new BrowseDescriptionCollection { nodeToBrowse };
BrowseResultCollection results;
DiagnosticInfoCollection diagnosticInfos;
session.Browse(null, null, 0U, nodesToBrowse, out results, out diagnosticInfos);
ClientBase.ValidateResponse(results, nodesToBrowse);
ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToBrowse);
while (!StatusCode.IsBad(results[0].StatusCode))
{
for (var index = 0; index < results[0].References.Count; ++index)
descriptionCollection.Add(results[0].References[index]);
if (results[0].References.Count == 0 || results[0].ContinuationPoint == null)
return descriptionCollection;
var continuationPoints = new ByteStringCollection();
continuationPoints.Add(results[0].ContinuationPoint);
session.BrowseNext(null, false, continuationPoints, out results, out diagnosticInfos);
ClientBase.ValidateResponse(results, continuationPoints);
ClientBase.ValidateDiagnosticInfos(diagnosticInfos, continuationPoints);
}
throw new ServiceResultException(results[0].StatusCode);
}
catch (Exception ex)
{
if (throwOnError)
throw new ServiceResultException(ex, 2147549184U);
return null;
}
}
示例2: HistoryReadProcessed
static void HistoryReadProcessed(Session session)
{
// translate browse paths.
IList<NodeOfInterest> nodeIds = GetNodeIds(session, Opc.Ua.Objects.ObjectsFolder,
VariableBrowsePaths.ToArray());
DiagnosticInfoCollection diagnosticInfos;
NodeId aggregateNodeId = null;
RequestHeader rh = null;
ViewDescription vd = null;
ReferenceDescriptionCollection references;
byte[] cp;
//Get the list of avalilable aggregate functions:
session.Browse(
rh,
vd,
Opc.Ua.ObjectIds.Server_ServerCapabilities_AggregateFunctions,
1000,
BrowseDirection.Forward,
ReferenceTypeIds.Aggregates,
false,
0,
out cp,
out references);
Console.WriteLine("{0} aggregates are detected:", references.Count);
//Print the list of avalible aggregates:
int i = 0;
foreach (ReferenceDescription rd in references)
{
i++;
Console.WriteLine("{0}. {1} {2}", i, rd.BrowseName, rd.NodeId.Identifier.ToString());
}
//Select aggregate function:
Console.WriteLine("\nEnter aggregate number: ");
string str = Console.ReadLine();
i = System.Int16.Parse(str);
if (i > 0 && i <= references.Count)
{
aggregateNodeId = ExpandedNodeId.ToNodeId(references[i - 1].NodeId, session.NamespaceUris);
}
//Prepare arguments to pass to read processed history
ReadProcessedDetails readDetails = new ReadProcessedDetails();
readDetails.StartTime = new DateTime(2008, 1, 1, 12, 0, 0);
readDetails.EndTime = new DateTime(2008, 1, 1, 12, 0, 12);
readDetails.AggregateType = new NodeIdCollection(nodeIds.Count);
for (int x = 0; x < nodeIds.Count; x++)
{
readDetails.AggregateType.Add (aggregateNodeId);
}
readDetails.ProcessingInterval = 500; //500 milliseconds
ExtensionObject eo = new ExtensionObject(readDetails.TypeId, readDetails);
HistoryReadValueIdCollection idCollection = new HistoryReadValueIdCollection();
for (int ii = 0; ii < nodeIds.Count; ii++)
{
HistoryReadValueId readValueId = new HistoryReadValueId();
readValueId.NodeId = nodeIds[ii].NodeId;
readValueId.Processed = true;
idCollection.Add(readValueId);
}
HistoryReadResultCollection historyReadResults;
//Read processed history:
ResponseHeader responseHeader =
session.HistoryRead(null, eo, TimestampsToReturn.Both, true,
idCollection, out historyReadResults, out diagnosticInfos);
//Print results:
for (int ii = 0; ii < historyReadResults.Count; ii++)
{
HistoryReadResult historyReadResult = historyReadResults[ii];
ServiceResult result = Session.GetResult(historyReadResult.StatusCode, ii, diagnosticInfos, responseHeader);
HistoryData historyData = null;
DataValueCollection dataValues = null;
if ( !(historyReadResult.HistoryData == null) )
{
historyData = ExtensionObject.ToEncodeable(historyReadResult.HistoryData) as HistoryData;
if (historyData == null)
dataValues = null;
else
dataValues = historyData.DataValues;
}
Console.WriteLine("\nHistoryRead result code for {0}: {1}", VariableBrowsePaths[ii], result.StatusCode.ToString());
//.........这里部分代码省略.........
示例3: Browse
static void Browse(Session session)
{
DiagnosticInfoCollection diagnosticInfos;
BrowseDescriptionCollection bc = new BrowseDescriptionCollection();
BrowseDescription bd = new BrowseDescription();
bd.BrowseDirection = BrowseDirection.Forward;
NodeId nodeId = Opc.Ua.Objects.ObjectsFolder;
do
{
Console.WriteLine("\n Enter nodeId to Browse (or q to exit)");
string s = Console.ReadLine();
if (s == "q")
break;
if (s.Length == 0)
{
nodeId = Opc.Ua.Objects.ObjectsFolder;
}
else
nodeId = new NodeId(s);
bc.Clear();
bd.NodeId = nodeId;
bc.Add(bd);
BrowseResultCollection results;
ResponseHeader rh =
session.Browse(null, null, 100, bc, out results, out diagnosticInfos);
foreach ( BrowseResult res in results)
{
foreach (ReferenceDescription rdc in res.References)
{
Console.WriteLine(String.Format(" Node = {0} (namespace {1}) {2}", rdc.NodeId.ToString(),rdc.NodeId.NamespaceIndex, Environment.NewLine));
}
}
} while (true);
}
示例4: Browse
/// <summary>
/// Browses the address space and returns the references found.
/// </summary>
public static ReferenceDescriptionCollection Browse(Session session, ViewDescription view, BrowseDescription nodeToBrowse, bool throwOnError)
{
try
{
ReferenceDescriptionCollection references = new ReferenceDescriptionCollection();
// construct browse request.
BrowseDescriptionCollection nodesToBrowse = new BrowseDescriptionCollection();
nodesToBrowse.Add(nodeToBrowse);
// start the browse operation.
BrowseResultCollection results = null;
DiagnosticInfoCollection diagnosticInfos = null;
session.Browse(
null,
view,
0,
nodesToBrowse,
out results,
out diagnosticInfos);
ClientBase.ValidateResponse(results, nodesToBrowse);
ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToBrowse);
do
{
// check for error.
if (StatusCode.IsBad(results[0].StatusCode))
{
throw new ServiceResultException(results[0].StatusCode);
}
// process results.
for (int ii = 0; ii < results[0].References.Count; ii++)
{
references.Add(results[0].References[ii]);
}
// check if all references have been fetched.
if (results[0].References.Count == 0 || results[0].ContinuationPoint == null)
{
break;
}
// continue browse operation.
ByteStringCollection continuationPoints = new ByteStringCollection();
continuationPoints.Add(results[0].ContinuationPoint);
session.BrowseNext(
null,
false,
continuationPoints,
out results,
out diagnosticInfos);
ClientBase.ValidateResponse(results, continuationPoints);
ClientBase.ValidateDiagnosticInfos(diagnosticInfos, continuationPoints);
}
while (true);
//return complete list.
return references;
}
catch (Exception exception)
{
if (throwOnError)
{
throw new ServiceResultException(exception, StatusCodes.BadUnexpectedError);
}
return null;
}
}
示例5: FindTargetOfReference
/// <summary>
/// Finds the targets for the specified reference.
/// </summary>
private static List<NodeId> FindTargetOfReference(Session session, List<NodeId> nodeIds, NodeId referenceTypeId, bool throwOnError)
{
try
{
// construct browse request.
BrowseDescriptionCollection nodesToBrowse = new BrowseDescriptionCollection();
for (int ii = 0; ii < nodeIds.Count; ii++)
{
BrowseDescription nodeToBrowse = new BrowseDescription();
nodeToBrowse.NodeId = nodeIds[ii];
nodeToBrowse.BrowseDirection = BrowseDirection.Forward;
nodeToBrowse.ReferenceTypeId = referenceTypeId;
nodeToBrowse.IncludeSubtypes = false;
nodeToBrowse.NodeClassMask = 0;
nodeToBrowse.ResultMask = (uint)BrowseResultMask.None;
nodesToBrowse.Add(nodeToBrowse);
}
// start the browse operation.
BrowseResultCollection results = null;
DiagnosticInfoCollection diagnosticInfos = null;
session.Browse(
null,
null,
1,
nodesToBrowse,
out results,
out diagnosticInfos);
ClientBase.ValidateResponse(results, nodesToBrowse);
ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToBrowse);
List<NodeId> targetIds = new List<NodeId>();
ByteStringCollection continuationPoints = new ByteStringCollection();
for (int ii = 0; ii < nodeIds.Count; ii++)
{
targetIds.Add(null);
// check for error.
if (StatusCode.IsBad(results[ii].StatusCode))
{
continue;
}
// check for continuation point.
if (results[ii].ContinuationPoint != null && results[ii].ContinuationPoint.Length > 0)
{
continuationPoints.Add(results[ii].ContinuationPoint);
}
// get the node id.
if (results[ii].References.Count > 0)
{
if (NodeId.IsNull(results[ii].References[0].NodeId) || results[ii].References[0].NodeId.IsAbsolute)
{
continue;
}
targetIds[ii] = (NodeId)results[ii].References[0].NodeId;
}
}
// release continuation points.
if (continuationPoints.Count > 0)
{
session.BrowseNext(
null,
true,
continuationPoints,
out results,
out diagnosticInfos);
ClientBase.ValidateResponse(results, nodesToBrowse);
ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToBrowse);
}
//return complete list.
return targetIds;
}
catch (Exception exception)
{
if (throwOnError)
{
throw new ServiceResultException(exception, StatusCodes.BadUnexpectedError);
}
return null;
}
}
示例6: Browse
/// <summary>
/// Fetches the references for the node.
/// </summary>
private List<ReferenceDescription> Browse(Session session, NodeId nodeId)
{
List<ReferenceDescription> references = new List<ReferenceDescription>();
// specify the references to follow and the fields to return.
BrowseDescription nodeToBrowse = new BrowseDescription();
nodeToBrowse.NodeId = nodeId;
nodeToBrowse.ReferenceTypeId = ReferenceTypeIds.References;
nodeToBrowse.IncludeSubtypes = true;
nodeToBrowse.BrowseDirection = BrowseDirection.Both;
nodeToBrowse.NodeClassMask = 0;
nodeToBrowse.ResultMask = (uint)BrowseResultMask.All;
BrowseDescriptionCollection nodesToBrowse = new BrowseDescriptionCollection();
nodesToBrowse.Add(nodeToBrowse);
// start the browse operation.
BrowseResultCollection results = null;
DiagnosticInfoCollection diagnosticInfos = null;
ResponseHeader responseHeader = session.Browse(
null,
null,
2,
nodesToBrowse,
out results,
out diagnosticInfos);
// these do sanity checks on the result - make sure response matched the request.
ClientBase.ValidateResponse(results, nodesToBrowse);
ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToBrowse);
// check status.
if (StatusCode.IsBad(results[0].StatusCode))
{
// embed the diagnostic information in a exception.
throw ServiceResultException.Create(results[0].StatusCode, 0, diagnosticInfos, responseHeader.StringTable);
}
// add first batch.
references.AddRange(results[0].References);
// check if server limited the results.
while (results[0].ContinuationPoint != null && results[0].ContinuationPoint.Length > 0)
{
ByteStringCollection continuationPoints = new ByteStringCollection();
continuationPoints.Add(results[0].ContinuationPoint);
// continue browse operation.
responseHeader = session.BrowseNext(
null,
false,
continuationPoints,
out results,
out diagnosticInfos);
ClientBase.ValidateResponse(results, continuationPoints);
ClientBase.ValidateDiagnosticInfos(diagnosticInfos, continuationPoints);
// check status.
if (StatusCode.IsBad(results[0].StatusCode))
{
// embed the diagnostic information in a exception.
throw ServiceResultException.Create(results[0].StatusCode, 0, diagnosticInfos, responseHeader.StringTable);
}
// add next batch.
references.AddRange(results[0].References);
}
return references;
}
示例7: BrowseBlock
/// <summary>
/// Sends the browse request to the server.
/// </summary>
/// <param name="session">The session.</param>
/// <param name="nodesToBrowse">The nodes to browse.</param>
/// <returns></returns>
private BrowseResultCollection BrowseBlock(Session session, BrowseDescriptionCollection nodesToBrowse)
{
try
{
// Utils.Trace("Browsing {0} Nodes", nodesToBrowse.Count);
ViewDescription view = new ViewDescription();
Dictionary<int,BrowseResult> combinedResults = new Dictionary<int, BrowseResult>();
// initialize the table of indexes used to correlate results.
BrowseDescriptionCollection browseOperations = nodesToBrowse;
List<int> browseIndexes = new List<int>();
for (int ii = 0; ii < nodesToBrowse.Count; ii++)
{
browseIndexes.Add(ii);
}
BrowseDescriptionCollection unprocessedOperations = new BrowseDescriptionCollection();
List<int> unprocessedBrowseIndexes = new List<int>();
while (browseOperations.Count > 0)
{
// start the browse operation.
BrowseResultCollection results = null;
DiagnosticInfoCollection diagnosticInfos = null;
session.Browse(
null,
view,
0,
browseOperations,
out results,
out diagnosticInfos);
ClientBase.ValidateResponse(results, browseOperations);
ClientBase.ValidateDiagnosticInfos(diagnosticInfos, browseOperations);
unprocessedOperations.Clear();
unprocessedBrowseIndexes.Clear();
ByteStringCollection continuationPoints = new ByteStringCollection();
List<int> continuationPointIndexes = new List<int>();
for (int ii = 0; ii < browseOperations.Count; ii++)
{
int index = browseIndexes[ii];
// Utils.Trace("{0}/{1}/{2}", browseOperations[ii].NodeId, browseOperations[ii].ReferenceTypeId, results[ii].References.Count);
// look up results.
BrowseResult combinedResult = null;
if (!combinedResults.TryGetValue(index, out combinedResult))
{
combinedResults[index] = combinedResult = new BrowseResult();
}
// check for error.
if (StatusCode.IsBad(results[ii].StatusCode))
{
// this error indicates that the server does not have enough simultaneously active
// continuation points. This request will need to be resent after the other operations
// have been completed and their continuation points released.
if (results[ii].StatusCode == StatusCodes.BadNoContinuationPoints)
{
unprocessedOperations.Add(browseOperations[ii]);
unprocessedBrowseIndexes.Add(index);
continue;
}
// save error.
if (StatusCode.IsGood(combinedResult.StatusCode))
{
combinedResult.StatusCode = results[ii].StatusCode;
}
continue;
}
// check if all references have been fetched.
if (results[ii].References.Count == 0)
{
continue;
}
// save results.
combinedResult.References.AddRange(results[ii].References);
// check for continuation point.
if (results[ii].ContinuationPoint != null && results[ii].ContinuationPoint.Length > 0)
{
continuationPoints.Add(results[ii].ContinuationPoint);
continuationPointIndexes.Add(index);
//.........这里部分代码省略.........