public void InitializeDevice(Message m_message) { if (m_message.GetMessageType() != MessageType.MSG_REGISTER_ID_CARD_INITIALIZE) { return; } CVRSDK.InitializeDevice(); if (CVRSDK.iRetCOM == 1 && CVRSDK.iRetUSB == 1) { MainForm.m_pMainWnd.m_isReadIdCard = true; Message newMessage = new Message(MessageType.MSG_REGISTER_ID_CARD_READ_PROCESS); MainForm.m_pMainWnd.m_sharedDataAndMethod.SendMessage(newMessage); } return; }
public static void InitializeDevice() { try { int iPort; 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; } } } if ((iRetCOM == 1) || (iRetUSB == 1)) { MessageBox.Show("身份证读卡器初始化成功!"); } else { MessageBox.Show("身份证读卡器初始化失败!"); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }//InitializeDevice end here
}//InitializeDevice end here public static CardInfo ReadCard() { CardInfo m_cardInfo = new CardInfo(); while (MainForm.m_pMainWnd.m_isReadIdCard) { try { if ((iRetCOM == 1) || (iRetUSB == 1)) { int authenticate = CVRSDK.CVR_Authenticate(); if (authenticate == 1) { int readContent = CVRSDK.CVR_Read_Content(4); if (readContent == 1) { byte[] name = new byte[30]; int length = 30; CVRSDK.GetPeopleName(ref name[0], ref length); //MessageBox.Show(); 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]); m_cardInfo.address = System.Text.Encoding.GetEncoding("GB2312").GetString(address).Replace("\0", "").Trim(); m_cardInfo.sex = System.Text.Encoding.GetEncoding("GB2312").GetString(sex).Replace("\0", "").Trim(); m_cardInfo.birthday = System.Text.Encoding.GetEncoding("GB2312").GetString(birthday).Replace("\0", "").Trim(); m_cardInfo.signdate = System.Text.Encoding.GetEncoding("GB2312").GetString(signdate).Replace("\0", "").Trim(); m_cardInfo.number = System.Text.Encoding.GetEncoding("GB2312").GetString(number).Replace("\0", "").Trim(); m_cardInfo.name = System.Text.Encoding.GetEncoding("GB2312").GetString(name).Replace("\0", "").Trim(); m_cardInfo.people = System.Text.Encoding.GetEncoding("GB2312").GetString(people).Replace("\0", "").Trim(); m_cardInfo.samid = "安全模块号:" + System.Text.Encoding.GetEncoding("GB2312").GetString(samid).Replace("\0", "").Trim(); m_cardInfo.time = System.Text.Encoding.GetEncoding("GB2312").GetString(validtermOfStart).Replace("\0", "").Trim() + "-" + System.Text.Encoding.GetEncoding("GB2312").GetString(validtermOfEnd).Replace("\0", "").Trim(); return(m_cardInfo); } else { MessageBox.Show("身份证读卡操作失败!"); return(m_cardInfo); } } else { MessageBox.Show("未放卡或卡片放置不正确"); return(m_cardInfo); } } else { MessageBox.Show("身份证读卡器初始化失败!"); return(m_cardInfo); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); return(m_cardInfo); } } return(m_cardInfo); }//ReadCard end here