博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
刷身份证读出相关信息
阅读量:5270 次
发布时间:2019-06-14

本文共 8237 字,大约阅读时间需要 27 分钟。

View Code
public partial class ReadID : Form    {        public ReadID()        {            InitializeComponent();        }        ///         /// 身份证阅读类        ///         class CVRSDK        {            [DllImport("termb.dll", EntryPoint = "CVR_InitComm", CharSet = CharSet.Auto, SetLastError = false)]            public static extern int CVR_InitComm(int Port);//声明外部的标准动态库, 跟Win32API是一样的            [DllImport("termb.dll", EntryPoint = "CVR_Authenticate", CharSet = CharSet.Auto, SetLastError = false)]            public static extern int CVR_Authenticate();            [DllImport("termb.dll", EntryPoint = "CVR_Read_Content", CharSet = CharSet.Auto, SetLastError = false)]            public static extern int CVR_Read_Content(int Active);            [DllImport("termb.dll", EntryPoint = "CVR_CloseComm", CharSet = CharSet.Auto, SetLastError = false)]            public static extern int CVR_CloseComm();            [DllImport("termb.dll", EntryPoint = "GetPeopleName", CharSet = CharSet.Ansi, SetLastError = false)]            public static extern unsafe int GetPeopleName(ref byte strTmp, ref int strLen);            [DllImport("termb.dll", EntryPoint = "GetPeopleNation", CharSet = CharSet.Ansi, SetLastError = false)]            public static extern int GetPeopleNation(ref byte strTmp, ref int strLen);            [DllImport("termb.dll", EntryPoint = "GetPeopleBirthday", CharSet = CharSet.Ansi, SetLastError = false, CallingConvention = CallingConvention.StdCall)]            public static extern int GetPeopleBirthday(ref byte strTmp, ref int strLen);            [DllImport("termb.dll", EntryPoint = "GetPeopleAddress", CharSet = CharSet.Ansi, SetLastError = false, CallingConvention = CallingConvention.StdCall)]            public static extern int GetPeopleAddress(ref byte strTmp, ref int strLen);            [DllImport("termb.dll", EntryPoint = "GetPeopleIDCode", CharSet = CharSet.Ansi, SetLastError = false, CallingConvention = CallingConvention.StdCall)]            public static extern int GetPeopleIDCode(ref byte strTmp, ref int strLen);            [DllImport("termb.dll", EntryPoint = "GetDepartment", CharSet = CharSet.Ansi, SetLastError = false, CallingConvention = CallingConvention.StdCall)]            public static extern int GetDepartment(ref byte strTmp, ref int strLen);            [DllImport("termb.dll", EntryPoint = "GetStartDate", CharSet = CharSet.Ansi, SetLastError = false, CallingConvention = CallingConvention.StdCall)]            public static extern int GetStartDate(ref byte strTmp, ref int strLen);            [DllImport("termb.dll", EntryPoint = "GetEndDate", CharSet = CharSet.Ansi, SetLastError = false, CallingConvention = CallingConvention.StdCall)]            public static extern int GetEndDate(ref byte strTmp, ref int strLen);            [DllImport("termb.dll", EntryPoint = "GetPeopleSex", CharSet = CharSet.Ansi, SetLastError = false, CallingConvention = CallingConvention.StdCall)]            public static extern int GetPeopleSex(ref byte strTmp, ref int strLen);        }        ///         /// 初始化加载数据        ///         ///         ///        private void ReadID_Load(object sender, EventArgs e)        {            //启动读卡器            try                {                    //初始化启动身份证读卡器                    bool isok = this.InitCRVSDK();                    if (!isok)  { return; }                //是否放置好卡片                    int authenticate = CVRSDK.CVR_Authenticate();                    if (authenticate == 1)                    {                        //是否读到内容                        int readContent = CVRSDK.CVR_Read_Content(4);                        if (readContent == 1)                        {                            FillData();                        }                    }                    else                    {                        //关闭读卡器                        CVRSDK.CVR_CloseComm();                    }                }                catch                {                }            }                ///         /// //初始化读卡器        ///         /// 
public bool InitCRVSDK() { try { int iRetUSB = 0, iRetCOM = 0; int iPort; // USB 口 1001~1016 for (iPort = 1001; iPort <= 1016; iPort++) { iRetUSB = CVRSDK.CVR_InitComm(iPort); if (iRetUSB == 1) { break; } } //连接串口 COM1~COM16 for (iPort = 1; iPort <= 4; iPort++) { iRetCOM = CVRSDK.CVR_InitComm(iPort); if (iRetCOM == 1) { break; } } if ((iRetCOM == 1) || (iRetUSB == 1)) { //MessageBox.Show("读卡器初始化成功!"); return true; } else { // MessageBox.Show("未连接读卡器!"); return false;//启动失败就不启动定时器 } } catch { return false; } } /// /// // 填充数据 /// public void FillData() { try { //相片 zp.bmp(解码) this.pic_Photo.ImageLocation = Application.StartupPath + "\\zp.bmp"; byte[] name = new byte[30]; int length = 30; //得到姓名信息 //得到性别信息 //得到民族信息 //得到出生日期 //得到地址信息 //得到卡号信息 //得到发证机关信息 //得到有效开始日期(签发日期) //得到有效截止日期 //读取设备模块号码 参数 返回值 strTmp[out]: CVRSDK.GetPeopleName(ref name[0], ref length); //MessageBox.Show(); byte[] number = new byte[30]; length = 36; CVRSDK.GetPeopleIDCode(ref number[0], ref length); byte[] people = new byte[30]; length = 3; CVRSDK.GetPeopleNation(ref people[0], ref length); byte[] validtermOfStart = new byte[30]; length = 16; CVRSDK.GetStartDate(ref validtermOfStart[0], ref length); byte[] birthday = new byte[30]; length = 16; CVRSDK.GetPeopleBirthday(ref birthday[0], ref length); byte[] address = new byte[30]; length = 70; CVRSDK.GetPeopleAddress(ref address[0], ref length); byte[] validtermOfEnd = new byte[30]; length = 16; CVRSDK.GetEndDate(ref validtermOfEnd[0], ref length); byte[] signdate = new byte[30]; length = 30; CVRSDK.GetDepartment(ref signdate[0], ref length); byte[] sex = new byte[30]; length = 3; CVRSDK.GetPeopleSex(ref sex[0], ref length); this.txt_Address.Text = System.Text.Encoding.GetEncoding("GB2312").GetString(address); //this.txt_RegAddrres.Text = System.Text.Encoding.GetEncoding("GB2312").GetString(address); this.cbo_Sex.Text = System.Text.Encoding.GetEncoding("GB2312").GetString(sex); this.dt_birth.Text = System.Text.Encoding.GetEncoding("GB2312").GetString(birthday); // lblDept.Text = System.Text.Encoding.GetEncoding("GB2312").GetString(signdate); this.txt_IdCard.Text = System.Text.Encoding.GetEncoding("GB2312").GetString(number); this.txt_Name.Text = System.Text.Encoding.GetEncoding("GB2312").GetString(name); this.cbo_Nation.Text = System.Text.Encoding.GetEncoding("GB2312").GetString(people); // lblValidDate.Text = System.Text.Encoding.GetEncoding("GB2312").GetString(validtermOfStart) + "-" + System.Text.Encoding.GetEncoding("GB2312").GetString(validtermOfEnd); } catch { } } } }

转载于:https://www.cnblogs.com/Warmsunshine/archive/2012/08/07/2627322.html

你可能感兴趣的文章
Android spinner默认样式不支持换行和修改字体样式的解决方法
查看>>
ajax标准格式
查看>>
高薪技术
查看>>
bootstrap collapse 无法收回
查看>>
GuessNumber
查看>>
IDL软件初步了解
查看>>
《高性能SQL调优精要与案例解析》一书谈主流关系库SQL调优(SQL TUNING或SQL优化)核心机制之——索引(index)...
查看>>
【DP】Big Barn 巨大的牛棚
查看>>
private与final修饰方法的区别(转)
查看>>
POJ3154 Graveyard
查看>>
VS .sln .csproj 文件的右键编译
查看>>
第四章运算方法与运算器4_3
查看>>
LSF 作业系统常用命令
查看>>
千里之行,始于足下
查看>>
.net 添加web引用和添加服务引用有什么区别?
查看>>
DWZ框架一些技巧
查看>>
Windows在pip install tensorflow遇到的问题 一些python安装包的时候,超时问题以及权限问题...
查看>>
cocos2d-x 之UITextField的使用
查看>>
BugReport-仿微信app
查看>>
python 三元运算
查看>>