Unsolved Completion notification after completion of write the data in file through UART
-
Hi,
How to include the completion notification after completion of write the data in file through UART (serially)?
I want to show the completion notification in my application. I am storing the data in a file through UART(serially).
But, I don't know that how can I include that tab or notification my application?
The application, i am making for windows. The platform is Qt creator.Thanks
-
@Mohit-Tripathi Please show the code you got so far.
-
Hi,
I am trying to implement this in terminal application. The code, i have attached is:
void SettingsDialog::on_pushButton_clicked() { const QStringList list = m_ui->serialPortInfoListBox->itemData(mohit).toStringList(); qDebug()<<list; QList<QString> List; List = list.mid(0,1); qDebug()<<"COM:"<<List; foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts()){ qDebug() << "Name :" << info.portName(); QString List1 = info.portName(); qDebug() <<List1; serial->setPortName(List1); } //qDebug()<< QPair<QString, QString>( serial->portName(), tr( "%1: %2" ).arg( serial->portName(), serial->description() ) ); //serial->setPortName(List); serial->open(QSerialPort::ReadWrite); serial->setBaudRate(QSerialPort::Baud19200); serial->setDataBits(QSerialPort::Data8); serial->setParity(QSerialPort::NoParity); serial->setStopBits(QSerialPort::OneStop); serial->setFlowControl(QSerialPort::NoFlowControl); connect(serial,&QSerialPort::readyRead,this,&SettingsDialog::serialReceived); static const char mydata[] ={'M','N'}; QByteArray sendPacket = QByteArray::fromRawData(mydata, sizeof(mydata)); // QByteArray sendPacket("MN"); // serial->write(sendPacket); sendPacket.resize(2); if(serial->isWritable()) { serial->write(sendPacket.toStdString().c_str(), sendPacket.size()); serial->flush(); serial->waitForBytesWritten(100); } else { qDebug()<<"write to serial"; } }
void SettingsDialog::serialReceived() { /*int data1 =0; char *dataBuffer; int size = arduino->bytesAvailable(); dataBuffer = new char[size+1]; data1 = arduino->read(dataBuffer,size); dataBuffer[data1]='\0'; //delete dataBuffer;*/ QStringList buffer_split = serialBuffer.split(","); if(buffer_split.length() < 3){ serialData = serial->readAll(); serialBuffer = serialBuffer + QString::fromStdString(serialData.toStdString()); serialData.clear(); }else{ serialBuffer = ""; qDebug() << buffer_split << "\n"; // Dialog::updatelcd1(buffer_split[0]); qDebug()<<"No reading"; } QFile logFile("Data.txt"); if (!logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) qFatal("Can't open the log file: %s", logFile.errorString().toLocal8Bit().constData()); QTextStream log(&logFile); logFile.setObjectName("Log File"); log << serialBuffer; log.flush(); // QFile logFile("Data.txt"); // logFile.open(QIODevice::ReadWrite); QTextStream in (&logFile); const QString content = in.readAll(); if(!content.contains("+++++++++++++++++++++++++++++++++++++++++++")) { qDebug()<<"completed\n"; } logFile.close(); }
-
@Mohit-Tripathi said in Completion notification after completion of write the data in file through UART:
QFile logFile("Data.txt"); if (!logFile.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) qFatal("Can't open the log file: %s", logFile.errorString().toLocal8Bit().constData()); QTextStream log(&logFile); logFile.setObjectName("Log File"); log << serialBuffer; log.flush();
// QFile logFile("Data.txt");
// logFile.open(QIODevice::ReadWrite);
QTextStream in (&logFile);
const QString content = in.readAll();
if(!content.contains("+++++++++++++++++++++++++++++++++++++++++++"))
{
qDebug()<<"completed\n";
}
logFile.close();Can you explain what this code fragment is supposed to do?
-
Hi,
This code fragment is about, to create the file and store the data in "Data.txt" file which we are getting through UART. I can say that this is like log file.
Thanks
-
Yeah, but what is this part meant to be:
// QFile logFile("Data.txt");
// logFile.open(QIODevice::ReadWrite);
QTextStream in (&logFile);
const QString content = in.readAll();
if(!content.contains("+++++++++++++++++++++++++++++++++++++++++++"))
{
qDebug()<<"completed\n";
}
logFile.close();?
-
Yeah,
I have created the string in MCU "+++++++++++++++++++++++++++++++++++++++++++". When, I get this string in my file through UART, I get to know that the data has been pushed or not. This is basically like notification. Then, I am printing "completed", if the data has been pushed.
You can see that I am taking the data from "Data.txt" file only.Thanks
-
So you get "++++++++++++++++++++" when the data is completely send? Because the condition implies the opposite (!contains()):
if(!content.contains("+++++++++++++++++++++++++++++++++++++++++++"))
But I can only advice you to not read and write the file alternating; that will destroy performance completely.
Back to your question: Why not simply emit a signal once the end condition is satisfied?
You already have the data in RAM, no need to write it in a file just to read it back afterwards for checking.
-
Actually, I have data in SD card which is attached with MCU. I am taking those data through UART. I think, there is no way to take the data except UART. So basically, I want to store the SD card data after clicking on to the tab in my desktop application.
"Why not simply emit a signal once the end condition is satisfied?"
How can I do this? Can you please tell me?Thanks
-
@Mohit-Tripathi said in Completion notification after completion of write the data in file through UART:
How can I do this? Can you please tell me?