本文介绍了在C#中通过RFID模块读取访问卡号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在C#Windows Project中通过rfid读取empolyee Acccess CardNo.
我已经使用了以下代码,但无法正常工作..


i want read empolyee Acccess Card No through rfid in C# Windows Project.
I have used the following code but it is not working..


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO.Ports;

namespace GuestRegistration
{
    public partial class frmGustReg : Form
    {
        public frmGustReg()
        {
            InitializeComponent();
        }

        private void frmGustReg_Load(object sender, EventArgs e)
        {

        }

        //private void btnGetACNo_Click(object sender, EventArgs e)
        //{
        //    serialPort1.DataReceived += new SerialDataReceivedEventHandler(serialPort1_DataReceived);
        //}
        //string data = string.Empty;
        //private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
        //{
        //    data = serialPort1.ReadLine().ToString().Trim();
        //    txtAccessCardNo.Text = data;
        //}
        SerialPort serialPort;
        private void btnGetACNo_Click(object sender, EventArgs e)
        {
            serialPort = new SerialPort();


            serialPort.PortName = "COM1";
            serialPort.BaudRate = 9600;
            serialPort.DataBits = 8;
            serialPort.Parity = Parity.None;
            serialPort.StopBits = StopBits.One;



            //serialPort.Handshake = Handshake.None;
            serialPort.Open();
           // Thread.Sleep(500);
            //string data1 = serialPort.ReadLine();
            serialPort1.ReadTimeout = 2000;
            serialPort.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);

            //sp_DataReceived(this , null);
            serialPort.Close();
        }
        string data = string.Empty;
        private delegate void SetTextDeleg(string text);
        void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            Thread.Sleep(500);
            data = serialPort.ReadLine();
            //data = serialPort.ReadExisting();
            this.BeginInvoke(new SetTextDeleg(si_DataReceived), new object[ ] { data });


        }
        private void si_DataReceived(string data)
        {
            txtAccessCardNo.Text = data.Trim();

        }
    }
}

推荐答案


这篇关于在C#中通过RFID模块读取访问卡号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 18:20