Multi serial port application
-
wrote on 11 Dec 2017, 07:25 last edited by
Hi @aha_1980 ,
I am working for single port now ,its not able to open the port here is my code by using send pushbutton and connect()void Dialog :: open_serialport()
{
QSerialPort serial;
QString portName = ui->port_comboBox->currentText();
qDebug() << "The portName is " << portName;
bool currentPortNameChanged = false;
QString currentPortName;
if(currentPortName != portName)
{
currentPortName = portName;
currentPortNameChanged = true;
}if(currentPortName.isEmpty()) { qDebug() << "No port name specified"; } if(currentPortNameChanged) { serial.close(); serial.setPortName(portName); qDebug() << "portName" << portName; if(!serial.open(QIODevice::ReadWrite)) { qDebug() << "can not able to open the serial port"; } }
}
its giving error i am passing from gui ,please help me out.... -
@veera said in multi serial port application:
void Dialog :: open_serialport()
{
QSerialPort serial; <<<< WRONG ! its local variablemake it a class member of Dialog
-
wrote on 11 Dec 2017, 07:59 last edited by
@mrjj ,
just now declared a QSerialPort as data members of the dialog class in dialog.h still also i am getting same error...here is the declaration of the QSerialPort
#ifndef DIALOG_H
#define DIALOG_H#include <QDialog> #include <stdio.h> #include <QtSerialPort/QSerialPort> namespace Ui { class Dialog; } class Dialog : public QDialog { Q_OBJECT public: QSerialPort serial;
-
Super
but what error ? -
wrote on 11 Dec 2017, 08:24 last edited by
can not able to open the serial port..what was the type its receiving whether its ttyS4 or /dev/ttyS4?
-
Hi
normally its ttyS4
for
serial->setPortName(p.name);Did you see the sample
http://doc.qt.io/qt-5/qtserialport-terminal-example.htmlIts available directly in Creator and you can use to test.
-
wrote on 11 Dec 2017, 09:41 last edited by
yes i have refer that example only.....
-
wrote on 11 Dec 2017, 09:42 last edited by
i have tried both the things not able to open the port .....
-
Lifetime Qt Championwrote on 11 Dec 2017, 09:47 last edited by mrjj 12 Nov 2017, 09:48
so are you sure PC has that port ?
if using a serial usb adapter, it has other name.
If you cannot open port using the Terminal sample then
something is wrong outside Qt. -
wrote on 11 Dec 2017, 09:51 last edited by
yes having two ports only ttyS4 and ttyS5 i am not using any usb to serial converter i am directly connecting with serial port only .....i have tried terminal example its giving the permission error means sudo permission .....
-
wrote on 11 Dec 2017, 09:54 last edited by
permission is denied error while opening the port in Terminal Sample...
-
-
wrote on 11 Dec 2017, 10:13 last edited by
Are you in dialout group?
-
wrote on 11 Dec 2017, 10:13 last edited by
i tried using this command on the qt project path also not able to open the serial ports.....
-
wrote on 11 Dec 2017, 10:31 last edited by
yes i am in dialout group....
-
wrote on 11 Dec 2017, 10:34 last edited by
crw-rw---- 1 root dialout 4, 68 Dec 11 13:22 /dev/ttyS4
-
wrote on 11 Dec 2017, 10:36 last edited by
@jsulm said in multi serial port application:
ls -lh /dev/ttyS4
crw-rw---- 1 root dialout 4, 68 Dec 11 13:22 /dev/ttyS4
-
wrote on 11 Dec 2017, 10:44 last edited by
Are you sure you really have 4 serial ports? Which kind of machine have you got?
In some case, with a beaglebone board for example, you have to enable the third and fourth serial port with a special kernel parameter. -
Hi
Often you have to add your user to the dialout group to be allowed to use itusermod -a -G dialout MY_USER_NAME
as @mrdebug asks/says
23/49