Click here to Skip to main content
15,878,953 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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()

        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;
           // Thread.Sleep(500);
            //string data1 = serialPort.ReadLine();
            serialPort1.ReadTimeout = 2000;
            serialPort.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);

            //sp_DataReceived(this , null);
        string data = string.Empty;
        private delegate void SetTextDeleg(string text);
        void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
            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();

Tom Deketelaere 7-Jun-10 4:26am    
Please explain a bit more what you want / what it is doing and what is is supposed to do.
What isn't working, do you get any errors, if so where?
Just saying that it isn't working isn't going to get you any help, we can't read your mind.

1 solution

still r u in problem with this code ?
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900