Exemple #1
0
        /// <summary>
        /// Reads the attribute values from the server.
        /// </summary>
        /// <param name="valuesToRead">The values to read.</param>
        /// <returns>
        /// The values read.
        /// </returns>
        public DaValue[] Read(ReadValueIdCollection valuesToRead)
        {
            TraceState("Read", valuesToRead.Count);

            // check for valid session.
            Session session = m_session;

            if (session == null)
            {
                throw ComUtils.CreateComException(ResultIds.E_FAIL);
            }

            int masterError = ResultIds.E_FAIL;

            DaValue[] results = new DaValue[valuesToRead.Count];

            if (session != null)
            {
                try
                {
                    // read the values.
                    DataValueCollection      values          = null;
                    DiagnosticInfoCollection diagnosticInfos = null;

                    session.Read(
                        null,
                        0,
                        TimestampsToReturn.Both,
                        valuesToRead,
                        out values,
                        out diagnosticInfos);

                    ClientBase.ValidateResponse(values, valuesToRead);
                    ClientBase.ValidateDiagnosticInfos(diagnosticInfos, valuesToRead);

                    // convert the response.
                    for (int ii = 0; ii < values.Count; ii++)
                    {
                        results[ii] = m_mapper.GetLocalDataValue(values[ii]);
                    }

                    // return the results.
                    return(results);
                }
                catch (Exception e)
                {
                    masterError = ComUtils.GetErrorCode(e, ResultIds.E_FAIL);
                }
            }

            // report any unexpected errors.
            for (int ii = 0; ii < results.Length; ii++)
            {
                DaValue result = results[ii] = new DaValue();
                result.Error = masterError;
            }

            return(results);
        }
Exemple #2
0
        /// <summary>
        /// Reads the attribute values from the server.
        /// </summary>
        /// <param name="valuesToWrite">The values to write.</param>
        /// <returns>The results.</returns>
        public int[] Write(WriteValueCollection valuesToWrite)
        {
            TraceState("Write", valuesToWrite.Count);

            // check for valid session.
            Session session = m_session;

            if (session == null)
            {
                throw ComUtils.CreateComException(ResultIds.E_FAIL);
            }

            int masterError = ResultIds.E_FAIL;

            int[] errors = new int[valuesToWrite.Count];

            if (session != null)
            {
                try
                {
                    // write the values.
                    StatusCodeCollection     results         = null;
                    DiagnosticInfoCollection diagnosticInfos = null;

                    session.Write(
                        null,
                        valuesToWrite,
                        out results,
                        out diagnosticInfos);

                    ClientBase.ValidateResponse(results, valuesToWrite);
                    ClientBase.ValidateDiagnosticInfos(diagnosticInfos, valuesToWrite);

                    // convert the response.
                    for (int ii = 0; ii < results.Count; ii++)
                    {
                        errors[ii] = ComDaProxy.MapWriteStatusToErrorCode(valuesToWrite[ii].Value, results[ii]);
                    }

                    // return the results.
                    return(errors);
                }
                catch (Exception e)
                {
                    masterError = ComUtils.GetErrorCode(e, ResultIds.E_FAIL);
                }
            }

            // report any unexpected errors.
            for (int ii = 0; ii < errors.Length; ii++)
            {
                errors[ii] = masterError;
            }

            return(errors);
        }
Exemple #3
0
        /// <summary>
        /// Writes the values for the specified item ids.
        /// </summary>
        /// <param name="itemIds">The item ids.</param>
        /// <param name="values">The values.</param>
        /// <returns>The results.</returns>
        public int[] Write(string[] itemIds, DaValue[] values)
        {
            int[] results = new int[itemIds.Length];
            WriteValueCollection valuesToWrite = new WriteValueCollection();

            ComDaReadPropertiesRequest[] requests = new ComDaReadPropertiesRequest[values.Length];

            // prepare request.
            for (int ii = 0; ii < itemIds.Length; ii++)
            {
                ComDaReadPropertiesRequest request = requests[ii] = new ComDaReadPropertiesRequest();
                request.ItemId = itemIds[ii];
            }

            // need to get the data type of the remote node.
            m_browseManager.GetPropertyValues(Session, requests, PropertyIds.UaBuiltInType, PropertyIds.UaValueRank);

            // validate items.
            for (int ii = 0; ii < requests.Length; ii++)
            {
                ComDaReadPropertiesRequest request = requests[ii];

                if (request.Error < 0)
                {
                    results[ii] = request.Error;
                    continue;
                }

                int?builtInType = request.Values[0].Value as int?;
                int?valueRank   = request.Values[1].Value as int?;

                if (builtInType == null || valueRank == null)
                {
                    results[ii] = ResultIds.E_UNKNOWNITEMID;
                    continue;
                }

                // convert value to UA data type.
                WriteValue valueToWrite = new WriteValue();

                valueToWrite.NodeId      = m_mapper.GetRemoteNodeId(itemIds[ii]);
                valueToWrite.AttributeId = Attributes.Value;
                valueToWrite.Handle      = ii;

                // convert value to UA data type.
                try
                {
                    TypeInfo remoteType = new TypeInfo((BuiltInType)builtInType.Value, valueRank.Value);
                    valueToWrite.Value = m_mapper.GetRemoteDataValue(values[ii], remoteType);
                }
                catch (Exception e)
                {
                    results[ii] = ComUtils.GetErrorCode(e, ResultIds.E_BADTYPE);
                    continue;
                }

                valuesToWrite.Add(valueToWrite);
            }

            // check if nothing to do.
            if (valuesToWrite.Count == 0)
            {
                return(results);
            }

            // write the values to the server.
            int[] remoteResults = m_groupManager.Write(valuesToWrite);

            // copy results.
            for (int ii = 0; ii < valuesToWrite.Count; ii++)
            {
                results[(int)valuesToWrite[ii].Handle] = remoteResults[ii];
            }

            return(results);
        }