private void ReadPort()
{
while (true)
{
if (sComm.IsOpen)
{
int count = sComm.BytesToRead;
if (count >=1)
{
byte[] readBuffer = new byte[count];
try
{
sComm.Read(readBuffer, 0, count);
if (count != 0)
//byteToHexStr(readBuffer);
//ThreadFunction(byteToHexStr(readBuffer, count));
Console.WriteLine(byteToHexStr(readBuffer));
}
catch (TimeoutException) { }
}
}
//TimeSpan waitTime = new TimeSpan(0, 0, 0, 0, 50);
Thread.Sleep(50);
}
}
C# 串口多线程接收
最新推荐文章于 2025-03-16 18:47:36 发布