zoukankan      html  css  js  c++  java
  • 身份证读卡设备-神思电子

    操作顺序:

    • 打开设备,获取句柄
    • 循环读卡
    • 判断设备是否断电
    • 判断是否读到卡
    • 判断是否读卡成功
    • 获取姓名、身份证号码、地址信息

    接口实现:
    采用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);
    }
    

    作者:马洪彪  Q我
    出处:http://www.cnblogs.com/mahongbiao/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    2019.7.17东湖大数据页面三
    2019.7.17东湖大数据页面二
    2019.7.17东湖大数据页面一
    css的使用方法和css选择器
    css定位和浮动
    form表单的理解及用法
    CSS中路径及form表单的用法
    关于新手html的认识 以及对table的基本用法
    网络编程和并发34题
    爬虫day01
  • 原文地址:https://www.cnblogs.com/mahongbiao/p/14626589.html
Copyright © 2011-2022 走看看