-1
我正在嘗試讀取和寫入串行端口,似乎我無法清除緩衝區。 我試過DiscardIn/Out方法無濟於事。從串口發送的數據已經被應該被清除的緩衝區抵銷。從串行端口讀取時堆棧溢出
public static SerialPort serialPort;
public static StringBuilder sendData { get { return sendData; } set { sendData = value;if (sendData.Equals("q")) quitEvent(); } }
static void Main(string[] args)
{
del ex = new del(StopThread);
serialPort = new SerialPort();
serialPort.PortName = "COM3";
serialPort.BaudRate = 9600;
serialPort.ReadTimeout = 2000;
_continue = true;
serialPort.Open();
serialPort.DiscardInBuffer();
serialPort.DiscardOutBuffer();
Thread readthread = new Thread(ReadFromSerial);
Thread writethread = new Thread(WriteToSerial);
readthread.Start();
writethread.Start();
readthread.Join();
writethread.Join();
serialPort.Close();
Console.ReadLine();
}
我的錯誤我糾正了autoproperty.Still事件沒有觸發。我的意思是我認爲stringbuilder獲取設置與他從串口收到的,但如果我按「q」它不會添加到收到的一行。 –