Exemplo n.º 1
0
        /// <summary>
        /// Unmarshals and deallocates an OPCHDA_ITEM structure.
        /// </summary>
        internal static ItemValueCollection GetItemValueCollection(OpcRcw.Hda.OPCHDA_ITEM input, bool deallocate)
        {
            ItemValueCollection output = new ItemValueCollection();

            output.ClientHandle = input.hClient;
            output.AggregateID  = input.haAggregate;

            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);

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

                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));

                output.Add(value);
            }

            return(output);
        }
Exemplo n.º 2
0
 public void OnDataChange(int dwTransactionID, int hrStatus, int dwNumItems, OPCHDA_ITEM[] pItemValues, int[] phrErrors)
 {
     try
     {
         lock (this)
         {
             Request request = (Request)this.m_requests[dwTransactionID];
             if (request != null)
             {
                 ItemValueCollection[] results = new ItemValueCollection[pItemValues.Length];
                 for (int i = 0; i < pItemValues.Length; i++)
                 {
                     results[i] = OpcCom.Hda.Interop.GetItemValueCollection(pItemValues[i], false);
                     results[i].ServerHandle = results[i].ClientHandle;
                     results[i].ClientHandle = null;
                     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);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Unmarshals and deallocates an array of OPCHDA_ITEM structures.
        /// </summary>
        internal static ItemValueCollection[] GetItemValueCollections(ref IntPtr pInput, int count, bool deallocate)
        {
            ItemValueCollection[] output = null;

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

                IntPtr pos = pInput;

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

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

            return(output);
        }
Exemplo n.º 4
0
        public void OnReadComplete(int dwTransactionID, int hrStatus, int dwNumItems, OPCHDA_ITEM[] pItemValues, int[] phrErrors)
        {
            try
            {
                lock (this)
                {
                    Request request = (Request)m_requests[dwTransactionID];
                    if (request != null)
                    {
                        ItemValueCollection[] array = new ItemValueCollection[pItemValues.Length];
                        for (int i = 0; i < pItemValues.Length; i++)
                        {
                            array[i] = Interop.GetItemValueCollection(pItemValues[i], deallocate: false);
                            array[i].ServerHandle = pItemValues[i].hClient;
                            array[i].ResultID     = OpcCom.Interop.GetResultID(phrErrors[i]);
                        }

                        if (request.InvokeCallback(array))
                        {
                            m_requests.Remove(request.RequestID);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                HandleException(dwTransactionID, exception);
            }
        }
Exemplo n.º 5
0
 public void OnPlayback(int dwTransactionID, int hrStatus, int dwNumItems, IntPtr ppItemValues, int[] phrErrors)
 {
     try
     {
         lock (this)
         {
             Request request = (Request)this.m_requests[dwTransactionID];
             if (request != null)
             {
                 ItemValueCollection[] results = new ItemValueCollection[dwNumItems];
                 int[] numArray = OpcCom.Interop.GetInt32s(ref ppItemValues, dwNumItems, false);
                 for (int i = 0; i < dwNumItems; i++)
                 {
                     IntPtr pInput = (IntPtr)numArray[i];
                     ItemValueCollection[] valuesArray2 = OpcCom.Hda.Interop.GetItemValueCollections(ref pInput, 1, false);
                     if ((valuesArray2 != null) && (valuesArray2.Length == 1))
                     {
                         results[i] = valuesArray2[0];
                         results[i].ServerHandle = results[i].ClientHandle;
                         results[i].ClientHandle = null;
                         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);
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Called when a batch of data from playback request arrives.
        /// </summary>
        public void OnPlayback(
            int dwTransactionID,
            int hrStatus,
            int dwNumItems,
            IntPtr ppItemValues,
            int[]  phrErrors)
        {
            try
            {
                lock (this)
                {
                    // lookup request transaction.
                    Request request = (Request)m_requests[dwTransactionID];

                    if (request == null)
                    {
                        return;
                    }

                    // unmarshal results.
                    ItemValueCollection[] results = new ItemValueCollection[dwNumItems];

                    // the data is transfered as a array of pointers to items instead of simply
                    // as an array of items. This is due to a mistake in the HDA IDL.
                    int[] pItems = OpcCom.Interop.GetInt32s(ref ppItemValues, dwNumItems, false);

                    for (int ii = 0; ii < dwNumItems; ii++)
                    {
                        // get pointer to item.
                        IntPtr pItem = (IntPtr)pItems[ii];

                        // unmarshal item as an array of length 1.
                        ItemValueCollection[] item = Interop.GetItemValueCollections(ref pItem, 1, false);

                        if (item != null && item.Length == 1)
                        {
                            results[ii] = item[0];
                            results[ii].ServerHandle = results[ii].ClientHandle;
                            results[ii].ClientHandle = null;
                            results[ii].ResultID     = OpcCom.Interop.GetResultID(phrErrors[ii]);
                        }
                    }

                    // invoke callback - remove request if unexpected error occured.
                    if (request.InvokeCallback(results))
                    {
                        m_requests.Remove(request.RequestID);
                    }
                }
            }
            catch (Exception exception)
            {
                HandleException(dwTransactionID, exception);
            }
        }
 private ItemValueCollection CreateTestCollection()
 {
     ItemValueCollection testCollection = new ItemValueCollection();
     ItemValue testItemValue = new ItemValue();
     testItemValue.ItemID = "SimulatedData.Random";
     testItemValue.Timestamp = DateTime.Now;
     Random rnd = new Random();
     testItemValue.Value = rnd.Next(900000);
     testCollection.Add(testItemValue);
     return testCollection;
 }
Exemplo n.º 8
0
        internal static ItemValueCollection GetItemValueCollection(IntPtr pInput, bool deallocate)
        {
            ItemValueCollection itemValueCollection = null;

            if (pInput != IntPtr.Zero)
            {
                itemValueCollection = GetItemValueCollection((OPCHDA_ITEM)Marshal.PtrToStructure(pInput, typeof(OPCHDA_ITEM)), deallocate);
                if (deallocate)
                {
                    Marshal.DestroyStructure(pInput, typeof(OPCHDA_ITEM));
                }
            }
            return(itemValueCollection);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Unmarshals and deallocates an OPCHDA_ITEM structure.
        /// </summary>
        internal static ItemValueCollection GetItemValueCollection(IntPtr pInput, bool deallocate)
        {
            ItemValueCollection output = null;

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

                output = GetItemValueCollection((OpcRcw.Hda.OPCHDA_ITEM)item, deallocate);

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

            return(output);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Called when new data arrives for a subscription.
        /// </summary>
        public void OnDataChange(
            int dwTransactionID,
            int hrStatus,
            int dwNumItems,
            OPCHDA_ITEM[] pItemValues,
            int[]         phrErrors)
        {
            try
            {
                lock (this)
                {
                    // lookup request transaction.
                    Request request = (Request)m_requests[dwTransactionID];

                    if (request == null)
                    {
                        return;
                    }

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

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

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

                    // invoke callback - remove request if unexpected error occured.
                    if (request.InvokeCallback(results))
                    {
                        m_requests.Remove(request.RequestID);
                    }
                }
            }
            catch (Exception exception)
            {
                HandleException(dwTransactionID, exception);
            }
        }
Exemplo n.º 11
0
 internal static ItemValueCollection[] GetItemValueCollections(ref IntPtr pInput, int count, bool deallocate)
 {
     ItemValueCollection[] valuesArray = null;
     if ((pInput != IntPtr.Zero) && (count > 0))
     {
         valuesArray = new ItemValueCollection[count];
         IntPtr ptr = pInput;
         for (int i = 0; i < count; i++)
         {
             valuesArray[i] = GetItemValueCollection(ptr, deallocate);
             ptr            = (IntPtr)(ptr.ToInt32() + Marshal.SizeOf(typeof(OPCHDA_ITEM)));
         }
         if (deallocate)
         {
             Marshal.FreeCoTaskMem(pInput);
             pInput = IntPtr.Zero;
         }
     }
     return(valuesArray);
 }
Exemplo n.º 12
0
        internal static ItemValueCollection GetItemValueCollection(OPCHDA_ITEM input, bool deallocate)
        {
            ItemValueCollection values = new ItemValueCollection {
                ClientHandle = input.hClient,
                AggregateID  = input.haAggregate
            };

            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);
            for (int i = 0; i < input.dwCount; i++)
            {
                Opc.Hda.ItemValue value2 = new Opc.Hda.ItemValue {
                    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)))
                };
                values.Add(value2);
            }
            return(values);
        }
Exemplo n.º 13
0
        public void OnPlayback(int dwTransactionID, int hrStatus, int dwNumItems, IntPtr ppItemValues, int[] phrErrors)
        {
            try
            {
                lock (this)
                {
                    Request request = (Request)m_requests[dwTransactionID];
                    if (request == null)
                    {
                        return;
                    }

                    ItemValueCollection[] array = new ItemValueCollection[dwNumItems];
                    int[] int32s = OpcCom.Interop.GetInt32s(ref ppItemValues, dwNumItems, deallocate: false);
                    for (int i = 0; i < dwNumItems; i++)
                    {
                        IntPtr pInput = (IntPtr)int32s[i];
                        ItemValueCollection[] itemValueCollections = Interop.GetItemValueCollections(ref pInput, 1, deallocate: false);
                        if (itemValueCollections != null && itemValueCollections.Length == 1)
                        {
                            array[i] = itemValueCollections[0];
                            array[i].ServerHandle = array[i].ClientHandle;
                            array[i].ClientHandle = null;
                            array[i].ResultID     = OpcCom.Interop.GetResultID(phrErrors[i]);
                        }
                    }

                    if (request.InvokeCallback(array))
                    {
                        m_requests.Remove(request.RequestID);
                    }
                }
            }
            catch (Exception exception)
            {
                HandleException(dwTransactionID, exception);
            }
        }
Exemplo n.º 14
0
 private ItemValueCollection CreateItemValues(DataTable dt)
 {
     ItemValueCollection result = new ItemValueCollection();
     ItemValue newItemValue;
     foreach (DataRow currentRow in dt.Rows) {
         newItemValue = CreateSingleItemValue(currentRow);
         result.Add(newItemValue);
     }
     return result;
 }
 public ItemValueCollectionEventArgs(ItemValueCollection collection)
 {
     Collection = collection;
 }
 private DateTime UpdateLastTimestamp(ItemValueCollection itemValueCollection)
 {
     int lastIndex = itemValueCollection.Count - 1;
     ItemValue lastItemValue = itemValueCollection[lastIndex];
     return lastItemValue.Timestamp;
 }
Exemplo n.º 17
0
		public ReportItem()
		{
			m_Values = new ItemValueCollection();
		}
Exemplo n.º 18
0
 public ReportItem()
 {
     m_Values = new ItemValueCollection();
 }
Exemplo n.º 19
0
 public ItemWithValues(Item item)
 {
     _item = item;
     _valueCollection = new ItemValueCollection();
 }