2014-12-11 3 views
0

저는 LM4F232H5QD 보드에서 작업 중이며 com 포트 데이터를 읽으려고합니다. Tera 용어 나 다른 직렬 터미널을 사용할 때마다 com 포트에서 데이터를 얻습니다.C++을 사용하여 COM 포트에서 쓰기 데이터를 읽으려고 시도했습니다.

하지만이 코드를 사용하면 code 타임 아웃 예외 오류가 발생합니다.

// _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 핀은 잘 작동합니다.

누구든지이 문제를 어떻게 해결할 수 있습니까?

+0

_ "하지만 짧은 Rx 및 Tx 핀은 잘 작동합니다."_ 실제로이 작업을 수행하는 방법을 보여줄 수 있습니까? –

답변

0

데이터가 단말기에서 잘 보이는 경우 핀을 짧게해도 도움이되지 않습니다. 사용하는 유일한 읽기 기능은 ReadLine()이며 NewLine을 수신 할 때까지 대기합니다. NewLine을 올바르게 보내시겠습니까? 또한 _serialPort->NewLine의 실제 값을 확인해야합니다. 아마도 CRLF로 설정되어 있고 LF 만 수신 중일 수 있습니다.

관련 문제