recieve continious data from serial port
I have a problem while reading data from microcontroller...my microcontroller sends char 'a' continiously(just to test)..and I want to receive the character in my ui application..(lineedit)...
Code:
QextSerialPort * port = new QextSerialPort("COM4", QextSerialPort::EventDriven);
port->setBaudRate(BAUD9600);
port->setFlowControl(FLOW_OFF);
port->setParity(PAR_NONE);
port->setDataBits(DATA_8);
port->setStopBits(STOP_1);
port->setTimeout(500);
port->setRts(true);
port->setDtr(true);
if(port->isReadable())
{
char buff[1024];
qint64 i=port->readLine(buff,1024);
buff[i]='\0';
if(i!=-1)
{
ui->lineEdit->setText(str);;
port->close();
}
}
else
qDebug("port not open");
this does not help me ............please help me/...
Re: recieve continious data from serial port
Quote:
this does not help me
^- this doesn't help me to help you.
Re: recieve continious data from serial port
Even if you get the read working, ask yourself what happens to your buffer if readLine returns -1. Specifically, what is buff[i] going to do? It can't be good.
Re: recieve continious data from serial port
Have you verified that your micro is even sending the data correctly using something like a terminal emulator?
After that, you have a possible buffer underrun, and you don't need the null character anyway, as the method you are calling adds it for you.
Last, you are running the serial port in event driven mode and then attempting to poll it. Doomed to failure.
Re: recieve continious data from serial port
Yes i have checked data from microcontroller .............but could not recieve in my ui application ....:(
please help me..
Re: recieve continious data from serial port
How do you know that "COM4" is the correct port?
Use the port enumeration static functions in QextSerialPort to extract the available ports, and be sure you are reading the port you micro is connected to.
Re: recieve continious data from serial port
Quote:
Originally Posted by
ready
Yes i have checked data from microcontroller .............but could not recieve in my ui application ....:(
please help me..
Use signals and slots, then the event loop will run.
Re: recieve continious data from serial port
Quote:
Use signals and slots, then the event loop will run.
can you please elaborate it...
Re: recieve continious data from serial port
Sure, http://doc.qt.nokia.com/4.7/signalsandslots.html
BTW, it seems like you are attempting to copy and paste chunks of code. This will not work, you have to understand the code first.
Re: recieve continious data from serial port
In addition to what was already said you are trying to read a line of data and a line is characterised by the fact that it ends with a newline character. Since your peer sends you only 'a' characters, you don't have a newline character and hence you don't have a line. readLine() probably will work and simply return all pending data but it's good to avoid bad habits.
Re: recieve continious data from serial port
finally my lineedit showed some character after I pressed the button .....but it read different character......for example If I send "b" from microcontroller......it reads as 'd',again after pressing the button it reads 'h' and again after pressing button it reads't'.....why this is happening so??
Re: recieve continious data from serial port
Do you send and receive at the same speed and all the other port settings?