Serial port 从COM端口读取数据
我有个小问题。 我尝试从COM端口读取数据,收到如下“坏”数据: 0 Fl-1 i 2 3. ? 4. M5. 6. 7. 8. 9 10 ? 11 12 13 d 14 D 15 打开端口的代码是:Serial port 从COM端口读取数据,serial-port,serial-communication,Serial Port,Serial Communication,我有个小问题。 我尝试从COM端口读取数据,收到如下“坏”数据: 0 Fl-1 i 2 3. ? 4. M5. 6. 7. 8. 9 10 ? 11 12 13 d 14 D 15 打开端口的代码是: _port = new SerialPort(Settings.Default.COM, 9600, Parity.None, 8, StopBits.One); _port.DataReceived += PortDataReceived; _port.Open(); 读取数据的代码是: pr
_port = new SerialPort(Settings.Default.COM, 9600, Parity.None, 8, StopBits.One);
_port.DataReceived += PortDataReceived;
_port.Open();
读取数据的代码是:
private void PortDataReceived(object sender, SerialDataReceivedEventArgs e)
{
string s = _port.ReadExisting();
_reportBuffer = _reportBuffer + s;
_counter++;
if (_counter == _messageLength)
{
//action
}
}
欢迎任何意见!
提前谢谢 如果您确定接收的数据与发送的数据不同,则需要仔细检查波特率、奇偶校验设置等 如果所有设置都正确,但仍无法获取发送的数据,请使用终端仿真器打开COM端口。如果你能在那里看到正确的数据,那么问题在于你的代码;如果你不能,问题就在别处