コード例 #1
0
        public int Camera_GetCount()
        {
            IVS_INDEX_RANGE pIndexRange = new IVS_INDEX_RANGE();

            pIndexRange.uiFromIndex = 1;
            pIndexRange.uiToIndex   = 1;
            int iCameraCount = 0;

            try
            {
                long   sizeList       = Marshal.SizeOf(typeof(IVS_CAMERA_BRIEF_INFO_LIST));                                                //992
                long   sizeInfo       = Marshal.SizeOf(typeof(IVS_CAMERA_BRIEF_INFO));                                                     //980
                long   deviceInfoLen  = (pIndexRange.uiToIndex - pIndexRange.uiFromIndex) * sizeInfo;                                      //2939020
                long   iBuffSize      = sizeList + deviceInfoLen;                                                                          //2940012
                IntPtr pDeviceListPtr = Marshal.AllocHGlobal((int)iBuffSize);                                                              //734789664
                IntPtr pDeviceINFO    = Marshal.AllocHGlobal((int)deviceInfoLen);                                                          //737738784

                int iCode = IVS_API.IVS_SDK_GetDeviceList(ApplicationEvent.iSession, 2, ref pIndexRange, pDeviceListPtr, (uint)iBuffSize); //0

                IVS_CAMERA_BRIEF_INFO_LIST list = new IVS_CAMERA_BRIEF_INFO_LIST();
                list.stCamerBriefInfo = new IVS_CAMERA_BRIEF_INFO[pIndexRange.uiToIndex - pIndexRange.uiFromIndex];
                list         = (IVS_CAMERA_BRIEF_INFO_LIST)Marshal.PtrToStructure(pDeviceListPtr, typeof(IVS_CAMERA_BRIEF_INFO_LIST));
                iCameraCount = StringEx.getInt(list.uiTotal);                                       //得到数量
                Marshal.FreeHGlobal(pDeviceListPtr);
                Marshal.FreeHGlobal(pDeviceINFO);
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine(ex.ToString());
            }
            return(iCameraCount);
        }
コード例 #2
0
        public void InitCamearaList(int iPACK_SIZE)
        {
            CAMEAR_INF_LIST.Clear();
            CAMEAR_CODE_LIST.Clear();
            CameraNameList.Items.Clear();
            IVS_INDEX_RANGE pIndexRange = new IVS_INDEX_RANGE();

            pIndexRange.uiFromIndex = 1;
            pIndexRange.uiToIndex   = (uint)iPACK_SIZE;
            try
            {
                long   sizeList       = Marshal.SizeOf(typeof(IVS_CAMERA_BRIEF_INFO_LIST));                                               //992
                long   sizeInfo       = Marshal.SizeOf(typeof(IVS_CAMERA_BRIEF_INFO));                                                    //980
                long   deviceInfoLen  = (pIndexRange.uiToIndex - pIndexRange.uiFromIndex) * sizeInfo;                                     //2939020
                long   iBuffSize      = sizeList + deviceInfoLen;                                                                         //2940012
                IntPtr pDeviceListPtr = Marshal.AllocHGlobal((int)iBuffSize);                                                             //734789664
                IntPtr pDeviceINFO    = Marshal.AllocHGlobal((int)deviceInfoLen);                                                         //737738784

                int iRet = IVS_API.IVS_SDK_GetDeviceList(ApplicationEvent.iSession, 2, ref pIndexRange, pDeviceListPtr, (uint)iBuffSize); //0

                IVS_CAMERA_BRIEF_INFO_LIST list = new IVS_CAMERA_BRIEF_INFO_LIST();
                list.stCamerBriefInfo = new IVS_CAMERA_BRIEF_INFO[pIndexRange.uiToIndex - pIndexRange.uiFromIndex];
                list = (IVS_CAMERA_BRIEF_INFO_LIST)Marshal.PtrToStructure(pDeviceListPtr, typeof(IVS_CAMERA_BRIEF_INFO_LIST));
                int cCameraCount = StringEx.getInt(list.uiTotal);//得到数量
                if (list.uiTotal > 0)
                {
                    IntPtr tempInfoIntPtr = Marshal.AllocHGlobal((int)sizeInfo);//531396896
                    byte[] tempInfoByte   = new byte[sizeInfo];

                    for (int index = -1; index < pIndexRange.uiToIndex - pIndexRange.uiFromIndex && index < list.uiTotal - 1; index++)
                    {
                        Marshal.Copy((IntPtr)(pDeviceListPtr + (int)sizeList + (int)sizeInfo * index), tempInfoByte, 0, (int)sizeInfo);
                        Marshal.Copy(tempInfoByte, 0, tempInfoIntPtr, (int)sizeInfo);

                        IVS_CAMERA_BRIEF_INFO st = (IVS_CAMERA_BRIEF_INFO)Marshal.PtrToStructure(tempInfoIntPtr, typeof(IVS_CAMERA_BRIEF_INFO));//摄像机的内容
                        CAMEAR_INF_LIST.Add(st);
                        CAMEAR_CODE_LIST.Add(st.cCode);
                        CameraNameList.Items.Add(st.cName);
                    }
                    Marshal.FreeHGlobal(tempInfoIntPtr);
                }
                else
                {
                }
                Marshal.FreeHGlobal(pDeviceListPtr);
                Marshal.FreeHGlobal(pDeviceINFO);
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine(ex.ToString());
            }
        }