本文介绍了如何从C#智能设备中的串行端口读取RFID数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
朋友,
我编写了用于在智能设备中打开串行端口的代码.它正在打开可用的串行端口.现在,我需要用于读取RFID数据(从串行端口)的代码.请帮助我.
Hi Friends,
I wrote the code for opening the serial port in smart device. It is opening the available serial ports. Now I need the code for reading the RFID data (from the serial port). Please help me.
推荐答案
private void btnReadTag_Click(object sender, EventArgs e)
{
serialPort = new SerialPort();// if u r not used Serial Port Tool
serialPort.PortName = "COM1";
serialPort.BaudRate = 9600;
serialPort.DataBits = 8;
serialPort.Parity = Parity.None;
serialPort.StopBits = StopBits.One;
serialPort.Open();
serialPort1.ReadTimeout = 2000;
serialPort.DataReceived += new SerialDataReceivedEventHandler(Fun_DataReceived);
serialPort.Close();
}
//Delegate for the Reading the Tag while RFID Card come to the Range.
string data = string.Empty;
private delegate void SetTextDeleg(string text);
void Fun_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
Thread.Sleep(500);
data = serialPort.ReadLine();
this.BeginInvoke(new SetTextDeleg(Fun_IsDataReceived), new object[] { data });
}
private void Fun_IsDataReceived(string data)
{
txtAccessCardNo.Text = data.Trim();
}
学得很好:)
Have great learning :)
这篇关于如何从C#智能设备中的串行端口读取RFID数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!