Serial port
-
QSerialPort works on all support platform so what is your exact problem with linux ?
Most probably you don't have the rights to access the serial port, do you ?
-
"This thread":http://qt-project.org/forums/viewthread/44793/ will guide you through my experiences when I added it to 4.6.3.
If you follow all the posts, you should be able to successfully add QtSerialPort to 4.8.4 .. even easier because you may not need all the changes that were needed for 4.6.3. -
thank u sir..now serial port is working , but am not able to read the hex data from serial port
-
hi sir,
int nreturn=0,len;
char buf[5];
QString str,s;QChar ch;
while (TRUE)
{nreturn = read(fd,&buf,1);
str =buf[i];
len = str.length();
qDebug () << "no of bytes:" << len;
for( i=0;i<len;i++)
{ch = str.at(i);
n+=ch.unicode();
s = QString::number(n,16);
}
qDebug () << "Data:" << s;}
Am able to display hex value, when data is only one byte and other problem is when continusly data is read only first byte is getting correct remaing am geting addition of the previous data . if i read 5 bytes of data am getting junk data .Please help me
-
use this
@QString a="a";
QByteArray BA1=a.toUtf8();
QByteArray BA2=BA1.toHex();
const char* chArr1=BA2.constData();
qDebug()<<QString::fromUtf8(chArr1);@ -
Is your fd the serialport?
Again, as asked before, why are you not using QSerialPort?
What is your target, the task you need to get done? -
Basic serial port usage as I have worked on is
@ serial=new QSerialPort(this);
serial->setPortName("/dev/ttyS0"); serial->setBaudRate(9600); serial->setDataBits(QSerialPort::Data8); serial->setParity(QSerialPort::NoParity); serial->setFlowControl(QSerialPort::NoFlowControl); serial->open(QIODevice::ReadWrite); serial->write("Hello World"); connect(serial,SIGNAL(readyRead()),this,SLOT(readSerialData()));@
-
.. and the readSerialData() ... (pseudo code)
@
void QTGUI_MainWindow::readSerialData()
{
while((iBytesAvailable = serial->bytesAvailable()))
{
QByteArray RawPortData = serial->read(iBytesAvailable);
...@
-
int main(int argc, char *argv[])
{QCoreApplication a(argc, argv);
fd = open(MODEMDEVICE,O_RDWR|O_NOCTTY);While(true)
{
Buffer.clear();
nreturn = read(fd,&chBuf,1);
if(nreturn > 0)
{
for(i=0;i<nreturn;i++)
{
Buffer.append(chBuf[i]);if(chBuf[0] == 0xc9) nReadIndex = 0;
pData[nReadIndex++] = chBuf[i];
qDebug() << "data" << Buffer.toHex();
}
if(chBuf[0] == 0xcf)
{if(nReadIndex >= 10)
//Display of Gui opreration //
nReadIndex = 0;
}
For this how can i use timers instead of while loop, where should i start timer , i tried but am geting segmentation problem.Please help me
-
Your issue seems not to be about the serial port. Please open a new thread for a new topic.
btw: You seem to be very reluctant in using QSerialPort.
-
k .
-
Hi sir,
How to flush the data in serial port without using qextserialport
Please help me sir...
-
hi sir...,
When i use Baud rate B115200...am getting segmentation fault ..in qt...How would i solve the problem..Please help me... -
hi sir...,
When i use Baud rate B115200...am getting segmentation fault ..in qt...How would i solve the problem..Please help me... -
Without any proper code, I can't.
-
Without any proper code, I can't.
-
#define BAUDRATE B9600
-
#define BAUDRATE B9600
-
That won't really help debugging but from the looks of it, you are using the linux platform API, so please ask this on a linux dedicated forum.
There's also this "how to":http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/x115.html that should give you some hints and this "stack overflow post":http://stackoverflow.com/questions/6947413/how-to-open-read-and-write-from-serial-port-in-c
-
That won't really help debugging but from the looks of it, you are using the linux platform API, so please ask this on a linux dedicated forum.
There's also this "how to":http://www.tldp.org/HOWTO/Serial-Programming-HOWTO/x115.html that should give you some hints and this "stack overflow post":http://stackoverflow.com/questions/6947413/how-to-open-read-and-write-from-serial-port-in-c