0

嗨,我是 RFID 阅读的新手。所以首先我从 github 下载了 pcsc sharp 存储库。然后我尝试从常见的 rfid 标签中读取二进制文件,它工作得很好,但下一步是从我认为模拟的 rfid 标签中读取数据。RFID标签控制器是pn71501。从这个使用 pcsc sharp 的标签中,我无法读取除 ATR 和 uid 之外的任何数据。我试图用我的 iPhone 读取这个标签,它读取了它。那么我做错了什么?

我也尝试使用已经完成的软件,但它也无法读取。

这是我使用 NFC 工具得到的结果:

在此处输入图像描述 在此处输入图像描述

我使用的 PS 智能卡读卡器是 ACS ACR1252

这是我的代码:

using System;
using System.Text;
using System.Collections.Generic;
using PCSC;
using PCSC.Iso7816;

namespace Transmit {
    public class Program {
        public static void Main() {
            using (var context = ContextFactory.Instance.Establish(SCardScope.System)) {
                var readerNames = context.GetReaders();
                if (NoReaderFound(readerNames)) {
                    Console.WriteLine("You need at least one reader in order to run this example.");
                    Console.ReadKey();
                    return;
                }

                var readerName = ChooseRfidReader(readerNames);
                if (readerName == null) {
                    return;
                }

                String response = "";

                using (var rfidReader = context.ConnectReader(readerName, SCardShareMode.Shared, SCardProtocol.Any)) {
                  // for (byte i = 0x00; i < 0x47; i++) {
                        var apdu = new CommandApdu(IsoCase.Case3Extended, rfidReader.Protocol) {
                            CLA = 0xFF,
                            Instruction = (InstructionCode)0xB0,
                            P1 = 0x00,
                            P2 = 0x00,
                            Le = 0x10
                        };

                        using (rfidReader.Transaction(SCardReaderDisposition.Leave)) {
                            //Console.WriteLine("Retrieving the UID .... ");

                            var sendPci = SCardPCI.GetPci(rfidReader.Protocol);
                            var receivePci = new SCardPCI(); // IO returned protocol control information.

                            var receiveBuffer = new byte[256];
                            var command = apdu.ToArray();


                            var bytesReceived = rfidReader.Transmit(
                                sendPci, // Protocol Control Information (T0, T1 or Raw)
                                command, // command APDU
                                command.Length,
                                receivePci, // returning Protocol Control Information
                                receiveBuffer,
                                receiveBuffer.Length); // data buffer

                            var responseApdu =
                                new ResponseApdu(receiveBuffer, bytesReceived, IsoCase.Case3Extended, rfidReader.Protocol);

                        Console.WriteLine(String.Format("SW1: {0:X2} SW2: {1:X2}", responseApdu.SW1, responseApdu.SW2));
                        //if(responseApdu.DataSize > 0) {
                        //response += BitConverter.ToString(responseApdu.GetData()).Replace('-', ' ');
                          response += responseApdu.DataSize;
                           // }
                        }
                   // }
                }
                /*String[] devidedResponse = response.Split(' ');

                String stillResponse = "";

                bool notStarted = true;

                int skipBytes = 7;
                int onByte = 0;

                for(int i = 0; i < devidedResponse.Length; i++) {
                    if (devidedResponse[i] != "D1" && notStarted) {
                        continue;
                    } else if (onByte < skipBytes) {
                        notStarted = false;
                        onByte += 1;
                        continue;
                    } else if (devidedResponse[i] == "FE") {
                        break;
                    }

                    stillResponse += devidedResponse[i] + " ";
                }

                String res = stillResponse.Trim();

                string asciiCharString = "";

                var splitResult = res.Split(' ');

                foreach (string hexChar in splitResult) {
                    var byteChar = int.Parse(hexChar, System.Globalization.NumberStyles.HexNumber);
                    asciiCharString += (char)byteChar;
                }*/
                
                Console.WriteLine(response);
            }

            Console.WriteLine("\nPress any key to exit.");
            Console.ReadKey();
        }

        private static string ChooseRfidReader(IList<string> readerNames) {
            // Show available readers.
            Console.WriteLine("Available readers: ");
            for (var i = 0; i < readerNames.Count; i++) {
                Console.WriteLine($"[{i}] {readerNames[i]}");
            }

            // Ask the user which one to choose.
            Console.Write("Which reader is an RFID reader? ");
            var line = Console.ReadLine();

            if (int.TryParse(line, out var choice) && choice >= 0 && (choice <= readerNames.Count)) {
                return readerNames[choice];
            }

            Console.WriteLine("An invalid number has been entered.");
            Console.ReadKey();
            return null;
        }

        private static bool NoReaderFound(ICollection<string> readerNames) =>
            readerNames == null || readerNames.Count < 1;
    }
}
4

1 回答 1

0

我知道。我之前查过。你能用文件浏览器读卡吗?

可以在三个不同级别读取 UART 等硬件设备

  1. 通过查找硬件 I/O 地址直接读/写 UART
  2. 通过驱动程序读/写。在 c# 中使用开放串行端口。驱动程序获取硬件 I/O
  3. 通过应用程序读/写。应用程序执行上述 1 和/或 2。

您有一个工作应用程序(编号 3),我不知道它使用的是方法 1 还是方法 2。

使用读卡器,我试图让您的编程尽可能简单。如果您有 API,最简单的方法是 3。下一个最简单的是方法 2,如果您安装了供应商驱动程序,您应该可以使用该方法。您应该在设备管理器中看到设备。

要解锁卡(加密),您还需要安装证书而不是卡随附的证书。文件资源管理器应该能够读/写卡。

于 2021-04-18T13:23:55.937 回答