Example #1
0
        /// <summary>
        /// Returns the value of the specified field.
        /// </summary>
        private object GetFieldValue(OpcItemResult item, int fieldID)
        {
            switch (fieldID)
            {
            case ITEM_NAME:     { return(item.ItemName); }

            case ITEM_PATH:     { return(item.ItemPath); }

            // case CLIENT_HANDLE: { return OpcClientSdk.Utilities.Convert.ToString(item.ClientHandle); }
            // case SERVER_HANDLE: { return OpcClientSdk.Utilities.Convert.ToString(item.ServerHandle); }
            case ERROR:         { return(GetErrorText(item.Result)); }
            }

            return(null);
        }
Example #2
0
        /// <summary>
        /// Returns the value of the specified field.
        /// </summary>
        private object GetFieldValue(OpcItemResult item, int fieldId)
        {
            switch (fieldId)
            {
            case ItemName:     { return(item.ItemName); }

            case ItemPath:     { return(item.ItemPath); }

            // case CLIENT_HANDLE: { return Technosoftware.DaAeHdaClient.Utilities.Convert.ToString(item.ClientHandle); }
            // case SERVER_HANDLE: { return Technosoftware.DaAeHdaClient.Utilities.Convert.ToString(item.ServerHandle); }
            case Error:         { return(GetErrorText(item.Result)); }
            }

            return(null);
        }
Example #3
0
        /// <summary>
        /// Begins an asynchronous write for a set of items using DA2.0 interfaces.
        /// </summary>
        protected override OpcItemResult[] BeginWrite(
            OpcItem[] itemIDs,
            TsCDaItemValue[] items,
            int requestID,
            out int cancelID)
        {
            cancelID = 0;

            ArrayList validItems  = new ArrayList();
            ArrayList validValues = new ArrayList();

            // construct initial result list.
            OpcItemResult[] results = new OpcItemResult[itemIDs.Length];

            for (int ii = 0; ii < itemIDs.Length; ii++)
            {
                results[ii] = new OpcItemResult(itemIDs[ii]);

                results[ii].Result         = OpcResult.S_OK;
                results[ii].DiagnosticInfo = null;

                if (items[ii].QualitySpecified || items[ii].TimestampSpecified)
                {
                    results[ii].Result         = OpcResult.Da.E_NO_WRITEQT;
                    results[ii].DiagnosticInfo = null;
                    continue;
                }

                validItems.Add(results[ii]);
                validValues.Add(Utilities.Interop.GetVARIANT(items[ii].Value));
            }

            // check if any valid items exist.
            if (validItems.Count == 0)
            {
                return(results);
            }

            string methodName = "IOPCAsyncIO2.Write";

            try
            {
                // initialize input parameters.
                int[] serverHandles = new int[validItems.Count];

                for (int ii = 0; ii < validItems.Count; ii++)
                {
                    serverHandles[ii] = (int)((OpcItemResult)validItems[ii]).ServerHandle;
                }

                // write to sever.
                IntPtr pErrors = IntPtr.Zero;

                IOPCAsyncIO2 subscription = BeginComCall <IOPCAsyncIO2>(methodName, true);
                subscription.Write(
                    validItems.Count,
                    serverHandles,
                    (object[])validValues.ToArray(typeof(object)),
                    requestID,
                    out cancelID,
                    out pErrors);

                // unmarshal results.
                int[] errors = Utilities.Interop.GetInt32s(ref pErrors, validItems.Count, true);

                // create result list.
                for (int ii = 0; ii < validItems.Count; ii++)
                {
                    OpcItemResult result = (OpcItemResult)validItems[ii];

                    result.Result         = Utilities.Interop.GetResultId(errors[ii]);
                    result.DiagnosticInfo = null;

                    // convert COM code to unified DA code.
                    if (errors[ii] == Result.E_BADRIGHTS)
                    {
                        results[ii].Result = new OpcResult(OpcResult.Da.E_READONLY, Result.E_BADRIGHTS);
                    }
                }
            }
            catch (Exception e)
            {
                ComCallError(methodName, e);
                throw Utilities.Interop.CreateException(methodName, e);
            }
            finally
            {
                EndComCall(methodName);
            }

            // return results.
            return(results);
        }
Example #4
0
        /// <summary>
        /// Begins an asynchronous read of a set of items using DA2.0 interfaces.
        /// </summary>
        protected override OpcItemResult[] BeginRead(
            OpcItem[] itemIDs,
            TsCDaItem[] items,
            int requestID,
            out int cancelID)
        {
            string methodName = "IOPCAsyncIO2.Read";

            try
            {
                // marshal input parameters.
                int[] serverHandles = new int[itemIDs.Length];

                for (int ii = 0; ii < itemIDs.Length; ii++)
                {
                    serverHandles[ii] = (int)itemIDs[ii].ServerHandle;
                }

                // initialize output parameters.
                IntPtr pErrors = IntPtr.Zero;

                IOPCAsyncIO2 subscription = BeginComCall <IOPCAsyncIO2>(methodName, true);
                subscription.Read(
                    itemIDs.Length,
                    serverHandles,
                    requestID,
                    out cancelID,
                    out pErrors);

                // unmarshal output parameters.
                int[] errors = Utilities.Interop.GetInt32s(ref pErrors, itemIDs.Length, true);

                // create item results.
                OpcItemResult[] results = new OpcItemResult[itemIDs.Length];

                for (int ii = 0; ii < itemIDs.Length; ii++)
                {
                    results[ii]                = new OpcItemResult(itemIDs[ii]);
                    results[ii].Result         = Utilities.Interop.GetResultId(errors[ii]);
                    results[ii].DiagnosticInfo = null;

                    // convert COM code to unified DA code.
                    if (errors[ii] == Result.E_BADRIGHTS)
                    {
                        results[ii].Result = new OpcResult(OpcResult.Da.E_WRITEONLY, Result.E_BADRIGHTS);
                    }
                }

                // return results.
                return(results);
            }
            catch (Exception e)
            {
                ComCallError(methodName, e);
                throw Utilities.Interop.CreateException(methodName, e);
            }
            finally
            {
                EndComCall(methodName);
            }
        }
Example #5
0
        /// <summary>
        /// Writes a set of items using DA2.0 interfaces.
        /// </summary>
        protected override OpcItemResult[] Write(OpcItem[] itemIDs, TsCDaItemValue[] items)
        {
            // create result list.
            OpcItemResult[] results = new OpcItemResult[itemIDs.Length];

            // construct list of valid items to write.
            ArrayList writeItems  = new ArrayList(itemIDs.Length);
            ArrayList writeValues = new ArrayList(itemIDs.Length);

            for (int ii = 0; ii < items.Length; ii++)
            {
                results[ii] = new OpcItemResult(itemIDs[ii]);

                if (items[ii].QualitySpecified || items[ii].TimestampSpecified)
                {
                    results[ii].Result         = OpcResult.Da.E_NO_WRITEQT;
                    results[ii].DiagnosticInfo = null;
                    continue;
                }

                writeItems.Add(results[ii]);
                writeValues.Add(items[ii]);
            }

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

            // initialize input parameters.
            int[]    serverHandles = new int[writeItems.Count];
            object[] values        = new object[writeItems.Count];

            for (int ii = 0; ii < serverHandles.Length; ii++)
            {
                serverHandles[ii] = (int)((OpcItemResult)writeItems[ii]).ServerHandle;
                values[ii]        = Utilities.Interop.GetVARIANT(((TsCDaItemValue)writeValues[ii]).Value);
            }

            IntPtr pErrors = IntPtr.Zero;

            // write item values.
            string methodName = "IOPCSyncIO.Write";

            try
            {
                IOPCSyncIO subscription = BeginComCall <IOPCSyncIO>(methodName, true);
                subscription.Write(
                    writeItems.Count,
                    serverHandles,
                    values,
                    out pErrors);
            }
            catch (Exception e)
            {
                ComCallError(methodName, e);
                throw Utilities.Interop.CreateException(methodName, e);
            }
            finally
            {
                EndComCall(methodName);
            }

            // unmarshal results.
            int[] errors = Utilities.Interop.GetInt32s(ref pErrors, writeItems.Count, true);

            for (int ii = 0; ii < writeItems.Count; ii++)
            {
                OpcItemResult result = (OpcItemResult)writeItems[ii];

                result.Result         = Utilities.Interop.GetResultId(errors[ii]);
                result.DiagnosticInfo = null;

                // convert COM code to unified DA code.
                if (errors[ii] == Result.E_BADRIGHTS)
                {
                    results[ii].Result = new OpcResult(OpcResult.Da.E_READONLY, Result.E_BADRIGHTS);
                }
            }

            // return results.
            return(results);
        }
Example #6
0
        /// <summary>
        /// Writes the value, quality and timestamp for a set of items.
        /// </summary>
        /// <param name="items">The set of item values to write.</param>
        /// <returns>The results of the write operation for each item.</returns>
        public virtual OpcItemResult[] Write(TsCDaItemValue[] items)
        {
            if (items == null)
            {
                throw new ArgumentNullException(nameof(items));
            }

            lock (this)
            {
                if (m_server == null)
                {
                    throw new NotConnectedException();
                }
                string methodName = "IOPCItemIO.WriteVQT";

                int count = items.Length;
                if (count == 0)
                {
                    throw new ArgumentOutOfRangeException("items.Length", "0");
                }

                // initialize arguments.
                string[] itemIDs = new string[count];

                for (int ii = 0; ii < count; ii++)
                {
                    itemIDs[ii] = items[ii].ItemName;
                }

                OpcRcw.Da.OPCITEMVQT[] values = Technosoftware.DaAeHdaClient.Com.Da.Interop.GetOPCITEMVQTs(items);

                IntPtr pErrors = IntPtr.Zero;

                // invoke COM method.
                try
                {
                    IOPCItemIO server = BeginComCall <IOPCItemIO>(methodName, true);
                    server.WriteVQT(
                        count,
                        itemIDs,
                        values,
                        out pErrors);
                }
                catch (Exception e)
                {
                    ComCallError(methodName, e);
                    throw Technosoftware.DaAeHdaClient.Com.Interop.CreateException(methodName, e);
                }
                finally
                {
                    EndComCall(methodName);
                }

                // unmarshal results.
                int[] errors = Technosoftware.DaAeHdaClient.Utilities.Interop.GetInt32s(ref pErrors, count, true);

                // construct result array.
                OpcItemResult[] results = new OpcItemResult[count];

                for (int ii = 0; ii < count; ii++)
                {
                    results[ii] = new OpcItemResult(items[ii]);

                    results[ii].ServerHandle   = null;
                    results[ii].Result         = Technosoftware.DaAeHdaClient.Utilities.Interop.GetResultID(errors[ii]);
                    results[ii].DiagnosticInfo = null;

                    // convert COM code to unified DA code.
                    if (errors[ii] == Result.E_BADRIGHTS)
                    {
                        results[ii].Result = new OpcResult(OpcResult.Da.E_READONLY, Result.E_BADRIGHTS);
                    }

                    // apply request options.
                    if ((filters_ & (int)TsCDaResultFilter.ItemName) == 0)
                    {
                        results[ii].ItemName = null;
                    }
                    if ((filters_ & (int)TsCDaResultFilter.ItemPath) == 0)
                    {
                        results[ii].ItemPath = null;
                    }
                    if ((filters_ & (int)TsCDaResultFilter.ClientHandle) == 0)
                    {
                        results[ii].ClientHandle = null;
                    }
                }

                // return results.
                return(results);
            }
        }