www.pudn.com > ReadIC.zip > ICRead.cs, change:2013-12-11,size:2205b


using System.Collections.Generic; 
using System.Text; 
using System; 
using System.Collections; 
using System.ComponentModel; 
using System.Windows.Forms; 
using System.Runtime.InteropServices; 
using System.Reflection; 
 
namespace ReadIC 
{ 
    class ICRead 
    { 
        #region 声明dll入口 
        [DllImport("sdtapi.dll")] 
        private static extern int InitComm (int iPort); 
        [DllImport("sdtapi.dll")] 
        private static extern int Routon_IC_FindCard();//本函数用于寻卡 
        [DllImport("sdtapi.dll")] 
        private static extern int Routon_IC_HL_ReadCardSN(StringBuilder SN);//本函数用于读取IC卡的序列号,自动完成找卡、选卡等过程。 
        [DllImport("sdtapi.dll")] 
        private static extern int Routon_IC_HL_ReadCard(int SID, int BID, int KeyType, byte[] Key,byte[] data);// 
        [DllImport("sdtapi.dll")] 
        private static extern int HID_BeepLED(bool BeepON,bool LEDON,int duration); 
        #endregion 
 
 
        public string Readxlh()//读取卡号 
        { 
            InitComm(1001); 
            StringBuilder sn = new StringBuilder(20); //卡序列号 
           //Routon_IC_FindCard(); 
            Routon_IC_HL_ReadCardSN(sn); 
            string re = sn.ToString(); 
            return re; 
        } 
 
        public string Readcd()//读取卡号 
        { 
            InitComm(1001); 
            StringBuilder sn= new StringBuilder(20); //卡序列号 
            byte[] data ={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //卡号 
            byte[] pw = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; 
            Routon_IC_FindCard(); 
         //   Routon_IC_HL_ReadCardSN(sn); 
            int o = Routon_IC_HL_ReadCard(0, 0, 0x60, pw, data); 
            string re = string.Empty; 
            re = Convert.ToString(data[2], 2).PadLeft(8, '0') + Convert.ToString(data[1], 2).PadLeft(8, '0') + Convert.ToString(data[0], 2).PadLeft(8, '0'); 
            int num =Convert.ToInt32(re,2); 
            HID_BeepLED(true, true, 100); 
            return num.ToString(); 
             
        } 
 
 
    } 
}