本文整理汇总了C#中Opc.Ua.Client.Session.Write方法的典型用法代码示例。如果您正苦于以下问题:C# Session.Write方法的具体用法?C# Session.Write怎么用?C# Session.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Opc.Ua.Client.Session
的用法示例。
在下文中一共展示了Session.Write方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteValue
/// <summary>
/// Writes the value
/// </summary>
private Variant WriteValue(Session session, NodeId nodeId)
{
// cast the value to a string.
object value = TypeInfo.Cast(ValueTB.Text, TypeInfo.Scalars.String, m_sourceType.BuiltInType);
// build list of attributes to read.
WriteValueCollection nodesToWrite = new WriteValueCollection();
WriteValue nodeToWrite = new WriteValue();
nodeToWrite.NodeId = nodeId;
nodeToWrite.AttributeId = Attributes.Value;
// using the WrappedValue instead of the Value property because we know the TypeInfo.
// this makes the assignment more efficient by avoiding reflection to determine type.
nodeToWrite.Value.WrappedValue = new Variant(value, m_sourceType);
nodesToWrite.Add(nodeToWrite);
// override the diagnostic masks (other parameters are set to defaults).
RequestHeader requestHeader = new RequestHeader();
requestHeader.ReturnDiagnostics = (uint)DiagnosticsMasks.All;
// read the attributes.
StatusCodeCollection results = null;
DiagnosticInfoCollection diagnosticInfos = null;
ResponseHeader responseHeader = session.Write(
requestHeader,
nodesToWrite,
out results,
out diagnosticInfos);
ClientBase.ValidateResponse(results, nodesToWrite);
ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToWrite);
// check status.
if (StatusCode.IsBad(results[0]))
{
// embed the diagnostic information in a exception.
throw ServiceResultException.Create(results[0], 0, diagnosticInfos, responseHeader.StringTable);
}
// return valid value.
return nodeToWrite.Value.WrappedValue;
}