當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。