[英]Read serialport and store it in a String Variable C#
我必須讀取串行端口並將該響應存儲在一個字符串變量中,該響應是一個六個字節的序列。我試圖通過連接響應將響應存儲在字符串變量中。 但是只有響應的最后一個字節被存儲。
int response = port.ReadByte();
string responseString = "";
responseString += response.ToString();
Console.WriteLine(responseString);
Port.ReadByte()
從 SerialPort 輸入緩沖區同步讀取一個字節。
所以你可能想使用:
Port.ReadExisting()
根據編碼,在 SerialPort 對象的流和輸入緩沖區中讀取所有立即可用的字節。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.