C# 串口读取并转换字符串

 public string ReadString()
        {
            ASCIIEncoding ascii = new ASCIIEncoding();
            byte[] readBuffer = new byte[serialPort.BytesToRead];
            serialPort.Read(readBuffer, 0, readBuffer.Length);

            if (readBuffer.Length>0)
            {
                string result  = ascii.GetString(readBuffer);
                Console.WriteLine(DateTime.Now);
                Console.WriteLine(result);
                return result;
            }
            return "";
        }
原文地址:https://www.cnblogs.com/jxl123456/p/15508465.html