当前位置: 首页>>代码示例>>C#>>正文


C# Session.Write方法代码示例

本文整理汇总了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;
        }
开发者ID:yuriik83,项目名称:UA-.NET,代码行数:48,代码来源:WriteValueDlg.cs


注:本文中的Opc.Ua.Client.Session.Write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。