QSerialPort Issue:: reading an undesired write message.
-
Hello,
I didn't find anyone with the same issue, so I guess that I'm doing something wrong.
I'm creating a QSerialPort , named COMRPI, in a QObject ,named m_arm, that is within a QApplication, named ArmApp. It is created within the constructor of m_arm:
arm::arm():QObject() { COMRPI=new QSerialPort("COM7"); COMRPI->setBaudRate(115200); COMRPI->setDataBits(QSerialPort::Data8); COMRPI->setParity(QSerialPort::NoParity); COMRPI->setStopBits(QSerialPort::OneStop); COMRPI->setFlowControl(QSerialPort::NoFlowControl); if(!COMRPI->open(QSerialPort::ReadWrite)) { qDebug()<<"Error ocured while opening COMRPI:"<<COMRPI->errorString()<<"Crash expected, deleting arm content to prevent most of memory leak."; delete COMRPI; delete m_hand; } else { std::cout<<"COMRPI is supposed to be operational."<<std::endl; } }
After that, I'm running a function, member of ArmApp, named connectEverything:
void ArmApp::connectEverything() { QObject::connect(this->m_controlWindow->ui->Actualisethearm,&QPushButton::pressed,this,&ArmApp::actualisationOfTheArm); QObject::connect(this->m_arm->COMRPI, &QIODevice::readyRead, this->m_arm, &arm::SerialPortReceiving); QObject::connect(this->m_arm, &arm::readingCompleted, &arm::InterpretingIncommingData); }
The slot SerialPortReceiving is simply reading all that is present in the buffer and putting it in a string called m_buffe and InterpretingIncommingData, far from being complete, is just printing out m_buffer:
void arm::SerialPortReceiving() { std::string NewData(COMRPI->readAll()); m_buffer+=NewData; COMRPI->clear(QSerialPort::Input); emit readingCompleted(); } void arm::InterpretingIncommingData() { std::cout<<m_buffer<<std::endl; }
There is a widget with a push button, named actualisatethearm, emitting a signals that triggered the slot ActualisationOfTheArm, that is actually sending " EDFR/r" to the raspberry pi:
oid ArmApp::actualisationOfTheArm() { //code of the actualisation std::cout<<"The arm is actualy being actualisate."<<std::endl; m_arm->COMRPI->write("EDFR\r"); }
Knowing that (Good point):
-I'm able to receive the right message with the pi coming from the pc.
-I'm able to receive the right message with the pc from the pi.
-Everything, but the following issue, seems to work fine.Why is the message sent from the pc to the pi ( EDFR/r) triggered readyRead() signals, which is followed by the integration of a sent message that could compromised the received command?
The integrity of the code implying the serial port is there, but don't mind to ask if you think that something required to a good understanding of this problems is missing.
-
Why is the message sent from the pc to the pi ( EDFR/r) triggered readyRead() signals, which is followed by the integration of a sent message that could compromised the received command?
maybe the
pi
is set to echo mode as well, und sends back all received packages, a common debug option. -
@aha_1980 I'm expecting to read and write data with a serial port, but, for some reason, the data sent by my pc is also read by my pc, so the problems is that the data sent is somehow triggering the readyRead signals.
@J-Hilk I noticed that ,effectively, the echo wasn't turned off on the pi. For whatever reason, it completely broke my programs when I'm turning it of, so I'm going to install qt and try again on the pi before calling it a win.