Esempio n. 1
0
        public void WriteCard(CardTrackMode mode, string readData)
        {
            if (readData == null)
            {
                throw new DeviceException(this.DeviceId, "-7", "参数data值非法");
            }

            int returnCode = 0;
            //BP 盒转口控制
            char bpControlFlag = 'A';

            nCommPort = BpController.CommPortToInt(this.PortName, out bpControlFlag);
            BpController.ChangeTo(nCommPort, bpControlFlag, nBaudRate);
            byte[] writeData = new byte[255];
            byte[] tmpBuf    = System.Text.Encoding.Default.GetBytes(readData);
            Array.Clear(writeData, 0, writeData.Length);
            Array.Copy(tmpBuf, writeData, tmpBuf.Length);
            try
            {
                returnCode = CardReaderDllWrapper.WriteCard(nCommPort, writeData, (int)mode);
            }
            catch (Exception e)
            {
                throw new DeviceException(this.DeviceId, "-9999", e.Message.ToString());
            }
            if (returnCode >= 1)
            {
                throw new DeviceException(this.DeviceId, "-9999", "009");
            }
            else
            {
                switch (returnCode)
                {
                case -11:
                    throw new DeviceException(this.DeviceId, returnCode.ToString(), "打开端口失败");

                case -1:
                    throw new DeviceException(this.DeviceId, "-99", "操作超时");

                case -2:
                    throw new DeviceException(this.DeviceId, returnCode.ToString(), "操作失败");

                case -7:
                    throw new DeviceException(this.DeviceId, returnCode.ToString(), "参数mode值非法");

                default:
                    throw new DeviceException(this.DeviceId, returnCode.ToString(), "失败");
                }
            }
        }
Esempio n. 2
0
        public string ReadCard(CardTrackMode mode)
        {
            int returnCode = 0;
            //BP 盒转口控制
            char bpControlFlag = 'A';

            nCommPort = BpController.CommPortToInt(this.PortName, out bpControlFlag);
            BpController.ChangeTo(nCommPort, bpControlFlag, nBaudRate);
            byte[] readData = new byte[255];
            Array.Clear(readData, 0, readData.Length);
            try
            {
                returnCode = CardReaderDllWrapper.ReadCard(nCommPort, readData, (int)mode);
            }
            catch (Exception e)
            {
                throw new DeviceException(this.DeviceId, "-9999", e.Message.ToString());
            }
            if (returnCode >= 1)
            {
                return(System.Text.Encoding.Default.GetString(readData));
            }
            else
            {
                switch (returnCode)
                {
                case -11:
                    throw new DeviceException(this.DeviceId, returnCode.ToString(), "打开端口失败");

                case -1:
                    throw new DeviceException(this.DeviceId, "-99", "操作超时");

                case -2:
                    throw new DeviceException(this.DeviceId, returnCode.ToString(), "操作失败");

                case -7:
                    throw new DeviceException(this.DeviceId, returnCode.ToString(), "参数mode值非法");

                default:
                    throw new DeviceException(this.DeviceId, returnCode.ToString(), "失败");
                }
            }
        }
Esempio n. 3
0
        public void ExportPhoto(string photoPath)
        {
            StringBuilder readData     = new StringBuilder(256);
            int           returnCode   = 0;
            int           returnConde2 = 0;
            int           returnConde3 = 0;

            byte[] CardPUCIIN  = new byte[255];
            byte[] pucManaMsg  = new byte[255];
            byte[] pucCHMsg    = new byte[255];
            byte[] pucPHMsg    = new byte[3024];
            UInt32 puiCHMsgLen = 0;
            UInt32 puiPHMsgLen = 0;

            //BP 盒转口控制
            char bpControlFlag = 'A';

            nCommPort = BpController.CommPortToInt(this.PortName, out bpControlFlag);
            BpController.ChangeTo(nCommPort, bpControlFlag, nBaudRate);

            try
            {
                //开始找卡
                returnCode = IdentityCardReaderDllWrapper.SDT_StartFindIDCard(nCommPort, CardPUCIIN, 1);
            }
            catch (Exception e)
            {
                throw new DeviceException(this.DeviceId, "-9999", "寻卡" + e.Message.ToString());
            }
            if (returnCode != 0x9f)
            {
                switch (returnCode)
                {
                case 128:
                    throw new DeviceException(this.DeviceId, returnCode.ToString(), "寻找证/卡失败");

                case 1:
                    throw new DeviceException(this.DeviceId, "-2", "端口打开失败");

                default:
                    throw new DeviceException(this.DeviceId, returnCode.ToString(), "失败");
                }
            }
            try
            {
                //选卡
                returnConde2 = IdentityCardReaderDllWrapper.SDT_SelectIDCard(nCommPort, pucManaMsg, 1);
            }
            catch (Exception e)
            {
                throw new DeviceException(this.DeviceId, "-9999", "选卡" + e.Message.ToString());
            }
            if (returnConde2 != 0x90)
            {
                switch (returnConde2)
                {
                case 128:
                    throw new DeviceException(this.DeviceId, returnCode.ToString(), "寻找证/卡失败");

                case 1:
                    throw new DeviceException(this.DeviceId, "-2", "端口打开失败");

                default:
                    throw new DeviceException(this.DeviceId, returnCode.ToString(), "失败");
                }
            }

            try
            {
                //读取固定信息
                returnConde3 = IdentityCardReaderDllWrapper.SDT_ReadBaseMsg(nCommPort, pucCHMsg, ref puiCHMsgLen, pucPHMsg, ref puiPHMsgLen, 1);
            }
            catch (Exception e)
            {
                throw new DeviceException(this.DeviceId, "-9999", "读取" + e.Message.ToString());
            }
            if (returnConde3 != 0x90)
            {
                switch (returnConde3)
                {
                case 128:
                    throw new DeviceException(this.DeviceId, returnCode.ToString(), "寻找证/卡失败");

                case 1:
                    throw new DeviceException(this.DeviceId, "-2", "端口打开失败");

                default:
                    throw new DeviceException(this.DeviceId, returnCode.ToString(), "失败");
                }
            }

            //处理图像信息。
            //string path = "C:\\zlz.wlt";
            string path = photoPath + ".wlt";

            File.Delete(path);
            FileStream fs = File.Open(path, FileMode.Append);

            fs.Write(pucPHMsg, 0, pucPHMsg.Length);
            fs.Close();

            int wlt = IdentityCardReaderDllWrapper.GetBmp(path, 2);

            if (wlt == 1)
            {
                // Bitmap image = new Bitmap("C:\\zlz.bmp");
                Bitmap image = new Bitmap(photoPath + ".bmp");
                image.Save(photoPath + ".jpg ", System.Drawing.Imaging.ImageFormat.Jpeg);
                image.Dispose();
            }
        }
Esempio n. 4
0
        //获得验证指纹特征[验证指纹]
        public string GetFeature()
        {
            //指纹特征
            //  string nRetString = "";
            String nRetStringbase64 = "";
            int    nRets            = -1;

            byte[] pRegs = new byte[512];
            //句柄
            int objHdl = -1;
            //返回图像
            int nRet = -1;

            //指纹图像特征
            byte[] pReg = new byte[65536];
            //图像长度
            int pdwLen = pReg.Length;
            //BP 盒转口控制
            char bpControlFlag = 'A';

            nCommPort = BpController.CommPortToInt(this.PortName, out bpControlFlag);
            BpController.ChangeTo(nCommPort, bpControlFlag, nBaudRate);

            try
            {
                objHdl = FingerReaderDllWrapper.TcOpenComm(nCommPort, nBaudRate, 0, 0);
            }
            catch (Exception e)
            {
                throw new DeviceException(this.DeviceId, "-9999", e.Message.ToString());
            }

            if (objHdl == 0)
            {
                throw new DeviceException(this.DeviceId, objHdl.ToString(), "打开句柄失败");
            }

            //返回图像信息。
            int nRetun = 14;

            try
            {
                nRet = FingerReaderDllWrapper.TcLoadrToPimg(objHdl, nRetun, pReg, ref pdwLen);
            }
            catch (Exception e)
            {
                objHdl = FingerReaderDllWrapper.TcCloseComm(objHdl);
                throw new DeviceException(this.DeviceId, "-9999", e.Message.ToString());
            }
            if (nRet != 0)
            {
                objHdl = FingerReaderDllWrapper.TcCloseComm(objHdl);
                throw new DeviceException(this.DeviceId, nRet.ToString(), "获取指纹图像失败");
            }
            else
            {
                // byte[]转成string
                //   nRetString = System.Text.Encoding.Default.GetString(pReg);

                //  nRetString = Convert.ToBase64String(pReg, 0, pdwLen);
                //图像处理

                /*
                 * FingerReaderDllWrapper.TcSmotImg(pReg,152,200);
                 * FingerReaderDllWrapper.SaveTotalImage("D:\\zlz.bmp",pReg, 152, 200);
                 * // FingerReaderDllWrapper.LoadBinaryFile("D:\\zlz.bmp", pReg, pReg.Length);
                 * Bitmap image = new Bitmap("D:\\zlz.bmp");
                 * image.Save("D:\\zlz.jpg ", System.Drawing.Imaging.ImageFormat.Jpeg);
                 * image.Dispose();
                 * int pRegLength= FingerReaderDllWrapper.LoadBinaryFile("D:\\zlz.bmp", pReg, pReg.Length);
                 * nRetStringbase64 = Convert.ToBase64String(pReg, 0, pRegLength);
                 */
                nRetStringbase64 = this.getImageUpdate("", pReg, pdwLen);
                int nIndex = 0;
                int nRetrn = 1;
                nRets = FingerReaderDllWrapper.TcMinutFrPimg(objHdl, nIndex, nRetrn, pRegs, ref pdwLen);
                if (nRets != 0)
                {
                    objHdl = FingerReaderDllWrapper.TcCloseComm(objHdl);
                    throw new DeviceException(this.DeviceId, nRet.ToString(), "获取指纹特征失败");
                }
                else
                {
                    nRetsString = Convert.ToBase64String(pRegs, 0, pdwLen);
                    //蜂鸣器
                    FingerReaderDllWrapper.TcSubDev(objHdl, 0, 10);
                }
            }
            objHdl = FingerReaderDllWrapper.TcCloseComm(objHdl);
            return(nRetStringbase64);
        }
Esempio n. 5
0
        /// <summary>
        /// 获得注册指纹模板
        /// </summary>
        /// <param name="mode">mode:指纹模式,=1,第一次获取指纹模板;=2,第二次获取指纹模板;=3,第三次获取</param>
        /// <remarks>失败抛异常</remarks>
        /// <returns>指纹图片信息,Base64存储为字符串,jpg格式;</returns>
        public string GetTemplate(int nMode)
        {
            //指纹图像base64信息
            String nRetStringbase64 = "";

            //特征合成
            nRetsString = "";
            string        nRetString = "";
            StringBuilder readData   = new StringBuilder(256);
            //句柄
            int objHdl = -1;
            //返回图像
            int nRet = -1;

            //指纹图像特征
            byte[] pReg = new byte[65536];

            //特征合成
            int nRets = -1;

            byte[] pRegs = new byte[512];

            //图像长度
            int pdwLen = pReg.Length;
            //第三次注册指纹,特征合成
            int pdwLen2 = pRegs.Length;
            //  byte[] CardPUCIIN = new byte[255];
            // byte[] pucManaMsg = new byte[255];
            //byte[] pucCHMsg = new byte[255];
            //byte[] pucPHMsg = new byte[3024];

            //BP 盒转口控制
            char bpControlFlag = 'A';

            nCommPort = BpController.CommPortToInt(this.PortName, out bpControlFlag);
            BpController.ChangeTo(nCommPort, bpControlFlag, nBaudRate);


            try
            {
                objHdl = FingerReaderDllWrapper.TcOpenComm(nCommPort, nBaudRate, 0, 0);
            }
            catch (Exception e)
            {
                throw new DeviceException(this.DeviceId, "-9999", e.Message.ToString());
            }
            if (objHdl == 0)
            {
                throw new DeviceException(this.DeviceId, objHdl.ToString(), "打开句柄失败");
            }
            //返回图像信息。
            int nRetun = 14;

            try
            {
                if (0 <= nMode - 1 && nMode - 1 < 3)
                {
                    nRet = FingerReaderDllWrapper.TcSuperRegist(objHdl, nMode - 1, nRetun, pReg, ref pdwLen);
                }
            }
            catch (Exception e)
            {
                objHdl = FingerReaderDllWrapper.TcCloseComm(objHdl);
                throw new DeviceException(this.DeviceId, "-9999", e.Message.ToString());
            }

            if (nRet != 0)
            {
                objHdl = FingerReaderDllWrapper.TcCloseComm(objHdl);
                throw new DeviceException(this.DeviceId, nRet.ToString(), "获取指纹图像信息失败");
            }
            else
            {
                // byte[]转成string
                //   nRetString = System.Text.Encoding.Default.GetString(pReg);
                nRetString       = Convert.ToBase64String(pReg, 0, pdwLen);
                nRetStringbase64 = this.getImageUpdate("", pReg, pdwLen);
                //蜂鸣器
                FingerReaderDllWrapper.TcSubDev(objHdl, 0, 10);
            }
            try
            {
                if (nMode - 1 == 2)
                {
                    nRets = FingerReaderDllWrapper.TcSuperRegist(objHdl, nMode, 0, pRegs, ref pdwLen2);
                    if (nRets != 0)
                    {
                        objHdl = FingerReaderDllWrapper.TcCloseComm(objHdl);
                        throw new DeviceException(this.DeviceId, nRets.ToString(), "特征合成失败");
                    }
                    else
                    {
                        nRetsString = Convert.ToBase64String(pRegs, 0, pdwLen2);
                        //蜂鸣器
                        FingerReaderDllWrapper.TcSubDev(objHdl, 0, 20);
                    }
                }
            }
            catch (Exception e)
            {
                objHdl = FingerReaderDllWrapper.TcCloseComm(objHdl);
                throw new DeviceException(this.DeviceId, "-9999", e.Message.ToString());
            }

            objHdl = FingerReaderDllWrapper.TcCloseComm(objHdl);

            return(nRetStringbase64);
        }