我有一个 RFID 设备,它通过 USB(串行端口或 com)连接到 pc 并发送数据如何获取它连接的端口的名称?我怎样才能得到它的数据?(它以十六进制格式发送 16 个字节)
我用 c# 编写了这段代码,但是它不起作用!
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();
}
我想检测这个设备连接,然后等待从它接收数据。这是我第一次这样做。我现在很困惑。:(