Exemplo n.º 1
0
        /// <summary>
        /// 连接设备
        /// </summary>
        /// <param name="sIP">设备IP</param>
        /// <returns></returns>
        public bool ConnectCamera(string sIP, IntPtr UserHandle)
        {
            try
            {
                StringBuilder strIP = new StringBuilder(sIP);
                pHandle = IntPtr.Zero;
                Ip      = sIP;
                uint uRes = DeviceInterface.HWTC_ConnectCamera(strIP, ref pHandle);
                if ((DeviceInterface.FEEKBACK_TYPE)uRes == DeviceInterface.FEEKBACK_TYPE.RESULT_OK)
                {
                    DeviceInterface.HWTC_RecordLog(false);
                    DeviceInterface.HWTC_SetRecRealtimeDataMode(pHandle, IntPtr.Zero, RealdataFuc, UserHandle, 0, 0);
                    //设置事件
                    DeviceInterface.HWTC_RegStatusCallback(pHandle, IntPtr.Zero, DeviceStatusFuc, NetStatusFuc, RunStatusFuc);
                    AddDeviceInfo Info = new AddDeviceInfo();
                    Info.intCameraIP         = Until.IP2Int(sIP);
                    Info.ptrCameraHandle     = pHandle;
                    Info.u32ArmBootTime      = 0;
                    Info.u32DspBootTime      = 0;
                    Info.u32DspBootCnt       = 0;
                    Info.ptrCamControlHandle = IntPtr.Zero;
                    Info.OnReadSuccess       = this.OnActionReadSuccess;
                    Info.OnScanError         = this.OnActionScanError;
                    Info.OnStatusChange      = this.OnActionStatusChange;

                    if (ForGlobal.g_DeviceTable[sIP] == null)
                    {
                        ForGlobal.g_DeviceTable.Add(sIP, Info);
                    }
                    if (OnActionStatusChange != null)
                    {
                        OnActionStatusChange(true);
                    }
                    return(true);
                }
                else
                {
                    ErrorStr = uRes.ToString();
                    if (OnActionStatusChange != null)
                    {
                        OnActionStatusChange(false);
                    }
                    return(false);
                }
            }
            catch (Exception)
            {
                if (OnActionStatusChange != null)
                {
                    OnActionStatusChange(false);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 设备运行状态回调
        /// </summary>
        /// <param name="pHandle"></param>
        /// <param name="pUserData"></param>
        /// <param name="ui64AlarmInfoData"></param>
        /// <param name="DevRunInfo"></param>
        public void RunStatus(IntPtr pHandle, IntPtr pUserData, UInt64 ui64AlarmInfoData, ref DeviceInterface.stDevRunInfo DevRunInfo)
        {
            string sIP = string.Empty;

            foreach (DictionaryEntry de in ForGlobal.g_DeviceTable)
            {
                AddDeviceInfo info = (AddDeviceInfo)ForGlobal.g_DeviceTable[de.Key];
                if (info.intCameraIP == DevRunInfo.CamInfo.netInfo.intCameraIP)
                {
                    sIP = de.Key.ToString();

                    break;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 响应控制通道网络状态回调函数
        /// </summary>
        /// <param name="pUserData"></param>
        /// <param name="pHandle"></param>
        /// <param name="ConnStatus"></param>
        public void NetControlStatus(IntPtr pUserData, IntPtr pHandle, DeviceInterface.CAMERA_STATUS ConnStatus)
        {
            string sIP = string.Empty;

            foreach (DictionaryEntry de in ForGlobal.g_DeviceTable)
            {
                AddDeviceInfo info = (AddDeviceInfo)ForGlobal.g_DeviceTable[de.Key];
                if (info.ptrCamControlHandle == pHandle)
                {
                    sIP = de.Key.ToString();

                    //交给外部程序处理

                    break;
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 处理设备工作状态
        /// </summary>
        /// <param name="sIP"></param>
        /// <param name="info"></param>
        public void DealDeviceStatus(string sIP, AddDeviceInfo info)
        {
            DateTime  dt_1970    = new DateTime(1970, 1, 1, 0, 0, 0); //1970年的时间
            const int TICKS_UNIT = 10000000;                          //时刻单位

            Int64    ArmBootTime   = Convert.ToInt64(info.u32ArmBootTime) * TICKS_UNIT;
            Int64    tricks_1970   = dt_1970.Ticks + ArmBootTime;
            DateTime dtArmBootTime = new DateTime(tricks_1970);

            string strArmBootTime = dtArmBootTime.ToString();            //设备重启时间

            Int64 DspBootTime = Convert.ToInt64(info.u32DspBootTime) * TICKS_UNIT;

            tricks_1970 = dt_1970.Ticks + DspBootTime;
            DateTime dtDspBootTime  = new DateTime(tricks_1970);
            string   strDspBootTime = dtDspBootTime.ToString();       //dsp复位时间

            UInt32 nDspBootCount = info.u32DspBootCnt;                //dsp启动次数
        }
Exemplo n.º 5
0
        /// <summary>
        /// 响应设备状态回调函数
        /// </summary>
        /// <param name="pHandle"></param>
        /// <param name="pUserData"></param>
        /// <param name="pDeviceStatus"></param>
        public void DeviceStatus(IntPtr pHandle, IntPtr pUserData, ref DeviceInterface.StDeviceStatus pDeviceStatus)
        {
            string sIP = string.Empty;

            foreach (DictionaryEntry de in ForGlobal.g_DeviceTable)
            {
                AddDeviceInfo info = (AddDeviceInfo)ForGlobal.g_DeviceTable[de.Key];
                if (info.ptrCameraHandle == pHandle)
                {
                    sIP = de.Key.ToString();
                    info.u32ArmBootTime = pDeviceStatus.u32ArmBootTime;
                    info.u32DspBootCnt  = pDeviceStatus.u32DspBootCnt;
                    info.u32DspBootTime = pDeviceStatus.u32DspBootTime;
                    //交给外部程序处理
                    this.DealDeviceStatus(sIP, info);
                    break;
                }
            }
        }
Exemplo n.º 6
0
        //响应实时数据回调函数
        public void Realdata(ref DeviceInterface.AnalysisData pAnalyData)
        {
            string        sIP  = string.Empty;
            AddDeviceInfo info = new AddDeviceInfo();

            foreach (DictionaryEntry de in ForGlobal.g_DeviceTable)
            {
                info = (AddDeviceInfo)ForGlobal.g_DeviceTable[de.Key];
                if (info.intCameraIP == pAnalyData.CamInfo.netInfo.intCameraIP)
                {
                    sIP = de.Key.ToString();
                    break;
                }
            }
            sIP = Until.Int2IP(pAnalyData.CamInfo.netInfo.intCameraIP);
            for (int i = 0; i < pAnalyData.chObjNum; i++)
            {
                DealData(sIP, pAnalyData.pDataInfo[i], info);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 处理数据
        /// </summary>
        /// <param name="sIP"></param>
        /// <param name="ptrData"></param>
        public void DealData(string sIP, IntPtr ptrData, AddDeviceInfo info)
        {
            if (ptrData == IntPtr.Zero)
            {
                return;
            }

            DeviceInterface.TCData pData = (DeviceInterface.TCData)Marshal.PtrToStructure(ptrData, typeof(DeviceInterface.TCData));

            //存储数据
            string sPlate = Encoding.Default.GetString(pData.chPlate);

            sPlate = sPlate.Substring(0, sPlate.IndexOf("\0"));

            string sColor = string.Empty;

            if (sPlate == "")
            {
                sPlate = "无车牌";
            }
            else
            {
                if (info.OnReadSuccess != null)
                {
                    info.OnReadSuccess(sPlate);
                }
                if (sPlate != "无车牌")
                {
                    CarNumber = sPlate;
                }
                switch (pData.PlateColor)
                {
                case DeviceInterface.PLATE_COLOR.YELLOW_COLOR:
                    sColor = "黄";
                    break;

                case DeviceInterface.PLATE_COLOR.BLUE_COLOR:
                    sColor = "蓝";
                    break;

                case DeviceInterface.PLATE_COLOR.WHITE_COLOR:
                    sColor = "白";
                    break;

                case DeviceInterface.PLATE_COLOR.BLACK_COLOR:
                    sColor = "黑";
                    break;

                default:
                    sColor = "未知";
                    break;
                }
            }

            //if (!Directory.Exists(CaptureFilePath))
            //{
            //    Directory.CreateDirectory(CaptureFilePath);
            //}
            FileStream fs      = null;
            string     strFile = string.Empty;

            //判断图像类型
            for (int i = 0; i < pData.usImageCount; i++)
            {
                switch (pData.ImgAttrs[i].imgType)
                {
                //全景图或者二值化图
                case DeviceInterface.IMAGE_TYPE.FULL_IMAGE:
                {
                    switch (pData.ImgAttrs[i].imgFormat)
                    {
                    case DeviceInterface.IMAGE_FORMAT.IMGFORMAT_JPG:
                    {
                        if (pData.ImgAttrs[i].uiImgLen > 0)
                        {
                            strFile = CaptureFilePath;
                            fs      = new FileStream(strFile, FileMode.Create, FileAccess.Write);
                            if (fs != null)
                            {
                                byte[] bytData = new byte[pData.ImgAttrs[i].uiImgLen];
                                Marshal.Copy(pData.ImgAttrs[i].pImgData, bytData, 0, (int)pData.ImgAttrs[i].uiImgLen);
                                fs.Write(bytData, 0, (int)pData.ImgAttrs[i].uiImgLen);
                                fs.Flush();
                                fs.Close();
                            }
                        }
                    }
                    break;

                    case DeviceInterface.IMAGE_FORMAT.IMGFORMAT_BIN:
                    {
                        if (pData.ImgAttrs[i].uiImgLen > 0)
                        {
                            strFile = CaptureFilePath;
                            StringBuilder sbFile = new StringBuilder(strFile);
                            DeviceInterface.HWTC_BinaryTOBmp(sbFile, pData.ImgAttrs[i].pImgData, pData.ImgAttrs[i].usWidth,
                                                             pData.ImgAttrs[i].usHeight);
                        }
                    }
                    break;

                    default:
                        break;
                    }
                }
                break;

                //车牌图
                case DeviceInterface.IMAGE_TYPE.SPECIAL_IMAGE:
                {
                    switch (pData.ImgAttrs[i].imgFormat)
                    {
                    case DeviceInterface.IMAGE_FORMAT.IMGFORMAT_JPG:
                    {
                        if (pData.ImgAttrs[i].uiImgLen > 0)
                        {
                            strFile = CaptureFilePath;
                            fs      = new FileStream(strFile, FileMode.Create, FileAccess.Write);
                            if (fs != null)
                            {
                                byte[] bytData = new byte[pData.ImgAttrs[i].uiImgLen];
                                Marshal.Copy(pData.ImgAttrs[i].pImgData, bytData, 0, (int)pData.ImgAttrs[i].uiImgLen);
                                fs.Write(bytData, 0, (int)pData.ImgAttrs[i].uiImgLen);
                                fs.Flush();
                                fs.Close();
                            }
                        }
                    }
                    break;

                    case DeviceInterface.IMAGE_FORMAT.IMGFORMAT_BIN:
                        break;

                    default:
                        break;
                    }
                }
                break;

                default:
                    break;
                }
            }
        }