身份证读卡设备-神思电子

打开设备,获取句柄

循环读卡

判断设备是否断电

判断是否读到卡

判断是否读卡成功

获取姓名、身份证号码、地址信息

接口实现:
采用Windows api的接口方式,通过dllimport引入Windows api方法。

打开设备 private int Open() { int g_handle = 0; try { g_handle = SS728M05Comom.ss_reader_open(); if (g_handle <= 0) { tsslMsg.Text = "连接设备失败!" + "," + DateTime.Now.TimeOfDay.ToString().Substring(0,8); } else { return g_handle; } } catch (Exception ex) { tsslMsg.Text = "连接设备异常!" + "," + DateTime.Now.TimeOfDay.ToString().Substring(0,8); return 0 ; } finally { } return g_handle; } 关闭设备 private void Close(int g_handle) { try { int iReturn = 0; iReturn = SS728M05Comom.ss_reader_close(g_handle); if (iReturn != 0)//关闭失败 { tsslMsg.Text = "读卡器关闭失败" + "," + DateTime.Now.TimeOfDay.ToString().Substring(0,8); return; } else//关闭成功 { } } catch (Exception ex) { return; } finally { g_handle = 0; } } 读卡 while (true)// { if (bgw.CancellationPending)// { e.Cancel = true; // return; } byte[] devver = new byte[128]; int iReturnReaderStatusCheck = SS_Reader_Version(devver);// if (iReturnReaderStatusCheck != 0)// { bgw.ReportProgress(10, iReturnReaderStatusCheck);// Thread.Sleep(TimeSpan.FromSeconds(5));// continue; } int iReturn = SS728M05IDCard.ss_id_ResetID2Card(g_handle); if (iReturn != 0) { Thread.Sleep(TimeSpan.FromSeconds(1));// continue; } iReturn = SS728M05IDCard.ss_id_read_card(g_handle, 0); if (iReturn != 0) { bgw.ReportProgress(100, "读卡失败"); Thread.Sleep(TimeSpan.FromSeconds(1));// continue; } byte[] _Name = new byte[36]; SS728M05IDCard.ss_id_query_name(g_handle, _Name); string name = Encoding.Default.GetString(_Name); // string addressStr = string.Empty; byte[] address = new byte[128]; SS728M05IDCard.ss_id_query_address(g_handle, address); addressStr = Encoding.Default.GetString(address); // byte[] ID = new byte[24]; SS728M05IDCard.ss_id_query_number(g_handle, ID); string cardNo = Encoding.Default.GetString(ID); // bgw.ReportProgress(50, new object[] { name, addressStr, cardNo }); // Thread.Sleep(TimeSpan.FromSeconds(3)); // } windows api class SS728M05Comom { [DllImport("SS728M05_SDK.dll")] internal static extern int ss_reader_open(); [DllImport("SS728M05_SDK.dll")] internal static extern int ss_reader_close(int ReaderHandle); [DllImport("SS728M05_SDK.dll")] internal static extern int SS_PBOC_ReadCardNum(int icdev, byte[] CardNum); [DllImport("SS728M05_SDK.dll")] internal static extern int ss_dev_beep(int icdev, UInt16 _Amount, UInt16 _Msec); [DllImport("SS728M05_SDK.dll")] internal static extern int SS_Reader_Reset(int ReaderHandle, byte[] ICC_Slot_No, byte[] Response, ref int RespLen); [DllImport("SS728M05_SDK.dll")] internal static extern int SS_Reader_AutoFindCard(long ReaderHandle); [DllImport("SS728M05_SDK.dll")] internal static extern int ICC_Reader_Open(); [DllImport("SS728M05_SDK.dll")] internal static extern int ICC_Reader_Reset(int ReaderHandle, int ICC_Slot_No, byte[] Response, ref int RespLen); [DllImport("SS728M05_SDK.dll")] internal static extern int ICC_Reader_Application(int ReaderHandle, int ICC_Slot_No, int Length_of_Command_APDU, byte[] Command_APDU, byte[] Response_APDU, ref int RespLen); }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzfwsg.html