Esempio n. 1
0
 public void OnReadModifiedComplete(int dwTransactionID, int hrStatus, int dwNumItems, OPCHDA_MODIFIEDITEM[] pItemValues, int[] phrErrors)
 {
     try
     {
         lock (this)
         {
             Request request = (Request)this.m_requests[dwTransactionID];
             if (request != null)
             {
                 ModifiedValueCollection[] results = new ModifiedValueCollection[pItemValues.Length];
                 for (int i = 0; i < pItemValues.Length; i++)
                 {
                     results[i] = OpcCom.Hda.Interop.GetModifiedValueCollection(pItemValues[i], false);
                     results[i].ServerHandle = pItemValues[i].hClient;
                     results[i].ResultID     = OpcCom.Interop.GetResultID(phrErrors[i]);
                 }
                 if (request.InvokeCallback(results))
                 {
                     this.m_requests.Remove(request.RequestID);
                 }
             }
         }
     }
     catch (Exception exception)
     {
         this.HandleException(dwTransactionID, exception);
     }
 }
        /// <summary>
        /// Unmarshals and deallocates an array of OPCHDA_MODIFIEDITEM structures.
        /// </summary>
        internal static ModifiedValueCollection[] GetModifiedValueCollections(ref IntPtr pInput, int count, bool deallocate)
        {
            ModifiedValueCollection[] output = null;

            if (pInput != IntPtr.Zero && count > 0)
            {
                output = new ModifiedValueCollection[count];

                IntPtr pos = pInput;

                for (int ii = 0; ii < count; ii++)
                {
                    output[ii] = GetModifiedValueCollection(pos, deallocate);
                    pos        = (IntPtr)(pos.ToInt64() + Marshal.SizeOf(typeof(OpcRcw.Hda.OPCHDA_MODIFIEDITEM)));
                }

                if (deallocate)
                {
                    Marshal.FreeCoTaskMem(pInput);
                    pInput = IntPtr.Zero;
                }
            }

            return(output);
        }
        /// <summary>
        /// Unmarshals and deallocates an OPCHDA_MODIFIEDITEM structure.
        /// </summary>
        internal static ModifiedValueCollection GetModifiedValueCollection(OpcRcw.Hda.OPCHDA_MODIFIEDITEM input, bool deallocate)
        {
            ModifiedValueCollection output = new ModifiedValueCollection();

            output.ClientHandle = input.hClient;

            object[]   values            = OpcCom.Interop.GetVARIANTs(ref input.pvDataValues, input.dwCount, deallocate);
            DateTime[] timestamps        = OpcCom.Interop.GetFILETIMEs(ref input.pftTimeStamps, input.dwCount, deallocate);
            int[]      qualities         = OpcCom.Interop.GetInt32s(ref input.pdwQualities, input.dwCount, deallocate);
            DateTime[] modificationTimes = OpcCom.Interop.GetFILETIMEs(ref input.pftModificationTime, input.dwCount, deallocate);
            int[]      editTypes         = OpcCom.Interop.GetInt32s(ref input.pEditType, input.dwCount, deallocate);
            string[]   users             = OpcCom.Interop.GetUnicodeStrings(ref input.szUser, input.dwCount, deallocate);

            for (int ii = 0; ii < input.dwCount; ii++)
            {
                ModifiedValue value = new ModifiedValue();

                value.Value            = values[ii];
                value.Timestamp        = timestamps[ii];
                value.Quality          = new Opc.Da.Quality((short)(qualities[ii] & 0x0000FFFF));
                value.HistorianQuality = (Opc.Hda.Quality)((int)(qualities[ii] & 0xFFFF0000));
                value.ModificationTime = modificationTimes[ii];
                value.EditType         = (Opc.Hda.EditType)editTypes[ii];
                value.User             = users[ii];

                output.Add(value);
            }

            return(output);
        }
Esempio n. 4
0
        internal static ModifiedValueCollection GetModifiedValueCollection(OPCHDA_MODIFIEDITEM input, bool deallocate)
        {
            ModifiedValueCollection values = new ModifiedValueCollection {
                ClientHandle = input.hClient
            };

            object[]   objArray   = OpcCom.Interop.GetVARIANTs(ref input.pvDataValues, input.dwCount, deallocate);
            DateTime[] timeArray  = OpcCom.Interop.GetFILETIMEs(ref input.pftTimeStamps, input.dwCount, deallocate);
            int[]      numArray   = OpcCom.Interop.GetInt32s(ref input.pdwQualities, input.dwCount, deallocate);
            DateTime[] timeArray2 = OpcCom.Interop.GetFILETIMEs(ref input.pftModificationTime, input.dwCount, deallocate);
            int[]      numArray2  = OpcCom.Interop.GetInt32s(ref input.pEditType, input.dwCount, deallocate);
            string[]   strArray   = OpcCom.Interop.GetUnicodeStrings(ref input.szUser, input.dwCount, deallocate);
            for (int i = 0; i < input.dwCount; i++)
            {
                ModifiedValue value2 = new ModifiedValue {
                    Value            = objArray[i],
                    Timestamp        = timeArray[i],
                    Quality          = new Opc.Da.Quality((short)(numArray[i] & 0xffff)),
                    HistorianQuality = ((Opc.Hda.Quality)numArray[i]) & ((Opc.Hda.Quality)(unchecked ((int)0xffff0000L))),
                    ModificationTime = timeArray2[i],
                    EditType         = (EditType)numArray2[i],
                    User             = strArray[i]
                };
                values.Add((Opc.Hda.ItemValue)value2);
            }
            return(values);
        }
Esempio n. 5
0
        internal static ModifiedValueCollection GetModifiedValueCollection(IntPtr pInput, bool deallocate)
        {
            ModifiedValueCollection modifiedValueCollection = null;

            if (pInput != IntPtr.Zero)
            {
                modifiedValueCollection = GetModifiedValueCollection((OPCHDA_MODIFIEDITEM)Marshal.PtrToStructure(pInput, typeof(OPCHDA_MODIFIEDITEM)), deallocate);
                if (deallocate)
                {
                    Marshal.DestroyStructure(pInput, typeof(OPCHDA_MODIFIEDITEM));
                }
            }
            return(modifiedValueCollection);
        }
        /// <summary>
        /// Unmarshals and deallocates an OPCHDA_MODIFIEDITEM structure.
        /// </summary>
        internal static ModifiedValueCollection GetModifiedValueCollection(IntPtr pInput, bool deallocate)
        {
            ModifiedValueCollection output = null;

            if (pInput != IntPtr.Zero)
            {
                object item = Marshal.PtrToStructure(pInput, typeof(OpcRcw.Hda.OPCHDA_MODIFIEDITEM));

                output = GetModifiedValueCollection((OpcRcw.Hda.OPCHDA_MODIFIEDITEM)item, deallocate);

                if (deallocate)
                {
                    Marshal.DestroyStructure(pInput, typeof(OpcRcw.Hda.OPCHDA_MODIFIEDITEM));
                }
            }

            return(output);
        }
Esempio n. 7
0
        /// <summary>
        /// Called when an asynchronous read modified request completes.
        /// </summary>
        public void OnReadModifiedComplete(
            int dwTransactionID,
            int hrStatus,
            int dwNumItems,
            OPCHDA_MODIFIEDITEM[] pItemValues,
            int[]                 phrErrors)
        {
            try
            {
                lock (this)
                {
                    // lookup request transaction.
                    Request request = (Request)m_requests[dwTransactionID];

                    if (request == null)
                    {
                        return;
                    }

                    // unmarshal results.
                    ModifiedValueCollection[] results = new ModifiedValueCollection[pItemValues.Length];

                    for (int ii = 0; ii < pItemValues.Length; ii++)
                    {
                        results[ii] = Interop.GetModifiedValueCollection(pItemValues[ii], false);

                        results[ii].ServerHandle = pItemValues[ii].hClient;
                        results[ii].ResultID     = OpcCom.Interop.GetResultID(phrErrors[ii]);
                    }

                    // invoke callback - remove request if all results arrived.
                    if (request.InvokeCallback(results))
                    {
                        m_requests.Remove(request.RequestID);
                    }
                }
            }
            catch (Exception exception)
            {
                HandleException(dwTransactionID, exception);
            }
        }
Esempio n. 8
0
 internal static ModifiedValueCollection[] GetModifiedValueCollections(ref IntPtr pInput, int count, bool deallocate)
 {
     ModifiedValueCollection[] valuesArray = null;
     if ((pInput != IntPtr.Zero) && (count > 0))
     {
         valuesArray = new ModifiedValueCollection[count];
         IntPtr ptr = pInput;
         for (int i = 0; i < count; i++)
         {
             valuesArray[i] = GetModifiedValueCollection(ptr, deallocate);
             ptr            = (IntPtr)(ptr.ToInt32() + Marshal.SizeOf(typeof(OPCHDA_MODIFIEDITEM)));
         }
         if (deallocate)
         {
             Marshal.FreeCoTaskMem(pInput);
             pInput = IntPtr.Zero;
         }
     }
     return(valuesArray);
 }