當我執行我的代碼時,它的權重變化時正常工作。但問題是我的文本框顯示01B等。請大家幫我得到了什麼錯在code.i希望它在人類可讀的格式INT像0546等等我是初學者,網絡編程。我開始連接體重秤並在我的文本框中獲得刻度數字
if (InvokeRequired) //<-- Makes sure the function is invoked to work properly in the UI-Thread
BeginInvoke(new Closure(() => { SerialPortOnDataReceived(sender, serialDataReceivedEventArgs); })); //<-- Function invokes itself
else
{
while (_serialPort.BytesToRead > 0) //<-- repeats until the In-Buffer is empty
{
int dataLength = _serialPort.BytesToRead;
byte[] data = new byte[dataLength];
int nbrDataRead = _serialPort.Read(data, 0, dataLength);
if (nbrDataRead == 0)
return;
string str = System.Text.Encoding.UTF8.GetString(data);
textBox1.Text = str.ToString();
}
}
04C,03N,03D,04F,這是什麼,十六進制?因爲是你的緩衝區的真實字符串值 – Ferus7
003是十六進制值:/ – Trump
你需要檢查你需要哪種格式並轉換值,你不要告訴我們你需要的格式類型 – Ferus7