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. :(