jvwlong
29th June 2012, 20:28
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
#include <QtCore/QCoreApplication>
#include <3rdparty/qextserialport/src/qextserialport.h>
#include <iostream>
#include <qiodevice.h>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, 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;
res = port->open(QIODevice::ReadWrite | QIODevice::Unbuffered);
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
#include <QtCore/QCoreApplication>
#include <3rdparty/qextserialport/src/qextserialport.h>
#include <iostream>
#include <qiodevice.h>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, 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;
res = port->open(QIODevice::ReadWrite | QIODevice::Unbuffered);
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