0

我正在尝试使用 C# 连续读取从 arduino 发送到串行端口的数据并将其显示在某处。最好的方法是什么?

4

2 回答 2

2

这在很大程度上取决于您的业务规则(我们没有),但总的来说,我发现尝试连续阅读充满了问题并导致不必要的复杂性。处理DataReceived事件通常会更好。

于 2012-10-31T16:19:58.770 回答
1

你可以试试SerialPort.ReadLine method

链接:http: //msdn.microsoft.com/en-us/library/system.io.ports.serialport

    var serialPort = new SerialPort();

    // Allow the user to set the appropriate properties.
    serialPort.PortName = ..;
    serialPort.BaudRate = ..;
    serialPort.Parity = ..;
    serialPort.DataBits = ..;
    serialPort.StopBits = ..;
    serialPort.Handshake = ..;

    string message = serialPort.ReadLine();
于 2012-10-31T16:18:54.343 回答