public Personal readCitizenid() { Personal personal = new Personal(); if (Open()) { // Send SELECT/RESET command SendCommand(_apdu.CMD_SELECT()); // CID personal.Citizenid = GetUTF8FromAsciiBytes(SendCommand(_apdu.CMD_CID())); Close(); return personal; } return null; }
public Personal readAll(bool with_photo = false, string readerName = null) { Personal personal = new Personal(); if (Open(readerName)) { // Send SELECT/RESET command SendCommand(_apdu.CMD_SELECT()); // CID personal.Citizenid = GetUTF8FromAsciiBytes(SendCommand(_apdu.CMD_CID())); // Fullname Thai + Eng + BirthDate + Sex personal.Info = GetUTF8FromAsciiBytes(SendCommand(_apdu.CMD_PERSON_INFO())); // Address personal.Address = GetUTF8FromAsciiBytes(SendCommand(_apdu.CMD_ADDRESS())); // issue/expire personal.Issue_Expire = GetUTF8FromAsciiBytes(SendCommand(_apdu.CMD_CARD_ISSUE_EXPIRE())); if (with_photo) { // Photo personal.PhotoRaw = SendPhotoCommand(); } Close(); return personal; } return null; }
// Create new SCardContext then connect, and read data+photo from card public bool ReadCard() { try { _context = new SCardContext(); _context.Establish(SCardScope.System); _cardReader = new SCardReader(_context); Console.WriteLine("Connection was establish"); var readers = _context.GetReaders(); if (readers == null) { MonitorStop(); ReleaseContext(); return(false); } // this will invoke StatusChanged with NewState 'SCRState.Exclusive'. so, handle it carefully _err = _cardReader.Connect(readers.First(), SCardShareMode.Exclusive, SCardProtocol.T0 | SCardProtocol.T1); SetIntPtr(_cardReader.ActiveProtocol); Console.WriteLine("Card Reading."); Console.WriteLine("Check Card Error => " + _err); Console.WriteLine("Check Card Support => " + IsThailandSupportCard()); //Console.WriteLine(IsThailandSupportCard()); if (_err == SCardError.Success && IsThailandSupportCard()) { Personal personal = new Personal(); Console.WriteLine("inside if"); if (eventBeforeCardInserted != null) { eventBeforeCardInserted(); } // Send SELECT/RESET command SendCommand(_apdu.CMD_SELECT()); // CID personal.Citizenid = GetUTF8FromAsciiBytes(SendCommand(_apdu.CMD_CID())); id = personal.Citizenid; // Fullname Thai + Eng + BirthDate + Sex personal.Info = GetUTF8FromAsciiBytes(SendCommand(_apdu.CMD_PERSON_INFO())); // Address personal.Address = GetUTF8FromAsciiBytes(SendCommand(_apdu.CMD_ADDRESS())); // issue/expire personal.Issue_Expire = GetUTF8FromAsciiBytes(SendCommand(_apdu.CMD_CARD_ISSUE_EXPIRE())); // get Photo personal.PhotoRaw = SendPhotoCommand(); if (personal.PhotoRaw == null) { for (int i = 0; i < 3; i++) { Console.WriteLine("try to read photo attemp => " + (i + 1)); personal.PhotoRaw = SendPhotoCommand(); if (personal.PhotoRaw != null) { break; } } } Console.WriteLine("Read complete."); if (eventCardInserted != null) { eventCardInserted(personal); } return(true); } return(false); } catch (PCSCException ex) { _error_code = ECODE_SCardError; _error_message = "Err: " + ex.Message + " (" + ex.SCardError.ToString() + ")"; Console.WriteLine(_error_message); Console.WriteLine("Cant Read"); if (eventCardReadError != null) { eventCardReadError(_error_message); } return(false); } finally { ReleaseContext(); } }