• 身份证读卡设备-德卡科技


    操作顺序:

    • 寻卡
    • 读卡

    读卡

    while (true)//
    {
        if (bgw.CancellationPending)//
        {
            e.Cancel = true; //
            return;
        }
        int result = -1;
        result = DeKaSDK.dc_find_i_d(g_handle);
        if (result == 0)//
        { 
            int m_hId = DeKaSDK.dc_start_i_d(g_handle); 
            if (m_hId < 0)
            { 
                Thread.Sleep(TimeSpan.FromSeconds(1));//
                continue;
            }
            else
            { 
                byte[] name = new byte[64];
                Marshal.Copy((IntPtr)DeKaSDK.dc_i_d_query_name(m_hId), name, 0, name.Length);
                string nameStr = Encoding.Default.GetString(name);
                //
                byte[] id_number = new byte[76];
                Marshal.Copy((IntPtr)DeKaSDK.dc_i_d_query_id_number(m_hId), id_number, 0, id_number.Length);
                string cardNoStr = Encoding.Default.GetString(id_number);
                //
                string IsReadCardAddress = mesh.common.SystemSetting.GetSetting("IsReadCardAddress"); 
                byte[] address = new byte[144];
                Marshal.Copy((IntPtr)DeKaSDK.dc_i_d_query_address(m_hId), address, 0, address.Length);
                string addressStr = Encoding.Default.GetString(address); 
                //
                DeKaSDK.dc_end_i_d(g_handle);
                // 
                bgw.ReportProgress(50, new object[] { nameStr, addressStr, cardNoStr });
                Thread.Sleep(TimeSpan.FromSeconds(3)); //
            }
        } else 
        { 
            Thread.Sleep(TimeSpan.FromSeconds(1));//
            continue;
        }
        #endregion   
    }
    

    Windows api

    internal class DeKaSDK
    {
        #region 外部函数
        [DllImport("winmm")]
        static extern uint timeGetTime();
        [DllImport("winmm")]
        static extern void timeBeginPeriod(int t);
        [DllImport("winmm")]
        static extern void timeEndPeriod(int t);
        [DllImport("dcrf32.dll")]
        public static extern short dc_init(Int16 port, int baud);  //初试化
        [DllImport("dcrf32.dll")]
        public static extern short dc_exit(int icdev);
        [DllImport("dcrf32.dll")]
        public static extern short dc_reset(int icdev, uint sec);
        [DllImport("dcrf32.dll")]
        public static extern short dc_config_card(int icdev, char cardtype);  //初试化
        [DllImport("dcrf32.dll")]
        public static extern short dc_card(int icdev, byte _Mode, ref uint SnrLen);
        //short USER_API dc_card_n(HANDLE icdev, unsigned char _Mode, unsigned int* SnrLen, unsigned char* _Snr);
        [DllImport("dcrf32.dll")]
        public static extern short dc_card_n(int icdev, byte _Mode, ref uint SnrLen, [Out]byte[] _Snr);
        //short USER_API dc_beep(HANDLE icdev, unsigned short _Msec);
        [DllImport("dcrf32.dll")]
        public static extern short dc_beep(int icdev, ushort _Msec);
        //short USER_API dc_authentication_passaddr(HANDLE icdev, unsigned char _Mode, unsigned char _Addr, unsigned char* passbuff);
        [DllImport("dcrf32.dll")]
        public static extern short dc_authentication_passaddr(int icdev, byte _Mode, byte _Addr, [In]byte[] passbuff);
        //short USER_API dc_write(HANDLE icdev, unsigned char _Adr, unsigned char* _Data);
        [DllImport("dcrf32.dll")]
        public static extern short dc_write(int icdev, byte adr, [In] byte[] sdata);  //向卡中写入数据
        //short USER_API dc_write_hex(HANDLE icdev, unsigned char _Adr, char *_Data);
        [DllImport("dcrf32.dll")]
        public static extern short dc_write_hex(int icdev, int adr, [In] byte[] sdata);  //向卡中写入数据(转换为16进制)
        //short USER_API dc_read(HANDLE icdev, unsigned char _Adr, unsigned char *_Data);
        [DllImport("dcrf32.dll")]
        public static extern short dc_read(int icdev, byte adr, [Out] byte[] sdata);  //从卡中读数据
        //short USER_API dc_read_hex(HANDLE icdev, unsigned char _Adr, char *_Data);
        [DllImport("dcrf32.dll")]
        public static extern short dc_read_hex(int icdev, int adr, [Out] byte[] sdata);  //从卡中读数据(转换为16进制)
        //short USER_API a_hex(unsigned char *a, unsigned char *hex, short len);
        [DllImport("dcrf32.dll")]
        public static extern short a_hex([In] byte[] a, [Out] byte[] hex, short len);  //普通字符转换成十六进制字符
        //short USER_API hex_a(unsigned char *hex, unsigned char *a, short length);
        [DllImport("dcrf32.dll")]
        public static extern short hex_a([In] byte[] hex, [Out] byte[] a, short length);  //普通字符转换成十六进制字符
        //short USER_API dc_initval(HANDLE icdev, unsigned char _Adr, unsigned int _Value);
        [DllImport("dcrf32.dll")]
        public static extern short dc_initval(int icdev, byte _Adr, uint _Value);  //普通字符转换成十六进制字符
        // short USER_API dc_readval(HANDLE icdev, unsigned char _Adr, unsigned int *_Value);
        [DllImport("dcrf32.dll")]
        public static extern short dc_readval(int icdev, byte _Adr, ref uint _Value);  //普通字符转换成十六进制字符
        // short USER_API dc_increment(HANDLE icdev, unsigned char _Adr, unsigned int _Value);
        [DllImport("dcrf32.dll")]
        public static extern short dc_increment(int icdev, byte _Adr, uint _Value);  //普通字符转换成十六进制字符
        // short USER_API dc_decrement(HANDLE icdev, unsigned char _Adr, unsigned int _Value);
        [DllImport("dcrf32.dll")]
        public static extern short dc_decrement(int icdev, byte _Adr, uint _Value);  //普通字符转换成十六进制字符
        //short USER_API dc_restore(HANDLE icdev, unsigned char _Adr);
        [DllImport("dcrf32.dll")]
        public static extern short dc_restore(int icdev, byte _Adr);  //普通字符转换成十六进制字符
        //short USER_API dc_transfer(HANDLE icdev, unsigned char _Adr);
        [DllImport("dcrf32.dll")]
        public static extern short dc_transfer(int icdev, byte _Adr);  //普通字符转换成十六进制字符
        //short USER_API dc_pro_resetInt(HANDLE icdev, unsigned char *rlen, unsigned char *receive_data);
        [DllImport("dcrf32.dll")]
        public static extern short dc_pro_resetInt(int icdev, ref byte rlen, [Out]byte[] receive_data);  //普通字符转换成十六进制字符
    
        [DllImport("dcrf32.dll")]
        public static extern short dc_pro_reset(int icdev, ref byte rlen, [Out]byte[] receive_data);
        //short USER_API dc_pro_commandlinkInt(HANDLE icdev, unsigned int slen, unsigned char *sendbuffer, unsigned int *rlen, unsigned char *databuffer, unsigned char timeout);
        [DllImport("dcrf32.dll")]
        public static extern short dc_pro_commandlinkInt(int icdev, uint slen, [In]byte[] sendbuffer, ref uint rlen, [Out]byte[] databuffer, byte timeout);  //普通字符转换成十六进制字符
        //short USER_API dc_card_b(HANDLE icdev, unsigned char *rbuf);
        [DllImport("dcrf32.dll")]
        public static extern short dc_pro_commandlink(int icdev, byte slen, [In]byte[] sendbuffer, ref byte rlen, [Out]byte[] databuffer, byte timeout, int flag);
        [DllImport("dcrf32.dll")]
        public static extern short dc_card_b(int icdev, [Out]byte[] rbuf);  //普通字符转换成十六进制字符
        // short USER_API dc_MFPL0_writeperso(HANDLE icdev, unsigned int BNr, unsigned char *dataperso);
        [DllImport("dcrf32.dll")]
        public static extern short dc_MFPL0_writeperso(int icdev, [In]uint BNr, [Out]byte[] dataperso);  //普通字符转换成十六进制字符
        //short USER_API dc_auth_ulc(HANDLE icdev, unsigned char *key);
        [DllImport("dcrf32.dll")]
        public static extern short dc_auth_ulc(int icdev, [In]byte[] key);  //普通字符转换成十六进制字符
        //short USER_API dc_verifypin_4442(HANDLE icdev, unsigned char *passwd);
        [DllImport("dcrf32.dll")]
        public static extern short dc_verifypin_4442(int icdev, [In]byte[] passwd);  //普通字符转换成十六进制字符
        //short USER_API dc_write_4442(HANDLE icdev, short offset, short length, unsigned char *data_buffer);
        [DllImport("dcrf32.dll")]
        public static extern short dc_write_4442(int icdev, short offset, short length, [In]byte[] data_buffer);  //普通字符转换成十六进制字符
        //short USER_API dc_read_4442(HANDLE icdev, short offset, short length, unsigned char *data_buffer);
        [DllImport("dcrf32.dll")]
        public static extern short dc_read_4442(int icdev, short offset, short length, [Out]byte[] data_buffer);  //普通字符转换成十六进制字符
        [DllImport("dcrf32.dll")]
        public static extern short dc_verifypin_4428(int icdev, [In]byte[] passwd);  //普通字符转换成十六进制字符
        //short USER_API dc_write_4442(HANDLE icdev, short offset, short length, unsigned char *data_buffer);
        [DllImport("dcrf32.dll")]
        public static extern short dc_write_4428(int icdev, short offset, short length, [In]byte[] data_buffer);  //普通字符转换成十六进制字符
        //short USER_API dc_read_4442(HANDLE icdev, short offset, short length, unsigned char *data_buffer);
        [DllImport("dcrf32.dll")]
        public static extern short dc_read_4428(int icdev, short offset, short length, [Out]byte[] data_buffer);  //普通字符转换成十六进制字符
        //short USER_API dc_setcpu(HANDLE icdev, unsigned char _Byte);
        [DllImport("dcrf32.dll")]
        public static extern short dc_setcpu(int icdev, [In]byte _Byte);  //普通字符转换成十六进制字符
        //short USER_API dc_write_24c(HANDLE icdev, short offset, short length, unsigned char *data_buffer);
        [DllImport("dcrf32.dll")]
        public static extern short dc_write_24c(int icdev, short offset, short length, [In]byte[] data_buffer);  //普通字符转换成十六进制字符
        //short USER_API dc_read_4442(HANDLE icdev, short offset, short length, unsigned char *data_buffer);
        [DllImport("dcrf32.dll")]
        public static extern short dc_read_24c(int icdev, short offset, short length, [Out]byte[] data_buffer);  //普通字符转换成十六进制字符
        //short USER_API dc_cpureset(HANDLE icdev, unsigned char *rlen, unsigned char *databuffer);
        [DllImport("dcrf32.dll")]
        public static extern short dc_cpureset(int icdev, ref byte rlen, [Out]byte[] databuffer);  //普通字符转换成十六进制字符
        //short USER_API dc_cpuapduInt(HANDLE icdev, unsigned int slen, unsigned char *sendbuffer, unsigned int *rlen, unsigned char *databuffer);
        [DllImport("dcrf32.dll")]
        public static extern short dc_cpuapduInt(int icdev, uint slen, [In]byte[] sendbuffer, ref uint rlen, [Out]byte[] databuffer);  //普通字符转换成十六进制字符
        [DllImport("dcrf32.dll")]
        public static extern short dc_SamAReadCardInfo(int handle, int type, ref int text_len, [Out]byte[] text, ref int photo_len, [Out]byte[] photo, ref int fingerprint_len, [Out]byte[] fingerprint, ref int extra_len, [Out] byte[] extra);
    
        [DllImport("dcrf32.dll")]
        public static extern short dc_find_i_d(int handle);
        [DllImport("dcrf32.dll")]
        public static extern int dc_start_i_d(int handle);
        [DllImport("dcrf32.dll")]
        public static extern IntPtr dc_i_d_query_name(int handle);
        [DllImport("dcrf32.dll")]
        public static extern IntPtr dc_i_d_query_sex(int handle);
        [DllImport("dcrf32.dll")]
        public static extern IntPtr dc_i_d_query_nation(int handle);
        [DllImport("dcrf32.dll")]
        public static extern IntPtr dc_i_d_query_birth(int handle);
        [DllImport("dcrf32.dll")]
        public static extern IntPtr dc_i_d_query_address(int handle);
        [DllImport("dcrf32.dll")]
        public static extern IntPtr dc_i_d_query_id_number(int handle);
        [DllImport("dcrf32.dll")]
        public static extern IntPtr dc_i_d_query_department(int handle);
        [DllImport("dcrf32.dll")]
        public static extern IntPtr dc_i_d_query_expire_day(int handle);
        [DllImport("dcrf32.dll")]
        public static extern short dc_i_d_query_photo_bmp_buffer(int handle, [Out]byte[] bmp_buffer, ref int bmp_len);
        [DllImport("dcrf32.dll")]
        public static extern short dc_i_d_query_photo_file(int handle, [Out]byte[] FileName);
        [DllImport("dcrf32.dll")]
        public static extern short dc_end_i_d(int handle);
        [DllImport("dcrf32.dll")]
        public static extern short dc_ParseTextInfo(int handle, int charset, int info_len, [Out]byte[] info, [Out]byte[] name, [Out]byte[] sex, [Out]byte[] nation, [Out]byte[] birth_day, [Out]byte[] address, [Out]byte[] id_number, [Out]byte[] department, [Out] byte[] expire_start_day, [Out]byte[] expire_end_day, [Out] byte[] reserved);
        [DllImport("dcrf32.dll")]
        public static extern short dc_ParseTextInfoForForeigner(int handle, int charset, int info_len, [Out]byte[] info, [Out]byte[] english_name, [Out]byte[] sex, [Out]byte[] id_number, [Out]byte[] citizenship, [Out] byte[] chinese_name, [Out]byte[] expire_start_day, [Out] byte[] expire_end_day, [Out] byte[] birth_day, [Out]byte[] version_number, [Out]byte[] department_code, [Out] byte[] type_sign, [Out]byte[] reserved);
        [DllImport("dcrf32.dll")]
        public static extern short dc_ParsePhotoInfo(int handle, int type, int info_len, [Out]byte[] info, ref int photo_len, [Out]byte[] photo);
        [DllImport("dcrf32.dll")]
        public static extern short dc_ParseOtherInfo(int icdev, int flag, [In]byte[] in_info, [Out]byte[] out_info);
        [DllImport("dcrf32.dll")]
        public static extern short dc_Scan2DBarcodeStart(int icdev, byte mode);
        [DllImport("dcrf32.dll")]
        public static extern short dc_Scan2DBarcodeGetData(int icdev, ref int rlen, [Out]byte[] rdata);
        [DllImport("dcrf32.dll")]
        public static extern short dc_Scan2DBarcodeExit(int icdev);
    
        #endregion
    }
    

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

  • 相关阅读:
    网店推广之秘诀
    预言:“你被暴光了没有?” 将成为2010又一网络流行语
    已不联系好多年
    任道而重远
    从思南县看撤县建市对提升城市价值的影响
    我和三十有个约定
    浅谈小学生英语学习方法
    热烈祝贺IT诗人代腾飞官方网站开通啦
    爱情许愿砂
    “走远了” 2010又一网络流行语诞生
  • 原文地址:https://www.cnblogs.com/mahongbiao/p/14626658.html
Copyright © 2020-2023  润新知