-1
CLI/C++でシリアルデータを読み込もうとしています。私はビデオチュートリアルからVisual C++でシンプルなプログラムを持っていますhttps://sourceforge.net/projects/kle8309/files/CLI/C++シリアルポート - > ReadLine()
SerialPort->ReadLine()
関数を呼び出すと、Timeout Exception
が得られます。
private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
// check if port is ready for reading
if(this->serialPort1->IsOpen){
// Reset the text in the result label.
this->textBox1->Text = "it is open!";
// this will read manually
try{
this->textBox1->Text=this->serialPort1->ReadLine();
}
catch(TimeoutException^){
this->textBox1->Text="Timeout Exception";
}
// Disable the init button the asynchronous operation is done.
this->button1->Enabled = false;
}
else{
// give error warning
this->textBox1->Text="Port Not Opened";}
}
私は間違いをどこで知っていますか?
SerialPort :: WriteTimeoutプロパティを設定しないで*最初に動作させるようにしてください。だから、もう例外はありません。それはあなたのUIをハングアップさせるでしょう、あなたは今それを正しく行う方法を発見するためにはるかに良い確率を持っています。 DataReceivedイベントを実装し、Handshakeプロパティを正しく設定すること。 –