Solved How I could send AT command and Key character to QserialPort?
-
Hi everyone! i'am Vu( VietNammese!) i have a project with moden 3G-Module GSM! and i wan't to send AT command to ComPort( enviroment WinDown8), i have a example "Terminal" in QT example( QT Creator 5.7) this link about project: http://doc.qt.io/qt-5/qtserialport-terminal-example.html . And to day, i want send AT command auto, i don't much push the "Key enter" when i over the command! one a code in mainwindown.cpp ( line 156):
void MainWindow::writeData(const QByteArray &data) { serial->write(data); }
I much press the key Enter when i over the one command! I don't know how to send the Key chacracter Ctrl+Z and character " Enter". same like: "serial->write("\n") or "serial->write('10')... Thanks for read!
-
Hi @Dang-Vu
Not sure i understand what do you want, but if you want to send command automatically without press any key you can use QTimer,
Take a look at QTimer doc:
http://doc.qt.io/qt-5/qtimer.html#details
you can use for example:
QTimer *timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(writeData())); timer->start(1000);
Here you send AT command every seconds,
Hope this can help you,
-
Hello Dang-Vu and welcome,
I'm afraid I don't really understand your question/problem,
but to catch for example the "Enter-Key" beeing pressed in your programm,
you can reimplement the functionkeyPressEvent
:protected: void keyPressEvent(QKeyEvent *ev){ if (ev->type() == Qt::Key_Return || ev->type() == Qt::Key_Enter){ //Do Stuff } }
-
@mostefa Firt of all, Thanks for you reply! about "auto", which mean i want
serial->write("AT"); serial->waitForBytesWritten(1000); serial->waitForReadyRead(1000); serial->write("AT+CMGW=1"); serial->waitForBytesWritten(1000); serial->waitForReadyRead(1000);
in here, i want to send a Key Enter and keystrokes Ctrl+Z to ComPort,.... serial->write("QTKEY::Enter"); because when i over every command, i must the press Enter to send AT to serial! examp: AT Enter
AT+CMGW=1 Enter -
@J.Hilk said in How I could send AT command and Key character to QserialPort?:
he "Enter-Key" beeing pressed in your programm,
you can reimplement the function keyPressEvent:
protected:
void keyPressEvent(QKeyEvent *ev){
if (ev->type() == Qt::Key_Return || ev->type() == Qt::Key_Enter){
//Do Stuffyou stand me! ecxactly, i want send the Qt::Key_Enter to COM16. Now, i send the command serial->write(data); you can see here link: http://doc.qt.io/qt-5/qtserialport-terminal-example.html ......when i write the AT command in Qplantext( black Desktop in center Widget) i must press the Enter to complete! example: AT Enter
Now, i want to send the Enter key by code: serial->write("Enter Key" ); Thanks for your reply -
in c++ the CTRL+Z is '\x1A' character.
//your code here char ctr_z = '\x1A';