尝试使用 c++ 从 com 端口读取写入数据
Trying to read write data from com port using c++
我正在LM4F232H5QD板上工作,想读取com端口数据。每当我使用Tera术语或任何其他串行终端时,我都会从com端口获取数据。
但是当我使用此代码时,我收到超时异常错误。
// _serialPort
//
this->_serialPort->PortName = L"COM3";
this->_serialPort->ReadTimeout = 5000;
this->_serialPort->WriteTimeout = 5000;
.
.
.
.
// Read button --------------------------------------
//this will start the asyn for backgroundwork
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
// check if port is ready for reading
if(this->_serialPort->IsOpen){
// Reset the text in the result label.
this->textBox2->Text = String::Empty;
// this will read manually
try{
this->textBox2->Text=this->_serialPort->ReadLine();
// printf("trying to read data");
}
catch(TimeoutException^){
this->textBox2->Text="Timeout Exception";
}
// Disable the init button
// the asynchronous operation is done.
this->button2->Enabled = false;
this->ovalShape1->FillColor= Color::Green;
}
else
// give error warning
this->textBox2->Text="Port Not Opened";
}
但是当我短 Rx 和 Tx 引脚时,效果很好。
谁能告诉我如何解决这个问题?
如果您确定终端的数据看起来不错,则短路引脚将无济于事。您使用的唯一读取函数是 ReadLine()
,它将等到收到换行符。您确定您正确发送了换行符吗?另外,您应该检查_serialPort->NewLine
的实际值,也许它已设置为 CRLF,并且您只收到 LF。
相关文章:
- 如何在ros2中从rosbag2读取数据
- OpenCV 和从 OutputArrays 或 (Mat) 读取数据
- 使用C++从磁卡读卡器MT188读取数据
- HDF5 简单读取数据集失败
- 嵌套结构,从由空行分隔的文件中读取数据
- 不要从输入队列套接字读取数据
- 从文件中读取数据,操作员>>
- 如何从excel文件中读取数据并存储到变量中?
- C++:从文件中读取x y数据会产生无限循环吗
- 无法通过FT232RL读取数据
- 如何从QNetworkReply读取数据?
- C++ 逐行从文件(包含空格)读取数据
- 通过显示一行星号来创建条形图,该条形图将读取数据的输入文件
- 我们可以从 TXT 文件中读取数据并使用 C 和 C++ 将其保存到 SQL 数据库吗?
- 从多个 tcp 连接读取数据
- 从文本文件中读取数据并删除所有换行符空格,并在 C++ 控制台中显示
- Qt TCP服务器不从客户端读取数据
- 累积从 C++11 中的文件中读取数据的整数
- 从 txt 文件中读取数据的最简单方法
- 从 txt 文件中读取数据的 Getline