0

I have a RFID device it connects to pc via usb(serial port or com) and sends data how can I get name of the port it connected? and how can I get it's data?(it sends 16 bytes in hex format )

I wrote this code in c# but, it doesn't work!

var sp = new SerialPort(device_names.Last<string>(), 4800);

        try
        {

            sp.Open();

            string received = sp.ReadLine();

            while (received.CompareTo(null) == 0)
            {
                Console.WriteLine("nothing received yet!");
            }

            if (received.CompareTo(null)!=0)
            {
                Console.WriteLine("device connected to: " + device_names.Last<string>()+"reading "+ received);
            }

        }
        catch
        {
            Console.WriteLine("device NOT connected to: " + device_names.Last<string>());

        }

        finally
        {
            sp.Close();
        }

I want to detect this device connection and then wait for receiving data from it. it's the first time I'm doing it. I'm very confused now. :(

mahya sj
  • 1
  • 1

1 Answers1

0

you need to know when RFID device sends data. if your reading before data is sent then you won't get any data. and If you want to do the processing on the data received then use sp.read instead of sp.readLine because in read you need to specify no of bytes you want to read.

user1725030
  • 143
  • 1
  • 7