Multi serial port application
-
here is my structure in dialog.h
enum portWindow
{
WINDOW_1
,WINDOW_2
,WINDOW_3
};struct Settings { FILE *fd; QString port_name; QString baudRate; QString dataBits; qint64 startbit; QString parity; QString StopBits; QString hwflowControl; QString swflowControl; bool logfileEnabled; QString SerialPort_Interval; enum portWindow serialPortWindow; }; Settings DevSettings;
and project files are
SOURCES +=
main.cpp
dialog.cpp
serialappparams.cppHEADERS +=
dialog.h
serialappparams.hFORMS +=
dialog.ui -
@veera said in multi serial port application:
okay thanks for the valuable reply i am sharing the code here for collecting all the parameters from gui storing into my structure for opening the serial ports .
I'm not sure if you need to store the data separately: you have it in the UI and you set them in the QSerialPort object. IMHO there's no need to cache them again... There is some caching in the Terminal example, but mostly because the data is transported from the settings dialog to the main window.
and how to set the mark and space parity ,i have to use the termios structure ?
-
@veera said in multi serial port application:
@aha_1980
How would you know the which port is sending the port information ,how i need to handle this problem????Sorry, but I don't understand your question.
As said, I would start creating ONE object (maybe a QPanel) configuring ONE serial port, sending data to ONE serial port and receiving data from ONE serial port. If you have this working, it's easy to have three of them so you can communicate with all serial ports.
-
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
-
@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 ? -
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.
-
yes i have refer that example only.....
-
i have tried both the things not able to open the port .....
-
mrjj Lifetime Qt Championreplied to veera 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. -
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 .....
-
permission is denied error while opening the port in Terminal Sample...
-
-
Are you in dialout group?
-
i tried using this command on the qt project path also not able to open the serial ports.....
-
yes i am in dialout group....
19/49