C# 串口多线程接收

       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# 串口多线程接收)