Asp. NET program read the second generation ID card

Source: Internet
Author: User

Generally speaking, the WinForm application solves this problem easily, the Web application is a bit of a hassle.

Here I'm talking about my idea of a solution:

One, you need to have a joint model identity card reader (with drive CD), here I use the iDR200 electronics company, and have the development interface of this reader description.

Second, create a new WinForm control project Readcardcontrol, add a main class Readcard

1. Declaring DLL entry

[DllImport ("Sdtapi.dll")]
private static extern int Initcomm (int iport);//Initialize
[Dllimpor          T ("Sdtapi.dll")]
private static extern int authenticate ();//card Authentication
[DllImport ("Sdtapi.dll")]
private static extern int Readbaseinfos (StringBuilder Name, StringBuilder Gender, StringBuilder Folk, Stringbuilde R Birthday, StringBuilder Code, StringBuilder address, StringBuilder Agency, StringBuilder expirestart, StringBuilder Ex          Pireend);//Read data, recommended use
[DllImport ("Sdtapi.dll")]
private static extern int Closecomm ();//Close Port
[DllImport ("Sdtapi.dll")]
private static extern int readbasemsg (byte[] PMSG, ref int len);//read data, not here
[DllImport ("Sdtapi . dll ')]
private static extern int READBASEMSGW (byte[] PMSG, ref int len);//read data, not here
[dllimport ("Kernel32.dll")]
private static extern int Beep (int dwfreq, int dwduration);/To Roar

2. Card Reader method

private string[] Arrys = null;//declares an array to hold the identity card information


public void OnTimer ()


         {


StringBuilder Name = new StringBuilder (31);


StringBuilder Gender = new StringBuilder (3);


StringBuilder Folk = new StringBuilder (10);


StringBuilder birthday = new StringBuilder (9);


StringBuilder Code = new StringBuilder (19);


StringBuilder address = new StringBuilder (71);


StringBuilder Agency = new StringBuilder (31);


StringBuilder Expirestart = new StringBuilder (9);


StringBuilder expireend = new StringBuilder (9);


//int len = 0;


//string[] temp;


char[] param = {' i '};


byte[] pMsg = new byte[256];


string[] Baseinfo = new STRING[9];





//Open port


int intopenret = Initcomm (1001);


if (intopenret!= 1)


             {


//settext ("Reading equipment Not Connected", lblmsg);


return;


             }


//Card certification


int intreadret = authenticate ();


if (intreadret!= 1)


             {


//settext ("Card authentication failed", lblmsg);


Closecomm ();


return;


             }


//readbaseinfos (recommended)


int intreadbaseinfosret = Readbaseinfos (Name, Gender, Folk, Birthday, Code, address, Agency, Expiresta RT, Expireend);


if (Intreadbaseinfosret!= 1)


             {


//settext ("Read card failure", lblmsg);


Closecomm ();


return;


             }


Beep (2047, 200);


Arrys = new STRING[10];


Arrys[0] = code.tostring (). Trim ();


arrys[1] = name.tostring (). Trim ();


arrys[2] = gender.tostring (). Trim ();


arrys[3] = folk.tostring (). Trim ();


Arrys[4] = birthday.tostring (). Trim ();


arrys[5] = address.tostring (). Trim ();


Arrys[6] = agency.tostring (). Trim ();


Arrys[7] = expirestart.tostring (). Trim ();


Arrys[8] = expireend.tostring (). Trim ();


ARRYS[9] = System.IO.Directory.GetCurrentDirectory () + "\\photo.bmp";


//settext ("Read card Success", lblmsg);


//settext ("certificate number:" + code.tostring (), Label1);


//settext ("Name:" + name.tostring (), Label2);


//settext ("Sex:" + gender.tostring (), label3);


//settext ("ethnic:" + folk.tostring (), label4);


//settext ("Date of birth:" + birthday.tostring (), Label5);


//settext ("Address:" + address.tostring (), label6);


//settext ("issuing authority:" + agency.tostring (), LABEL7);


//settext ("Issuing time:" + expirestart.tostring (), Label8);


//settext ("Effective cut-off time:" + expireend.tostring (), LABEL9);


setimage ("Photo.bmp", pictureBox1);


Closecomm ();


         }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.