从体重秤设备通过 COM 到 USB 端口的不可读输入
本文关键字:USB 输入 COM | 更新日期: 2023-09-27 17:55:48
我有正常的代码从COM端口读取输入:
public static void Main()
{
SerialPort mySerialPort = new SerialPort("COM1");
mySerialPort.BaudRate = 9600;
mySerialPort.Parity = Parity.None;
mySerialPort.StopBits = StopBits.One;
mySerialPort.DataBits = 8;
mySerialPort.Handshake = Handshake.None;
mySerialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
mySerialPort.Open();
Console.WriteLine("Press any key to continue...");
Console.WriteLine();
Console.ReadKey();
mySerialPort.Close();
}
private static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string indata = sp.ReadExisting();
Debug.Print("Data Received:");
Debug.Print(indata);
}
并且这段代码可以正常工作,但是我在设备屏幕上收到了这样的
??BH003?00
和值003100KG
.
那么我如何格式化它或将其转换为可读性呢?
谢谢。
刚刚通过更改找到了答案
mySerialPort.DataBits = 8;
自
mySerialPort.DataBits = 7;
但我不确定为什么8
不起作用!!