[SOLVED] Connecting arduino (Galileo) failed with QSerialPort
-
I have tried to connect my Intel Galileo with QSerialPort, but can't even establish a connection.
The error message (errorString() ) turned out to be "No Such File or Directory" on my mac, and "Resource Temporarily Unavailable" on a parallel desktops VM running Xubuntu 13.10.
I have attempted to use pySerial and it worked on both environment, it also worked on arduino playground with serial monitor
Any idea?
Here is the arduino program.
@int led = 13;
char incomingByte;void setup() {
// put your setup code here, to run once:
pinMode(led, OUTPUT);
Serial.begin(9600);
}void loop() {
// put your main code here, to run repeatedly:
if (Serial.available()) {
incomingByte = Serial.read();
Serial.print("read : ");
Serial.println(incomingByte);
if(incomingByte == 'a') {
digitalWrite(led, HIGH);
}
else {
digitalWrite(led, LOW);
}
}
}@and the qt program:
@#include <QCoreApplication>
#include <QtSerialPort/QSerialPort>
#include <QtSerialPort/QSerialPortInfo>
#include <QTextStream>int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QTextStream out(stdout);
out << "Hello World!" << endl;
QSerialPort * serial = new QSerialPort("ttyACM0");if(serial->open(QIODevice::ReadWrite | QIODevice::Unbuffered)) { // can't open and prompt "Resource Unavailable" serial->setBaudRate(QSerialPort::Baud9600); serial->write("a"); serial->close(); } else { out << serial->errorString() << endl; } a.exit(); return a.exec();
}@
-
I think you can try something like this:
@
QSerialPort * serial = new QSerialPort(“/dev/ttyACM0”);
if(serial->open(QIODevice::ReadWrite))
{
//setup your serialport params - baudrate, databits, parity, flowcontrol, stopbits, dataerrorpolicy
//do something there whatever you want - send "a" for example
}
else
{
out << serial->errorString() << endl;
}
@ -
[quote author="MrMNight" date="1394527326"]I think you can try something like this:
[/quote]Thanks for your reply, but it seems that the error occurs when it goes to
@serial->open()@
and then, jumps to
@serial->errorString()@
and I also tried to set databits\parity\etc. but it still doesn't work.
I wonder if it need some extra setting.
-
try run this
@
for (QSerialPortInfo port : QSerialPortInfo::availablePorts())
{
qDebug() << port.portName();
}
@Does this list contains "ttyACM0"?
-
[quote author="MrMNight" date="1394533009"]try run this
@
for (QSerialPortInfo port : QSerialPortInfo::availablePorts())
{
qDebug() << port.portName();
}
@Does this list contains "ttyACM0"?[/quote]
Yes. It can be found by QSerialPortInfo::availablePorts() on both OS X(cu.modemxxxxx) and Xubuntu(ttyACM0).
-
Do you have enough permissions to read and write to your ttyACM0?
I don't know how to perform this on Mac, but in Xubuntu you can add your user to dialout group, simply write in console (terminal)
@
sudo adduser your_user_name dialout
@and try to run again your code.
-
[quote author="MrMNight" date="1394535113"]Do you have enough permissions to read and write to your ttyACM0?
I don't know how to perform this on Mac, but in Xubuntu you can add your user to dialout group, simply write in console (terminal)
@
sudo adduser your_user_name dialout
@and try to run again your code.[/quote]
Thanks for your help! I solved this by removing
@QIODevice::Unbuffered@
It seems that ardunio doesn't support such openmode. -
- QIODevice::Unbuffered does not supported by QtSerialPort
- After write() you should call waitForBytesWritten(), because otherwise nothing to be write.
-
You are welcome, in "documentation":http://qt-project.org/doc/qt-5.1/qtserialport/qserialport.html#open there are warning "The mode has to be QIODevice::ReadOnly, QIODevice::WriteOnly, or QIODevice::ReadWrite. Other modes are unsupported."
-
Hi edward_zhu,
Can you share the code for connecting to USB(/dev/ttyACM0) in QT here?
I need to connect to the device from Linux QT.Please consider this as High Priority.I will be waiting for the code.
Regards,
Kripa -
@kripashree said in [SOLVED] Connecting arduino (Galileo) failed with QSerialPort:
Please consider this as High Priority.I will be waiting for the code.
Please don't be so demanding!
This is user forum where people help for free.
Nobody here is obliged to consider anything high priority or deliver code!And when asking you should provide more information.
What is the device you want to connect to? -
Hi @kripashree: edward_zhu was last only 5 years ago, I doubt he will see your request. And even if he did, he might not even have it anymore.
So please answer the questions @jsulm gave you, and we will see if we can help you.
Regards