public PersonInfo ReadPersonInfo() { PersonInfo p = new PersonInfo(); try { //String sText; byte[] pucIIN = new byte[4]; byte[] pucSN = new byte[8]; IDCardData CardMsg = new IDCardData(); var nRet = ConvertResultToMessage(Syn_OpenPort(iPort)); if (nRet.Success) { //判断状态 nRet = ConvertResultToMessage(Syn_GetSAMStatus(iPort, 0)); if (!nRet.Success) { throw new Exception(nRet.Message); } //寻找卡 nRet = ConvertResultToMessage(Syn_StartFindIDCard(iPort, ref pucIIN[0], 0)); if (!nRet.Success) { throw new Exception(nRet.Message); } //选择卡 nRet = ConvertResultToMessage(Syn_SelectIDCard(iPort, ref pucSN[0], 0)); if (!nRet.Success) { throw new Exception(nRet.Message); } nRet = ConvertResultToMessage(Syn_ReadMsg(iPort, 0, ref CardMsg)); if (nRet.Success) { p.Name = CardMsg.Name.Trim(); p.Sex = CardMsg.Sex; p.CardNO = CardMsg.IDCardNo; p.Birthday = CardMsg.Born; p.Address = CardMsg.Address; p.Nation = CardMsg.Nation; p.GrantDept = CardMsg.GrantDept; p.IDCardBeginDate = CardMsg.UserLifeBegin; p.IDCardEndDate = CardMsg.UserLifeEnd; p.Photo = Image.FromFile(CardMsg.PhotoFileName); #region Old //listBox1.Items.Add("姓名:" + CardMsg.Name); //listBox1.Items.Add("性别:" + CardMsg.Sex); //listBox1.Items.Add("民族:" + CardMsg.Nation); //listBox1.Items.Add("出生日期:" + CardMsg.Born); //listBox1.Items.Add("住址:" + CardMsg.Address); //listBox1.Items.Add("身份证号:" + CardMsg.IDCardNo); //listBox1.Items.Add("发证机关:" + CardMsg.GrantDept); //listBox1.Items.Add("有效期:" + CardMsg.UserLifeBegin + "-" + CardMsg.UserLifeEnd); //listBox1.Items.Add("照片文件名:" + CardMsg.PhotoFileName); //pictureBox1.Image = Image.FromFile(CardMsg.PhotoFileName); #endregion } else { throw new Exception(nRet.Message); } } else { throw new Exception(nRet.Message); } } catch (Exception ex) { throw new Exception("新中新电子读卡器:\n" + ex.Message, ex); } finally { var nRet = ConvertResultToMessage(Syn_ClosePort(iPort)); if (!nRet.Success) { throw new Exception(nRet.Message); } } return(p); }
public static extern int Syn_ReadMsg(int iPortID, int iIfOpen, ref IDCardData pIDCardData);