WPF—通过华视电子身份证识别仪读取身份证信息
Posted king10086
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WPF—通过华视电子身份证识别仪读取身份证信息相关的知识,希望对你有一定的参考价值。
1.源码
/// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { int iPort; int iRetUSB = 0, iRetCOM = 0; static Hashtable hash = new Hashtable();//转JSON用 public BitmapSource ImgCur { get; set; } public MainWindow() { for (iPort = 1001; iPort <= 1016; iPort++) { iRetUSB = CVRSDK.CVR_InitComm(iPort); if (iRetUSB == 1) { break; } } if (iRetUSB != 1) { for (iPort = 1; iPort <= 4; iPort++) { iRetCOM = CVRSDK.CVR_InitComm(iPort); if (iRetCOM == 1) { break; } } } InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { DispatcherTimer timer; timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromMilliseconds(800); timer.Tick += timer1_Tick; timer.Start(); } private void timer1_Tick(object sender, EventArgs e) { int authenticate = CVRSDK.CVR_Authenticate(); if (authenticate == 1) { int readContent = CVRSDK.CVR_Read_Content(4); if (readContent == 1) { FillData(); } } } private void FillData() { byte[] name = new byte[30]; int length = 30; CVRSDK.GetPeopleName(ref name[0], ref length); 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); byte[] samid = new byte[32]; CVRSDK.CVR_GetSAMID(ref samid[0]); CurCard card = new CurCard(); card.Address = System.Text.Encoding.GetEncoding("GB2312").GetString(address).Replace("