Example #1
0
        public bool Read(OPCDATASOURCE src, int[] arrHSrv, out OPCItemState[] arrStat)
        {
            arrStat = null;
            int    count = arrHSrv.Length;
            IntPtr ptrStat;
            IntPtr ptrErr;
            // FIXME: check if ifSync valid?
            int hresult = ifSync.Read(src, count, arrHSrv, out ptrStat, out ptrErr);

            if (HRESULTS.Failed(hresult))
            {
                Marshal.ThrowExceptionForHR(hresult);
            }

            int runErr  = (int)ptrErr;
            int runStat = (int)ptrStat;

            if ((runErr == 0) || (runStat == 0))
            {
                Marshal.ThrowExceptionForHR(HRESULTS.E_ABORT);
            }

            arrStat = new OPCItemState[count];
            for (int i = 0; i < count; i++)
            {                                                                                                           // WORKAROUND !!!
                arrStat[i] = new OPCItemState();

                arrStat[i].Error = Marshal.ReadInt32((IntPtr)runErr);
                runErr          += 4;

                arrStat[i].HandleClient = Marshal.ReadInt32((IntPtr)runStat);

                if (HRESULTS.Succeeded(arrStat[i].Error))
                {
                    short vt = Marshal.ReadInt16((IntPtr)(runStat + 16));
                    if (vt == (short)VarEnum.VT_ERROR)
                    {
                        arrStat[i].Error = Marshal.ReadInt32((IntPtr)(runStat + 24));
                    }

                    arrStat[i].TimeStamp = Marshal.ReadInt64((IntPtr)(runStat + 4));
                    arrStat[i].Quality   = Marshal.ReadInt16((IntPtr)(runStat + 12));
                    arrStat[i].DataValue = Marshal.GetObjectForNativeVariant((IntPtr)(runStat + 16));
                    VariantClear((IntPtr)(runStat + 16));
                }
                else
                {
                    arrStat[i].DataValue = null;
                }

                runStat += 32;
            }
            Marshal.DestroyStructure(ptrStat, typeof(tagOPCITEMSTATE));

            Marshal.FreeCoTaskMem(ptrStat);
            Marshal.FreeCoTaskMem(ptrErr);
            return(hresult == HRESULTS.S_OK);
        }
Example #2
0
        public bool Read(OPCDATASOURCE src, int[] arrHSrv, out OPCItemState[] arrStat)
        {
            arrStat = null;
            int count = arrHSrv.Length;
            IntPtr ptrStat;
            IntPtr ptrErr;
            // FIXME: check if ifSync valid?
            int hresult = ifSync.Read(src, count, arrHSrv, out ptrStat, out ptrErr);
            if (HRESULTS.Failed(hresult))
                Marshal.ThrowExceptionForHR(hresult);

            int runErr = (int)ptrErr;
            int runStat = (int)ptrStat;
            if ((runErr == 0) || (runStat == 0))
                Marshal.ThrowExceptionForHR(HRESULTS.E_ABORT);

            arrStat = new OPCItemState[count];
            for (int i = 0; i < count; i++)
            {														// WORKAROUND !!!
                arrStat[i] = new OPCItemState();

                arrStat[i].Error = Marshal.ReadInt32((IntPtr)runErr);
                runErr += 4;

                arrStat[i].HandleClient = Marshal.ReadInt32((IntPtr)runStat);

                if (HRESULTS.Succeeded(arrStat[i].Error))
                {
                    short vt = Marshal.ReadInt16((IntPtr)(runStat + 16));
                    if (vt == (short)VarEnum.VT_ERROR)
                        arrStat[i].Error = Marshal.ReadInt32((IntPtr)(runStat + 24));

                    arrStat[i].TimeStamp = Marshal.ReadInt64((IntPtr)(runStat + 4));
                    arrStat[i].Quality = Marshal.ReadInt16((IntPtr)(runStat + 12));
                    arrStat[i].DataValue = Marshal.GetObjectForNativeVariant((IntPtr)(runStat + 16));
                    VariantClear((IntPtr)(runStat + 16));
                }
                else
                    arrStat[i].DataValue = null;

                runStat += 32;
            }
            Marshal.DestroyStructure(ptrStat, typeof(tagOPCITEMSTATE));

            Marshal.FreeCoTaskMem(ptrStat);
            Marshal.FreeCoTaskMem(ptrErr);
            return hresult == HRESULTS.S_OK;
        }