Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How I could send AT command and Key character to QserialPort?
Forum Updated to NodeBB v4.3 + New Features

How I could send AT command and Key character to QserialPort?

Scheduled Pinned Locked Moved Solved Mobile and Embedded
6 Posts 4 Posters 2.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dang Vu
    wrote on last edited by Dang Vu
    #1

    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!

    J.HilkJ 1 Reply Last reply
    0
    • M Offline
      M Offline
      mostefa
      wrote on last edited by
      #2

      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,

      D 1 Reply Last reply
      0
      • D Dang Vu

        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!

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @Dang-Vu

        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 function keyPressEvent:

        protected:
        void keyPressEvent(QKeyEvent *ev){
            if (ev->type() == Qt::Key_Return || ev->type() == Qt::Key_Enter){
                 //Do Stuff
            }
        }
        

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        D 1 Reply Last reply
        0
        • M mostefa

          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,

          D Offline
          D Offline
          Dang Vu
          wrote on last edited by
          #4

          @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

          1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            @Dang-Vu

            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 function keyPressEvent:

            protected:
            void keyPressEvent(QKeyEvent *ev){
                if (ev->type() == Qt::Key_Return || ev->type() == Qt::Key_Enter){
                     //Do Stuff
                }
            }
            
            D Offline
            D Offline
            Dang Vu
            wrote on last edited by
            #5

            @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 Stuff

            you 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

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              Zakaria Chahboun
              wrote on last edited by
              #6

              in c++ the CTRL+Z is '\x1A' character.

              //your code here
              char ctr_z = '\x1A';
              
              1 Reply Last reply
              2

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved