I am trying to extract the correct RFID TAG ID in asp.net but I got the random tag id instead.

I'm expecting this data tag ID to be returned in my ajax request

Tag UID: 0B A5 56 D3

Expectation result

but I've got a random ID Tag instead

D3 Tag UID: 0B A5 56 D

3 Tag UID: 0B A5 56

random 1,

random 2,

Here is my code

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO.Ports;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Mvc;

public delegate void displayToView(String tagID);

namespace read_rfid_example.Controllers
{
    public class HomeController : Controller
    {
        SerialPort mySerialPort = new SerialPort("COM3");
        // GET: Home
        public ActionResult Index()
        {


            return View();
        }

        List<string> mlist = new List<string>();
        private void DataReceivedHandler(
                         object sender,
                         SerialDataReceivedEventArgs e)
        {
            SerialPort sp = (SerialPort)sender;
            string indata = sp.ReadExisting();

            displayToView display = new displayToView(pageReload);
            display.Invoke(indata);

        }
        string result = "";

        [HttpGet]
        public JsonResult start()
        {

            mySerialPort.BaudRate = 9600;
            mySerialPort.Parity = Parity.None;
            mySerialPort.StopBits = StopBits.One;
            mySerialPort.DataBits = 8;
            mySerialPort.Handshake = Handshake.None;
            mySerialPort.RtsEnable = true;
            mySerialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);

            try
            {
                mySerialPort.Open();
            }
            catch
            {

            }

            while(mySerialPort.IsOpen)
            {
                Thread.Sleep(100);
            }


            return Json(result, JsonRequestBehavior.AllowGet);
        }
        string[] str = new string[10];
        int count = 0;
        public void pageReload(String text)
        {

                mlist.Add(text);
                count++;
                str[mlist.Count] = mlist[mlist.Count - 1];

                if (count == 5)
                {
                result = string.Join("", str);
                    mySerialPort.Close();
                }




        }
    }
}

How to return the correct TAG ID? Please help

0 Answers