public bool Read(OpcDataSource p_Src, int[] p_ArrHSrv, out OpcItemState[] p_ArrStat)
        {
            p_ArrStat = null;
            int    l_Count = p_ArrHSrv.Length;
            IntPtr l_PtrStat;
            IntPtr l_PtrErr;

            int l_HResult = m_IfSync.Read(p_Src, l_Count, p_ArrHSrv, out l_PtrStat, out l_PtrErr);

            if (HResults.Failed(l_HResult))
            {
                Marshal.ThrowExceptionForHR(l_HResult);
            }

            int l_RunErr  = (int)l_PtrErr;
            int l_RunStat = (int)l_PtrStat;

            if ((l_RunErr == 0) || (l_RunStat == 0))
            {
                Marshal.ThrowExceptionForHR(HResults.E_ABORT);
            }

            p_ArrStat = new OpcItemState[l_Count];

            for (int i = 0; i < l_Count; ++i)
            {
                p_ArrStat[i] = new OpcItemState();

                p_ArrStat[i].Error = Marshal.ReadInt32((IntPtr)l_RunErr);
                l_RunErr          += 4;

                p_ArrStat[i].HandleClient = Marshal.ReadInt32((IntPtr)l_RunStat);

                if (HResults.Succeeded(p_ArrStat[i].Error))
                {
                    short l_VT = Marshal.ReadInt16((IntPtr)(l_RunStat + 16));
                    if (l_VT == (short)VarEnum.VT_ERROR)
                    {
                        p_ArrStat[i].Error = Marshal.ReadInt32((IntPtr)(l_RunStat + 24));
                    }

                    p_ArrStat[i].Timestamp = Marshal.ReadInt64((IntPtr)(l_RunStat + 4));
                    p_ArrStat[i].Quality   = Marshal.ReadInt16((IntPtr)(l_RunStat + 12));
                    p_ArrStat[i].DataValue = Marshal.GetObjectForNativeVariant((IntPtr)(l_RunStat + 16));
                    DummyVariant.VariantClear((IntPtr)(l_RunStat + 16));
                }
                else
                {
                    p_ArrStat[i].DataValue = null;
                }

                l_RunStat += 32;
            }

            Marshal.FreeCoTaskMem(l_PtrStat);
            Marshal.FreeCoTaskMem(l_PtrErr);

            return(l_HResult == HResults.S_OK);
        }
        void IOPCDataCallback.OnReadComplete(int p_TransID, int p_Group, int p_MasterQuality,
                                             int p_MasterError, int p_Count, IntPtr p_ClientItems, IntPtr p_Values,
                                             IntPtr p_Qualities, IntPtr p_TimeStamps, IntPtr p_Errors)
        {
            Trace.WriteLine("OPCGroup.OnReadComplete");
            if ((p_Count == 0) || (p_Group != m_State.HandleClient))
            {
                return;
            }

            int l_Count = (int)p_Count;
            int l_RunH  = (int)p_ClientItems;
            int l_RunV  = (int)p_Values;
            int l_RunQ  = (int)p_Qualities;
            int l_RunT  = (int)p_TimeStamps;
            int l_RunE  = (int)p_Errors;

            OpcItemState[] l_Sts = new OpcItemState[l_Count];

            for (int i = 0; i < l_Count; ++i)
            {
                l_Sts[i]       = new OpcItemState();
                l_Sts[i].Error = Marshal.ReadInt32((IntPtr)l_RunE);
                l_RunE        += 4;

                l_Sts[i].HandleClient = Marshal.ReadInt32((IntPtr)l_RunH);
                l_RunH += 4;

                if (HResults.Succeeded(l_Sts[i].Error))
                {
                    short l_VT = Marshal.ReadInt16((IntPtr)l_RunV);
                    if (l_VT == (short)VarEnum.VT_ERROR)
                    {
                        l_Sts[i].Error = Marshal.ReadInt32((IntPtr)(l_RunV + 8));
                    }

                    l_Sts[i].DataValue = Marshal.GetObjectForNativeVariant((IntPtr)l_RunV);
                    l_Sts[i].Quality   = Marshal.ReadInt16((IntPtr)l_RunQ);
                    l_Sts[i].Timestamp = Marshal.ReadInt64((IntPtr)l_RunT);
                }

                l_RunV += DummyVariant.CONST_SIZE;
                l_RunQ += 2;
                l_RunT += 8;
            }

            var args = new ReadCompleteEventArgs(p_TransID, p_Group, p_MasterQuality, p_MasterError, l_Sts);

            ReadCompleted?.Invoke(this, args);
        }
        void IOPCDataCallback.OnDataChange(int transId,
                                           int @group,
                                           int masterQuality,
                                           int masterError,
                                           int count,
                                           IntPtr clientItemsPtr,
                                           IntPtr valuesPtr,
                                           IntPtr qualitiesPtr,
                                           IntPtr timeStampsPtr,
                                           IntPtr errorsPtr)
        {
            Trace.WriteLine("OPCGroup.OnDataChange, " + DateTime.Now);
            if ((count == 0) || (@group != m_State.HandleClient))
            {
                return;
            }

            //int l_Count = (int) count;
            int runH       = (int)clientItemsPtr;
            int runValue   = (int)valuesPtr;
            int runQuality = (int)qualitiesPtr;
            int runTime    = (int)timeStampsPtr;
            int runError   = (int)errorsPtr;

            var itemStates = new OpcItemState[count];

            for (int i = 0; i < count; ++i)
            {
                itemStates[i] = new OpcItemState {
                    Error = Marshal.ReadInt32((IntPtr)runError)
                };
                runError += 4;

                itemStates[i].HandleClient = Marshal.ReadInt32((IntPtr)runH);
                runH += 4;

                if (HResults.Succeeded(itemStates[i].Error))
                {
                    short value = Marshal.ReadInt16((IntPtr)runValue);
                    if (value == (short)VarEnum.VT_ERROR)
                    {
                        itemStates[i].Error = Marshal.ReadInt32((IntPtr)(runValue + 8));
                    }

                    itemStates[i].DataValue = Marshal.GetObjectForNativeVariant((IntPtr)runValue);
                    itemStates[i].Quality   = Marshal.ReadInt16((IntPtr)runQuality);
                    itemStates[i].Timestamp = Marshal.ReadInt64((IntPtr)runTime);
                }

                runValue   += DummyVariant.CONST_SIZE;
                runQuality += 2;
                runTime    += 8;
            }

            //实体序列化和反序列化
            string json1 = JsonHelper.SerializeObject(itemStates);

            try
            {
                var parameter = new MySqlParameter("?p1", MySqlDbType.Text, 0)
                {
                    Value = json1
                };

                var executeScalar = MySqlHelper.ExecuteScalar("insert into opc_data(item_data) values(?p1)", parameter);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
            var eventArgs = new DataChangeEventArgs(transId, @group, masterQuality, masterError, itemStates);

            DataChanged?.Invoke(this, eventArgs);
        }