Need help setting up a serial port connection
Hello, I am trying to wrtie a program in Ubuntu where, throught the console, I can read and write a serial port. So I have started using the qextserialport library. I found code online and tried to emulate it to make a simple test to see if I can get the program to merely connect to the serial port. But alas my program does not seem to be connecting. And I am at a loss for why it won't open the port. Here is my code
Code:
#include <QtCore/QCoreApplication>
#include <3rdparty/qextserialport/src/qextserialport.h>
#include <iostream>
#include <qiodevice.h>
using namespace std;
int main(int argc, char *argv[])
{
const char data[]= "e";
QextSerialPort * port = new QextSerialPort("/dev/ttyUSB0");
port->setBaudRate(BAUD115200);
port->setFlowControl(FLOW_OFF);
port->setParity(PAR_NONE);
port->setDataBits(DATA_8);
port->setStopBits(STOP_1);
port->setTimeout(10);
bool res = false;
if(res)
{
cout << "Opened" << endl;
char i = port->write(data);
}
else
{
cout << "Failed to connect" << endl;
}
return a.exec();
}
The console that is opened always displays "Failed to connect"
Can anyone see any very obvious erros?
Thanks
-Jvwlong
Re: Need help setting up a serial port connection
Do You have rigths to use /dev/ttyUSB0 ?
Re: Need help setting up a serial port connection
I believe I do? How would I check if I have permission or not?
Re: Need help setting up a serial port connection
Quote:
Originally Posted by
jvwlong
I believe I do? How would I check if I have permission or not?
From command line :
ls -l /dev/ttyUSB0
and watch at screen.
Re: Need help setting up a serial port connection
This is the output from that command
"crw-rw---- 1 root dialout 188, 0 Jul 2 09:30 /dev/ttyUSB0"
Re: Need help setting up a serial port connection
Solved. I just needed to be added to the dialout group.