Qextserialport can't open port
-
Hi, I'm using qextserialport with Qt 4.8 on Windows XP in Qt Creator. I almost only need to write to the serial port, sending various commands like "A1", "D5" and the only thing I need to read is "Ready" when I send the "?" command.
I'm using serial ports connected throught an usb cable. The qextserialport enumerator exemple runs fine, but I can't connect to them. Here's my code, it's pretty simple :
@MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);QList<QextPortInfo> ports = QextSerialEnumerator::getPorts(); ui->plainTextEdit->setPlainText( ui->plainTextEdit->toPlainText() + "List of " + ports.size() + " ports:\n" ); for (int i = 0; i < ports.size(); i++) { ui->plainTextEdit->setPlainText( ui->plainTextEdit->toPlainText() + ports.at(i).portName.toLocal8Bit().constData() + "\n" ); ui->plainTextEdit->setPlainText( ui->plainTextEdit->toPlainText() + ports.at(i).friendName.toLocal8Bit().constData() + "\n" ); ui->plainTextEdit->setPlainText( ui->plainTextEdit->toPlainText() + ports.at(i).physName.toLocal8Bit().constData() + "\n" ); ui->plainTextEdit->setPlainText( ui->plainTextEdit->toPlainText() + ports.at(i).enumName.toLocal8Bit().constData() + "\n\n" ); } port = new QextSerialPort( "COM12" ); port->setBaudRate(BAUD115200); port->setStopBits(STOP_1); port->setDataBits(DATA_8); port->setParity(PAR_NONE); port->setFlowControl(FLOW_OFF); // if connection is successful if( port->open( QIODevice::ReadWrite ) ) ui->plainTextEdit->setPlainText( ui->plainTextEdit->toPlainText() + "Connected." + "\n" ); else ui->plainTextEdit->setPlainText( ui->plainTextEdit->toPlainText() + "Failed to connect." + "\n" );
}
MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::on_pushButton_clicked()
{
if( ui->lineEdit->text().length() > 0 )
{
QByteArray ba = ui->lineEdit->text().toAscii();
port->write( ba );
ui->plainTextEdit->setPlainText( ui->plainTextEdit->toPlainText() + ui->lineEdit->text() + "\n" );
ui->lineEdit->clear();
ui->lineEdit->setFocus();
}
}@The thing is, in Hyperterminal I have no problem to connect to my port (COM12)...
Anyone have an idea of what the problem might be ?
-
bq. Anyone have an idea of what the problem might be ?
Elementary - to use another library http://gitorious.org/qserialdevice/qserialdevice/trees/2.0
Reason "this":http://developer.qt.nokia.com/forums/viewreply/67246/ -
IIRC I ran into a similar issue before... I think it only COM1 to COM4 (or was it COM9?) work, to address the others you need to use a different syntax to address them. You need to use e.g. "\.\COM56" to address those with higher numbers.
-
People, stop raping the corpse (qextserialport),
let's develop Qt addon QtSerialPort (formerly QSerialDevice 2.0). :)Also, here is a summary http://qt-apps.org/content/show.php?content=112039
-
Thanks for the replies.
@Tobias You might be right, because earlier when I was using another piece of hardware, the COM port was COM5 and it worked. Now that it's COM12 it doesn't work anymore... And I tried "\.\COM12" without success :(
@kuzulis I'm looking into that, but of course I can't get it to build -_-.
-
Did you escape the backslashes properly?
-
@kuzulis I finally got it to build yesterday, but still have a problem to link it to a project (but that's got nothing to do with the lib, more with my lacking knowledge). If I could make a suggestion, it would be to specify in the readme that you need QtSource to build it... or at least the qwineventnotifier_p.h from QtSource.
@Tobias You're right I hadn't escaped them and now it works with "\\.\COM12" ! Thanks !
I have another problem with qextserialport compared to hyperterminal. My COM device is a little LCD display powered through the usb connection. With Hyperterminal, when the command "?;" is sent, the display is turned on and should reply "Ready". However when opening the port and sending the "?;" command, the lcd display doesn't turn on. The only way I have to make it work so far is to first open it in hyperterminal and then use my app to send commands (which is defeating the purpose of my app -> replacing hyperterminal). Could there be any reasons I'm not seeing with the lib or is this too device specific ?
I'll still try with QSerialDevice to see how it goes.
-
bq. @kuzulis I finally got it to build yesterday, but still have a problem to link it to a project (but that’s got nothing to do with the lib, more with my lacking knowledge). If I could make a suggestion, it would be to specify in the readme that you need QtSource to build it… or at least the qwineventnotifier_p.h from QtSource.
Emm .. solution to this issue "here":http://developer.qt.nokia.com/forums/viewreply/70489/
In principle, this is not a problem. Yes, in the current version Qt4.x QWinEventNotifier class is private, so the library must be compiled as the link above (the same applies to the repository QextSerialPort on the google.code). But in the future Qt5 this class will be made public so that there should be no problems.
Therefore, for a transitional (temporary) version of QSerialDevice 2.0 I do not write this "feature" to the ReadMe. The reason is that QSerialDevice 2.0 is frozen, and the future development of Gerrit moved to a QtSerialPort.
Details, see example "this":http://qt-apps.org/content/show.php?content=112039.