Exemple #1
0
        /// <summary>
        /// 小图回调
        /// </summary>
        /// <param name="pFirstParameter"></param>
        /// <param name="dwCarID"></param>
        /// <param name="wImageWidth"></param>
        /// <param name="wImageHigh"></param>
        /// <param name="bType"></param>
        /// <param name="wSize"></param>
        /// <param name="pbImage"></param>
        /// <param name="dwTimeMs"></param>
        /// <returns></returns>
        private unsafe long onSmallImgCallBack(IntPtr pFirstParameter, uint dwCarID, ushort wImageWidth, ushort wImageHigh, byte bType,
                                               ushort wSize, byte *pbImage, ulong dwTimeMs)
        {
            HvResult hvresult = Marshal.GetObjectForIUnknown(pFirstParameter) as HvResult;

            if (null == hvresult)
            {
                return(-1);
            }

            ////设置缓存长度
            int iRealLen = 0;
            int iBuffLen = (int)wImageWidth * (int)wImageHigh * 3 + 1024;

            hvresult.SmallImage = new byte[iBuffLen];
            ////m_Redult为存储结果流的类
            long state = 0;

            fixed(byte *pDest = hvresult.SmallImage)
            {
                state = HVDLLFun.Yuv2BMP(pDest, iBuffLen, ref iRealLen, pbImage, wImageWidth, wImageHigh);
                Array.Resize <byte>(ref hvresult.SmallImage, iRealLen);
            }

            return(0);
        }
Exemple #2
0
 /// <summary>
 /// 关闭当前识别器
 /// </summary>
 /// <returns></returns>
 public string Close()
 {
     if (IntPtr.Zero != this.m_Hv)
     {
         HVDLLFun.CloseHv(this.m_Hv);
     }
     this.m_Hv             = IntPtr.Zero;
     this.ipaddr           = "";
     this.resultFirst.m_Hv = this.resultSecond.m_Hv = IntPtr.Zero;
     this.whCheckOpened.Set();
     return("");
 }
Exemple #3
0
 /// <summary>
 /// 检查是否连接,断开时自动重联
 /// </summary>
 private void checkedOpened()
 {
     while (IntPtr.Zero != this.m_Hv)
     {
         Int32 piStatus = -1;
         HVDLLFun.HvIsConnected(this.m_Hv, ref piStatus);
         if (0 != piStatus && IntPtr.Zero != this.m_Hv)
         {
             IntPtr hdl = this.m_Hv;
             this.m_Hv = IntPtr.Zero;
             this.Open(this.ipaddr);
             if (IntPtr.Zero == this.m_Hv)
             {
                 this.m_Hv = hdl;
             }
         }
         this.whCheckOpened.WaitOne(10000, false);
     }
 }
Exemple #4
0
        /// <summary>
        /// 车牌号回调
        /// </summary>
        /// <param name="pFirstParameter">第一个传递参数</param>
        /// <param name="dwCarID">车号</param>
        /// <param name="pcPlateNo">车牌号</param>
        /// <param name="dwTimeMs">时间</param>
        /// <returns></returns>
        private long onPlateNoCallBack(IntPtr pFirstParameter, uint dwCarID, string pcPlateNo, ulong dwTimeMs)
        {
            HvResult hvresult = Marshal.GetObjectForIUnknown(pFirstParameter) as HvResult;

            if (null == hvresult)
            {
                return(-1);
            }

            string strplateno, strcolor;
            int    length = pcPlateNo.Length;

            strcolor   = pcPlateNo.Substring(0, 1);
            strplateno = pcPlateNo.Substring(1, length - 1);
            //时间的转化
            long     time_C_Long = (long)dwTimeMs;                    //C++长整型日期,毫秒为单位
            DateTime dt_1970     = new DateTime(1970, 1, 1, 0, 0, 0, 0);
            long     tricks_1970 = dt_1970.Ticks;                     //1970年1月1日刻度
            long     time_tricks = tricks_1970 + time_C_Long * 10000; //日志日期刻度
            DateTime dt          = new DateTime(time_tricks);         //转化为DateTime(世界时间)

            DateTime dt2 = dt.ToLocalTime();                          //将世界时间转化为当前时间(本时区的时间)

            hvresult.strTime = string.Format("{0:yyyy-MM-dd HH:mm:ss}", dt2);
            byte[] plateinfo = new byte[256];
            unsafe
            {
                byte *pszInfo = null;
                HVDLLFun.HV_GetPlateInfo(hvresult.m_Hv, &pszInfo);                                      //提取附加的信息
                Marshal.Copy((IntPtr)pszInfo, plateinfo, 0, 256);
            }
            hvresult.CarID      = dwCarID;
            hvresult.info       = Encoding.Default.GetString(plateinfo);
            hvresult.strcolor   = strcolor;
            hvresult.strplateno = strplateno;
            return(0);
        }
Exemple #5
0
        /// <summary>
        /// 打开指定IP地址的识别器
        /// </summary>
        /// <param name="ip">识别器IP地址</param>
        /// <returns></returns>
        public string Open(string ip)
        {
            //已经打开直接返回,关闭时同步退出打开状态检查
            if (IntPtr.Zero != this.m_Hv && this.ipaddr == ip)
            {
                return("");
            }
            this.Close();
            this.m_Hv = HVDLLFun.OpenHv(ip);
            if (m_Hv == IntPtr.Zero)
            {
                this.m_Hv        = IntPtr.Zero;
                this.ipaddr      = "";
                resultFirst.m_Hv = resultSecond.m_Hv = IntPtr.Zero;
                return("连接设备失败!");
            }
            this.ipaddr      = ip;
            resultFirst.m_Hv = resultSecond.m_Hv = this.m_Hv;
            //创建参数
            //第一通道参数
            IntPtr argfirst = Marshal.GetIUnknownForObject(this.resultFirst);
            //第二通道参数
            IntPtr argsecond = Marshal.GetIUnknownForObject(this.resultSecond);

            //车牌号回调
            plateCallback = new HVDLLFun.PLATE_NO_CALLBACK(onPlateNoCallBack);
            IntPtr ptfunPlt   = Marshal.GetFunctionPointerForDelegate(plateCallback);
            UInt16 streamtype = Convert.ToUInt16(HvStreamType.PlateStr);
            int    f          = HVDLLFun.SetHvCallBack(this.m_Hv, ptfunPlt, argfirst, 0, streamtype);

            if (f > -1)
            {
                f = HVDLLFun.SetHvCallBack(this.m_Hv, ptfunPlt, argsecond, 1, streamtype);
            }
            if (f > -1)
            {
                //车牌小图回调
                unsafe
                {
                    sImgCallback = new HVDLLFun.SMALL_IMAGE_CALLBACK(onSmallImgCallBack);
                    IntPtr ptfunImgsmall = Marshal.GetFunctionPointerForDelegate(sImgCallback);
                    streamtype = Convert.ToUInt16(HvStreamType.SmallImage);
                    f          = HVDLLFun.SetHvCallBack(this.m_Hv, ptfunImgsmall, argfirst, 0, streamtype);
                    if (f > -1)
                    {
                        f = HVDLLFun.SetHvCallBack(this.m_Hv, ptfunImgsmall, argsecond, 1, streamtype);
                    }
                }
            }
            if (f > -1)
            {
                //大图回调
                unsafe
                {
                    bImgCallbak = new HVDLLFun.BIG_IMAGE_CALLBACK(onBigImgCallBack);
                    IntPtr ptfunImgbig = Marshal.GetFunctionPointerForDelegate(bImgCallbak);
                    streamtype = Convert.ToUInt16(HvStreamType.BigImage);
                    f          = HVDLLFun.SetHvCallBack(this.m_Hv, ptfunImgbig, argfirst, 0, streamtype);
                    if (f > -1)
                    {
                        f = HVDLLFun.SetHvCallBack(this.m_Hv, ptfunImgbig, argsecond, 1, streamtype);
                    }
                }
            }
            if (f > -1)
            {
                //视频回调
                unsafe
                {
                    videoCallback = new HVDLLFun.VIDEO_CALLBACK(onVideoCallBack);
                    IntPtr ptfunVideo = Marshal.GetFunctionPointerForDelegate(videoCallback);
                    streamtype = Convert.ToUInt16(HvStreamType.FullCmpImage);
                    f          = HVDLLFun.SetHvCallBack(this.m_Hv, ptfunVideo, argfirst, 0, streamtype);
                    if (f > -1)
                    {
                        f = HVDLLFun.SetHvCallBack(this.m_Hv, ptfunVideo, argsecond, 1, streamtype);
                    }
                }
            }
            if (f < 0)
            {
                this.Close();
                return("回调设置失败!");
            }
            ThreadManager.QueueUserWorkItem(delegate(object obj) { this.checkedOpened(); }, null);
            return("");
        }