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);
        }
        public void Next(int l_EnumCountMax, out OpcItemAttributes[] l_Attributes)
        {
            l_Attributes = null;
            IntPtr l_PtrAtt;
            int    l_Count;

            m_IfEnum.Next(l_EnumCountMax, out l_PtrAtt, out l_Count);
            int l_RunAtt = (int)l_PtrAtt;

            if ((l_RunAtt == 0) || (l_Count <= 0) || (l_Count > l_EnumCountMax))
            {
                return;
            }

            l_Attributes = new OpcItemAttributes[l_Count];
            IntPtr l_PtrString;

            for (int i = 0; i < l_Count; ++i)
            {
                l_Attributes[i] = new OpcItemAttributes();

                l_PtrString = (IntPtr)Marshal.ReadInt32((IntPtr)l_RunAtt);
                l_Attributes[i].AccessPath = Marshal.PtrToStringUni(l_PtrString);
                Marshal.FreeCoTaskMem(l_PtrString);

                l_PtrString            = (IntPtr)Marshal.ReadInt32((IntPtr)(l_RunAtt + 4));
                l_Attributes[i].ItemID = Marshal.PtrToStringUni(l_PtrString);
                Marshal.FreeCoTaskMem(l_PtrString);

                l_Attributes[i].Active            = (Marshal.ReadInt32((IntPtr)(l_RunAtt + 8)) != 0);
                l_Attributes[i].HandleClient      = Marshal.ReadInt32((IntPtr)(l_RunAtt + 12));
                l_Attributes[i].HandleServer      = Marshal.ReadInt32((IntPtr)(l_RunAtt + 16));
                l_Attributes[i].AccessRights      = (OpcAccessRights)Marshal.ReadInt32((IntPtr)(l_RunAtt + 20));
                l_Attributes[i].RequestedDataType = (VarEnum)Marshal.ReadInt16((IntPtr)(l_RunAtt + 32));
                l_Attributes[i].CanonicalDataType = (VarEnum)Marshal.ReadInt16((IntPtr)(l_RunAtt + 34));

                l_Attributes[i].EUType = (OpcEuType)Marshal.ReadInt32((IntPtr)(l_RunAtt + 36));
                l_Attributes[i].EUInfo = Marshal.GetObjectForNativeVariant((IntPtr)(l_RunAtt + 40));
                DummyVariant.VariantClear((IntPtr)(l_RunAtt + 40));

                int ptrblob = Marshal.ReadInt32((IntPtr)(l_RunAtt + 28));
                if (ptrblob != 0)
                {
                    int l_BlobSize = Marshal.ReadInt32((IntPtr)(l_RunAtt + 24));
                    if (l_BlobSize > 0)
                    {
                        l_Attributes[i].Blob = new byte[l_BlobSize];
                        Marshal.Copy((IntPtr)ptrblob, l_Attributes[i].Blob, 0, l_BlobSize);
                    }
                    Marshal.FreeCoTaskMem((IntPtr)ptrblob);
                }

                l_RunAtt += 56;
            }

            Marshal.FreeCoTaskMem(l_PtrAtt);
        }
예제 #3
0
        public bool GetItemProperties(string p_ItemID, int[] p_PropertyIDs, out OpcPropertyData[] p_PropertiesData)
        {
            p_PropertiesData = null;
            int l_Count = p_PropertyIDs.Length;

            if (l_Count < 1)
            {
                return(false);
            }

            IntPtr l_PtrDat;
            IntPtr l_PtrErr;
            int    l_HResult = m_IfItmProps.GetItemProperties(p_ItemID, l_Count, p_PropertyIDs, out l_PtrDat, out l_PtrErr);

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

            int l_RunDat = (int)l_PtrDat;
            int l_RunErr = (int)l_PtrErr;

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

            p_PropertiesData = new OpcPropertyData[l_Count];

            for (int i = 0; i < l_Count; ++i)
            {
                p_PropertiesData[i]            = new OpcPropertyData();
                p_PropertiesData[i].PropertyId = p_PropertyIDs[i];

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

                if (p_PropertiesData[i].Error == HResults.S_OK)
                {
                    p_PropertiesData[i].Data = Marshal.GetObjectForNativeVariant((IntPtr)l_RunDat);
                    DummyVariant.VariantClear((IntPtr)l_RunDat);
                }
                else
                {
                    p_PropertiesData[i].Data = null;
                }

                l_RunDat += DummyVariant.CONST_SIZE;
            }

            Marshal.FreeCoTaskMem(l_PtrDat);
            Marshal.FreeCoTaskMem(l_PtrErr);

            return(l_HResult == HResults.S_OK);
        }
예제 #4
0
 public override string ToString()
 {
     return("ID:" + PropertyId + " '" + Description + "' T:" + DummyVariant.VarEnumToString(DataType));
 }