Problem with serial port readline()

I am trying to read serial data into c++

I used an online tutorial authored by kle8309 (on YouTube) that worked nicely for sending serial data but it will not receive serial data.

I have an external micro-controller sending serial data to the computer through a serial port that i established through the USB port. When I use a terminal program (terraterm), it receives the data just fine. My C++ program though will not receive the data, it time out after the timeout that i set for it (500ms).

My external hardware is sending single byte data one byte after the next starting at "A" and going to "Z" and then looping at 9600 baud.

I tried to research what could be wrong and found this statement on MS website:

""""""
Because the SerialPort class buffers data, and the stream contained in the BaseStream property does not, the two might conflict about how many bytes are available to read. The BytesToRead property can indicate that there are bytes to read, but these bytes might not be accessible to the stream contained in the BaseStream property because they have been buffered to the SerialPort class.

"""""""

I think that this statement is related to my problem but I think it was written by a lawyer :)

Here is the code I am using to read in the data

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";


}


Any ideas on what I am doing wrong? For some reason, readline is not thinking that there is any data available from the serial port...

Thank you
Topic archived. No new replies allowed.