Using System; Using System.Collections.Generic; Using System.Linq; Using System.Runtime.InteropServices; Using System.Text;
public class Readidcardservice {
Public Idcard readidcard (int Port) {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);
Initialize port//int intopenret = Initcomm (1001); if (Intopenret!= 1)//{//throw new Exception (""); //}
Set the current operation of the HID interface iDR210 if (Hidselect (Port) {//card authentication int intreadret = Authenticate (); if (Intreadret!= 1) {//closecomm (); throw new Exception (""); }
Read ID information int intreadbaseinfosret = Readbaseinfos (Name, Gender, Folk, Birthday, Code, address, Agency, EXPI restart, expireend); if (Intreadbaseinfosret!=-3) {//closecomm (); throw new Exception (""); }
Hid_beepled (True,true, 200);
Idcard carddata = new Idcard (); Carddata.cardno = code.tostring (). Trim (); carddata.name = name.tostring (). Trim (); carddata.sex = gender.tostring (). Trim (); carddata.nationality = folk.tostring (). Trim (); Carddata.birthday = birthday.tostring (). Trim (); carddata.address = address.tostring (). Trim (); carddata.institution = agency.tostring (). Trim (); carddata.begin_validity = expirestart.tostring (). Trim (); carddata.end_validity = Expireend.tosTring (). Trim (); Carddata.photodirectory = System.IO.Directory.GetCurrentDirectory () + "//photo.bmp";
Closecomm (); return carddata; else {//closecomm (); throw new Exception (""); } }
[DllImport ("Sdtapi.dll")] " private static extern int Initcomm (int Port)//initialization [DllImport ("Sdtapi.dll")] [ private static extern int Au Thenticate ()//Card certification [DllImport ("Sdtapi.dll")] [ ] private static extern void Closecomm (); Closing ports [DllImport ("Sdtapi.dll")] private static extern int Readbas Einfos (StringBuilder Name, StringBuilder Gender, StringBuilder Folk, Stringbuild Er birthday, StringBuilder Code, StringBuilder address, StringBuilder Agency, St Ringbuilder Expirestart, StringBuilder expireend)/Read data [DllImport ("Sdtapi.dll")] & nbsp private static extern int hid_beepled (bool beepon, bool LeDon, int duration); Buzzer   [DllImport ("Sdtapi.dll")] private static extern bool Hidselect (int index); Set the current operation of the HID interface iDR210 [DllImport ("Sdtapi.dll")] private static Exte RN int CardOn (); Determine if the ID card is on the device
}
---------------------
IDCard.CS
Using System; Using System.Collections.Generic; Using System.Linq; Using System.Text;
public class Idcard {public string name;//name public string sex;//sex public string Cardno; /ID number public string nationality; National public, string birthday; Birthday public string address;//home address public string institution;//issuing authority public string begin_validity //valid start public string end_validity;//valid end public string photodirectory;//photo path; }
--------------------------------------------
Call:
[DllImport ("Sdtapi.dll")] private static extern int Initcomm (int Port);//initialization
///
int Intopenret = Initcomm (1001); if (Intopenret!= 1) { / /initialization failure { &N Bsp Try { &NBS P Readidcardservice readidcardservice = new Readidcardservice (); Idcard carddata = Readidcardservice.readidcard (1); string SFZ = carddata.cardno;//Here you can get the ID card after reading the card information &NBSP ; C Atch (Exception ex) { IF (ex. Message!= "") }
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