opening of serial port
-
how to open the serial port outside Qt?
I have written my code in qt, it is opening but whenver I am writing or reading in that port its showing device not open.
Is there any solution??
I am using MOXA card for serial communication. -
@Nimika "it is opening but whenver I am writing or reading in that port its showing device not open" - are you sure you opened the port? Did you check it like this:
qDebug() << serial.open(QIODevice::ReadWrite);
@jsulm
i just checked it and it is showing false.
I wrote this program.#include <QCoreApplication> #include <QSerialPort> #include <QDebug> QSerialPort serial; int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); serial.setPortName("ttyM"); serial.setBaudRate(QSerialPort::Baud115200); serial.setDataBits(QSerialPort::Data8); serial.setStopBits(QSerialPort::OneStop); serial.setParity(QSerialPort::NoParity); serial.setFlowControl(QSerialPort::NoFlowControl); serial.open(QIODevice::ReadWrite); qDebug() << "port connected"; qDebug() << serial.open(QIODevice::ReadWrite); serial.write("hello"); QByteArray bb = serial.readAll(); qDebug() << bb ; serial.close(); return a.exec(); }
-
@Nimika
That's wrong:serial.open(QIODevice::ReadWrite); qDebug() << "port connected"; qDebug() << serial.open(QIODevice::ReadWrite);
do it like this (do not call open twice!):
qDebug() << "port connected"; qDebug() << serial.open(QIODevice::ReadWrite);
-
@Nimika
Hi are you 100% sure about portname ?
serial.setPortName("ttyM");
I would expect a number ttyM0 -
@Nimika
Ok. Just checking.Did you try with minicom or any other serial programs if it will open it ?
-
@Nimika If it still not able to open the connection then check all the connection parameters you're specifying.
-
-
@Nimika "made on Monday" :-)
Usually people are not fully operable on Monday after weekend and do more mistakes and produce more broken products :-) -
Hi,
Looks like you're on linux, wouldn't that be
/dev/ttyM0
?One other thing: do you have the rights to access the serial port ?