C# 使用RFID c从卡获取信息#

C# 使用RFID c从卡获取信息#,c#,rfid,C#,Rfid,我正在尝试使用RFID Gigatek UR110/115U读取卡中的信息。 这张卡只有一个代码,我想读取它并将其存储在变量中。 我的阅读器在COM4中,通过USB连接 我正在尝试这样的事情: 设计师: private void InitializeComponent() { //... this.serialPort1 = new System.IO.Ports.SerialPort(this.components); //... this.serialPort1

我正在尝试使用RFID Gigatek UR110/115U读取卡中的信息。

这张卡只有一个代码,我想读取它并将其存储在变量中。 我的阅读器在COM4中,通过USB连接

我正在尝试这样的事情:

设计师

private void InitializeComponent()
   {
   //...
   this.serialPort1 = new System.IO.Ports.SerialPort(this.components);
   //...
   this.serialPort1.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(this.serialPort1_DataReceived);
   //...
   private System.IO.Ports.SerialPort serialPort1;
   //...
}
    private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
    {
        if (this.serialPort1.IsOpen == true)
        {
            String aux = this.serialPort1.ReadLine();

            if (Encoding.ASCII.GetBytes(aux)[0] == 2)
                aux = aux.Substring(1);


            if (aux.Length > 10)
                aux = aux.Substring(0, 10);

            this.Lectura = aux;

            if (this.serialPort1.IsOpen)
                this.serialPort1.Close();

            this.tiempo_esperado = 0;
        }
    }
方法

private void InitializeComponent()
   {
   //...
   this.serialPort1 = new System.IO.Ports.SerialPort(this.components);
   //...
   this.serialPort1.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(this.serialPort1_DataReceived);
   //...
   private System.IO.Ports.SerialPort serialPort1;
   //...
}
    private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
    {
        if (this.serialPort1.IsOpen == true)
        {
            String aux = this.serialPort1.ReadLine();

            if (Encoding.ASCII.GetBytes(aux)[0] == 2)
                aux = aux.Substring(1);


            if (aux.Length > 10)
                aux = aux.Substring(0, 10);

            this.Lectura = aux;

            if (this.serialPort1.IsOpen)
                this.serialPort1.Close();

            this.tiempo_esperado = 0;
        }
    }

但这是行不通的。我做错了什么?提前谢谢

您的读者将附带一本手册、SDK和/或开发人员指南,其中将记录他们的串行通信协议,并应附带示例。我注意到“RFID”不是一个特定的技术术语,因为RFID有许多不同的不兼容规范和标准。你能说得更具体些吗?(例如,EPC 1类2代UHF、各种VHF标准以及完全针对NFC的不同规格。您是否已验证您要读取的卡与您的读卡器使用相同的RFID标准?是
aux
string。空的
?如果您使用
读卡器
,您必须确保收到的数据包括新行字符串。使用
Rea>d
ReadExisting
检查实际数据。如果要使用ReadLine,请将
SerialPort.NewLine
设置为更正字符串。