I turn to you because I have a problem reading the serial port. It turns out that my demo runs correctly on windows but I don't get any kind of response on linux. The device to which I connect is an antenna, to which it is necessary to send the command "log gpgga ontime 1" + the carriage return. My code is the following:
void MainWindow::on_btnObtener_clicked()
{
foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts())
{
qDebug() << "Puerto: " << info.portName();
qDebug() << "Nro. Serie: " << info.serialNumber();
qDebug() << "Fabricante: " << info.manufacturer();
qDebug() << "Descripcion: " << info.description();
if (info.portName().trimmed().compare("ttyUSB0") == 0)
{
auxserial = new QSerialPort(info);
auxserial->setBaudRate(QSerialPort::Baud9600);
connect(auxserial, &QSerialPort::readyRead, this, &MainWindow::readData);
if (auxserial->open(QIODevice::ReadWrite))
{
const QByteArray buffer = "log gprmc ontime 1";
auxserial->write(buffer);
auxserial->flush();
const QByteArray fin = "\r\n";
auxserial->write(fin);
auxserial->flush();
qInfo() << "Puerto Abierto correctamente";
break;
}
}
}
}
void MainWindow::readData()
{
while(auxserial->canReadLine())
qInfo() << auxserial->readLine();
}
Now, on windows it works correctly and even if I write the command wrong on purpose, it returns the response of the antenna with an error message emitted by the antenna. HOWEVER FROM LINUX, none of this happens... it tells me that the port is open correctly, but it doesn't respond either OK or ERROR. That could be happening?
EDIT: I just discovered that there are linux that have problems with the "CH341 USB Adapter"...in this case I'm using a Debian 9
Thank you
I already found the solution... obviously the problem was the CH340-341 adapter, since some linux distros work fine and others don't, due to a parity problem in the driver. The video in the link explains how to fix it. It worked for me, I hope others who have the same problem can solve it.
https://www.youtube.com/watch?v=3Yun14QscDs
Thank you