PDA

View Full Version : QextSerialPort question



sidenelen
10th May 2012, 21:26
Hello, I'm trying to establish a communication between a microprocessor and my Ubuntu PC.

I'm using Qextserialport library. But some error occured I don't know why.

I tested the portname and it's like that attached "ttyACM0"



QextSerialPort *deneme = new QextSerialPort();
deneme->setPortName("/dev/ttyACM0");
deneme->setBaudRate(BAUD9600);
deneme->setParity(PAR_NONE);
deneme->setDataBits(DATA_8);
deneme->setStopBits(STOP_1);

if ( !(deneme->open(QIODevice::ReadWrite)) )
{
qDebug("error"); }
if(deneme->isOpen())
{
qDebug("opened");
deneme->close();
}


When I run it, It just waits and "error" occured. What I am missing you think?

Thanks in advance

norobro
10th May 2012, 23:53
Possibly a permissions problem?

sidenelen
11th May 2012, 00:57
Probably. How should i overcome it?

norobro
11th May 2012, 01:09
I use QextSerialPort on my Debian box to communicate with a weather station console. Had to add my user account to the dialout group.

$ ls -l /dev/ttyS0
crw-rw---T 1 root dialout 4, 64 May 10 18:01 /dev/ttyS0


sudo adduser user dialout

sidenelen
11th May 2012, 13:15
onur@onur-pc:~$ ls -l /dev/ttyACM0
crw-rw---- 1 root dialout 166, 0 2012-05-11 14:11 /dev/ttyACM0


and then i try to run

onur@onur-pc:~$ sudo adduser onur dialout


the output is


The user `onur' is already a member of `dialout'.

sorry for the such noob questions.

norobro
11th May 2012, 22:18
sorry for the such noob questions.No prob, this is the newbie forum after all.

Try your code without the "if" on the open statement:
. . .
deneme->open(QIODevice::ReadWrite)
if(deneme->isOpen())
{
. . .

Edit:

Obviously I'm stabbing in the dark with the above.

Did your microprocessor docs specify the port settings you are using? Here are the settings that I use:
port = new QextSerialPort("/dev/ttyS0");
port->setBaudRate(BAUD19200);
port->setFlowControl(FLOW_OFF);
port->setParity(PAR_NONE);
port->setDataBits(DATA_8);
port->setStopBits(STOP_2);
port->open(QIODevice::ReadWrite)

sidenelen
12th May 2012, 13:31
I've changed the code like that


QextSerialPort *deneme = new QextSerialPort();
deneme->open(QIODevice::ReadWrite);
deneme->setQueryMode(QextSerialPort::EventDriven);
deneme->setPortName("/dev/ttyACM0");
deneme->setBaudRate(BAUD9600);
deneme->setParity(PAR_NONE);
deneme->setDataBits(DATA_8);
deneme->setStopBits(STOP_1);

if (deneme->isOpen()) qDebug("connection established");
else qDebug("failed to connect");
if (deneme->bytesAvailable()>0) {
qDebug("byte=",deneme->bytesAvailable());
}
else
{
qDebug("theres nothing");
}
}

Now it always says "connection established", even if i write some wrong port name like "tty12334324".

But bytesAvailable() returns "-1" when i'm trying to learn how many bytes are available to read.

By the way, I'm sure some data coming from the microprocessor with parameters that i wrote. Cause i've try it with another desktop program which is reading data from the same microprocessor truly.

norobro
12th May 2012, 16:50
Do you not need to send data to your device to get a response?

Try something like this:

QString cmd("a command for your device");
deneme->write(cmd.toAscii(), cmd.length());
deneme->waitForReadyRead();
qDebug() << "Bytes availible:" << deneme->bytesAvailible() << "data:" << deneme->readAll();

sidenelen
13th May 2012, 17:29
i tried it, still the same :( dunno wheres the missing.

norobro
13th May 2012, 19:03
Sorry I haven't been any help. Sending LF to my device wakes it up and it responds with CRLF, then you can start sending commands.

You might try the QSerialDevice (https://gitorious.org/qserialdevice) library. The author is a member of this site: thread (http://www.qtcentre.org/threads/28581-QSerialDevice-v-0-2-0-released)

sidenelen
13th May 2012, 19:20
I don't know how but i finally got it! thank you so much for your patient help :)