Example #1
0
 public void CloseDevice()
 {
     if (_nHandle != -1)
     {
         CLotusCardDriver.LotusCardCloseDevice(_nHandle);
     }
     _nHandle = -1;
 }
Example #2
0
        public string readNFC_data()
        {
            // 读取设备 // 读取设备信息
            OnLotusCardExtendReadWriteCallBackFunc pt = null;
            long nHandle = LotusCardOpenDevice("", 0, 0, 0, 0, pt);

            if (nHandle == -1)   //MessageBox.Show("驱动读取失败!");
            {
                return("驱动读取失败!");
            }

            // Request寻卡
            int nRequestType = CLotusCardDriver.RT_NOT_HALT;
            LotusCardParamStruct lotusCardParam = new LotusCardParamStruct();// 结构体

            lotusCardParam.arrCardNo          = new byte[8];
            lotusCardParam.arrBuffer          = new byte[64];
            lotusCardParam.arrKeys            = new byte[64];
            lotusCardParam.arrCosResultBuffer = new byte[256];
            int bResult = CLotusCardDriver.LotusCardRequest(nHandle, nRequestType, ref lotusCardParam);

            if (bResult == 0)   //MessageBox.Show("寻卡失败");
            {
                return("寻卡失败");
            }

            // Anticoll读卡
            bResult = Anticoll(nHandle, ref lotusCardParam);
            if (bResult == 0)   //MessageBox.Show("读卡失败");
            {
                return("读卡失败");
            }
            // 读卡成功蜂鸣一下
            bResult = LotusCardBeep(nHandle, 10);
            string nfc_id = string.Empty;

            //for (int i = 0; i < lotusCardParam.arrCardNo.Length - 1; i++)
            //{
            //    nfc_id += Convert.ToString(lotusCardParam.arrCardNo[i], 16).PadLeft(2, '0').ToUpper();// 解决左边输出编号为0,丢失0问题
            //}
            // 读取data信息
            int  rd       = Read(nHandle, 8, ref lotusCardParam);
            uint geterror = LotusCardGetErrorCode(nHandle);

            // MessageBox.Show(Convert.ToString(geterror), "geterror");
            //if (rd == 0)
            //{
            //    MessageBox.Show("ok");
            //    for (int i = 0; i < lotusCardParam.arrBuffer.Length-1; i++)
            //    {
            //        nfc_id += Convert.ToString(lotusCardParam.arrBuffer[i], 16).PadLeft(2, '*').ToUpper();// 解决左边输出编号为0,丢失0问题
            //    }
            //}

            // 关闭设备
            LotusCardCloseDevice(nHandle);
            return(nfc_id);
        }//getNFC_id()
Example #3
0
 public bool OpenDevice()
 {
     _nHandle = CLotusCardDriver.LotusCardOpenDevice("", 0, 0, 0, 0, null);
     if (-1 == _nHandle)
     {
         NotifyMessage("设备打开失败,请确认读卡器是否连接到电脑。");
         return(false);
     }
     return(true);
 }
Example #4
0
        public string getNFC_id(Boolean sound)
        {
            // 读取设备 // 读取设备信息
            OnLotusCardExtendReadWriteCallBackFunc pt = null;
            long nHandle = LotusCardOpenDevice("", 0, 0, 0, 0, pt);

            if (nHandle == -1)
            {                                 //MessageBox.Show("驱动读取失败!");
                return(Convert.ToString(-1)); // "驱动读取失败!";
            }

            // Request寻卡
            int nRequestType = CLotusCardDriver.RT_NOT_HALT;
            LotusCardParamStruct lotusCardParam = new LotusCardParamStruct();// 结构体

            lotusCardParam.arrCardNo          = new byte[8];
            lotusCardParam.arrBuffer          = new byte[64];
            lotusCardParam.arrKeys            = new byte[64];
            lotusCardParam.arrCosResultBuffer = new byte[256];
            int bResult;

            bResult = CLotusCardDriver.LotusCardRequest(nHandle, nRequestType, ref lotusCardParam);
            if (bResult == 0)
            {                                 //MessageBox.Show("寻卡失败");
                return(Convert.ToString(-2)); //"寻卡失败";
            }

            // Anticoll读卡
            bResult = Anticoll(nHandle, ref lotusCardParam);
            if (bResult == 0)
            {                                 //MessageBox.Show("读卡失败");
                return(Convert.ToString(-3)); //"读卡失败";
            }
            // 读卡成功蜂鸣一下
            if (sound)
            {
                bResult = LotusCardBeep(nHandle, 10);
            }
            string nfc_id = string.Empty;

            //foreach (var i in lotusCardParam.arrCardNo)
            //{
            //    nfc_id +=Convert.ToString(i,16);// 可能会多取
            //}
            for (int i = 0; i < lotusCardParam.arrCardNo.Length - 1; i++)
            {
                nfc_id += Convert.ToString(lotusCardParam.arrCardNo[i], 16).PadLeft(2, '0').ToUpper();// 解决左边输出编号为0,丢失0问题
            }
            // 关闭设备
            LotusCardCloseDevice(nHandle);
            return(nfc_id);
        }//getNFC_id()
Example #5
0
        public bool ReadM1Card(bool beep, string oldNumber = "")
        {
            Thread.Sleep(2000);//等待2s

            if (_nHandle == -1)
            {
                return(false);
            }

            int    bResult      = 0;
            int    nRequestType = CLotusCardDriver.RT_NOT_HALT;
            long   lngCardNo    = 0;
            String strLog;

            //开启声音提醒
            if (beep)
            {
                bResult = CLotusCardDriver.LotusCardBeep(_nHandle, 10);
                if (bResult != 1)
                {
                    NotifyMessage("设置读卡器声音提醒失败!");
                    return(false);
                }
            }

            try
            {
                bResult = CLotusCardDriver.LotusCardGetCardNo(_nHandle, nRequestType, ref sttLotusCardParam);
            }
            catch (Exception ex)
            {
                return(false);
            }
            if (bResult != 1)
            {
                //NotifyM1CardNumber(string.Empty);
                NotifyMessage("寻卡失败,请将一卡通放置在读卡器上!");
                return(false);
            }

            lngCardNo = (sttLotusCardParam.arrCardNo[3] << 24 | sttLotusCardParam.arrCardNo[2] << 16 | sttLotusCardParam.arrCardNo[1] << 8 | sttLotusCardParam.arrCardNo[0]) & 0xffffffff;
            strLog    = Convert.ToString(lngCardNo, 16).ToUpper();//卡号
            //strLog = "test";
            if (oldNumber != strLog || string.IsNullOrEmpty(oldNumber))
            {
                NotifyM1CardNumber(strLog);
            }
            NotifyMessage("读卡成功");
            return(true);
        }
Example #6
0
        // 重载函数有参
        public string readNFC_data(Boolean sound)
        {
            bool innersound = true;

            innersound = sound;
            // 读取设备 // 读取设备信息
            OnLotusCardExtendReadWriteCallBackFunc pt = null;
            int nHandle = LotusCardOpenDevice("", 0, 0, 0, 0, pt);

            if (nHandle == -1)
            { //MessageBox.Show("驱动读取失败!");
                return("-1");
            }
            // Request寻卡
            int nRequestType = CLotusCardDriver.RT_NOT_HALT;
            LotusCardParamStruct lotusCardParam = new LotusCardParamStruct();// 结构体

            lotusCardParam.nBufferSize = 0;
            lotusCardParam.arrCardNo   = new byte[8];
            lotusCardParam.arrBuffer   = new byte[64];
            lotusCardParam.arrKeys     = new byte[64];
            //lotusCardParam.arrCosResultBuffer = new byte[256];
            lotusCardParam.arrCosSendBuffer = new byte[256];

            int bResult = CLotusCardDriver.LotusCardRequest(nHandle, nRequestType, ref lotusCardParam);

            if (bResult == 0)
            { //MessageBox.Show("寻卡失败");
                return("-2");
            }

            // Anticoll读卡
            bResult = Anticoll(nHandle, ref lotusCardParam);
            if (bResult == 0)
            {
                return("-3");// 读卡失败
            }
            // 读卡成功蜂鸣一下
            if (innersound)
            {
                bResult = LotusCardBeep(nHandle, 10);
            }

            // 重置卡
            int    reset          = LotusCardResetCpuCard(nHandle, ref lotusCardParam);
            int    sendCOSCommand = 2;
            string cosString      = string.Empty;

            if (reset == 1)
            {
                // 有严格的顺序
                // 指令一
                cosString = "00A4040007D276000085010100";
                mycopyCOSCommand(cosString, ref lotusCardParam);
                sendCOSCommand = LotusCardSendCOSCommand(nHandle, ref lotusCardParam);// 成功执行指令返回int 1
                // 指令有误返回“-5”
                if (sendCOSCommand != 1)
                {
                    return("-5");
                }

                // 指令二
                cosString = "00A4000C02E103";
                mycopyCOSCommand(cosString, ref lotusCardParam);
                sendCOSCommand = LotusCardSendCOSCommand(nHandle, ref lotusCardParam);// 成功执行指令返回int 1
                if (sendCOSCommand != 1)
                {
                    return("-5");
                }

                // 指令三
                cosString = "00A4000C020001";
                mycopyCOSCommand(cosString, ref lotusCardParam);
                sendCOSCommand = LotusCardSendCOSCommand(nHandle, ref lotusCardParam);// 成功执行指令返回int 1
                if (sendCOSCommand != 1)
                {
                    return("-5");
                }

                // 指令四
                cosString = " 00B0000008";
                mycopyCOSCommand(cosString, ref lotusCardParam);
                sendCOSCommand = LotusCardSendCOSCommand(nHandle, ref lotusCardParam);// 成功执行指令返回int 1
                if (sendCOSCommand != 1)
                {
                    return("-5");
                }
            }
            else
            {
                return("-4");
            }               // 重置卡失败
            // 关闭设备
            LotusCardCloseDevice(nHandle);

            string result = "";

            for (int i = 0; i < lotusCardParam.unCosReultBufferLength; i++)
            {
                result += lotusCardParam.arrCosResultBuffer[i].ToString("X2");
            }

            result = result.Replace("9000", "");
            string new_result = string.Empty;

            for (int i = result.Length - 2; i >= 0; i -= 2)
            {
                new_result += result.Substring(i, 2);
            }
            return(new_result);
        }//getNFC_id()