Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]QSerialPort - send command AT
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]QSerialPort - send command AT

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 4.2k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    bkerdev
    wrote on 2 Oct 2013, 20:02 last edited by
    #1

    Hello everyone.
    I would like to ask you how to send AT command to a 3G modem (HUAWEI E153 Mobile Broadband).
    I can open the port for reading and writing.
    But when I send an AT command he answers me. But this is not the answer I expected.

    Currently I use
    Qt 5.1.0
    Qt Creator 2.7.2
    Mac OS X 10.7.5

    My source
    @
    // Test de dialogue avec le port
    QSerialPort myPort;
    myPort.setPortName("HUAWEIMobile-Modem");

    QString str = "AT";
    str.append(QChar(10));
    
    if(myPort.open(QIODevice::ReadWrite)){
        qDebug() << "Port Open...";
    
        //Default configuration
    

    // qDebug() << "Baud rate:" << myPort.baudRate();
    // qDebug() << "Data bits:" << myPort.dataBits();
    // qDebug() << "Stop bits:" << myPort.stopBits();
    // qDebug() << "Parity:" << myPort.parity();
    // qDebug() << "Flow control:" << myPort.flowControl();
    // qDebug() << "Read buffer size:" << myPort.readBufferSize();

        //Configuration du port
        myPort.setBaudRate(460800);
        myPort.setParity(QSerialPort::NoParity);
        myPort.setFlowControl(QSerialPort::NoFlowControl);
        myPort.setDataBits(QSerialPort::Data8);
        myPort.setStopBits(QSerialPort::OneStop);
    
        //Send command
        if(myPort.isWritable()){
            qDebug() <<"Writting...";
            myPort.write(str.toLocal8Bit());
            qDebug() << "End Writting.." << endl;
        }else
            qDebug() << myPort.errorString();
    
        // Lecture du port
        if(myPort.isReadable()) {
            qDebug() <<"Reading...";
            if(myPort.waitForReadyRead(60)) {
                QString out;
                qDebug() << out.fromLocal8Bit(myPort.readAll());
            } else {
                qDebug() <<"ERROR : " << myPort.errorString();
            }
        }else
            qDebug() << myPort.errorString();
    
        myPort.close();
    }else
        qDebug() << myPort.errorString();
    @
    

    My Output
    @Port Open...
    Writting...
    End Writting...
    Reading...
    "AT
    "@

    Normal Output
    @Port Open...
    Writting...
    End Writting...
    Reading...
    "OK"@

    Boris Bker

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kuzulis
      Qt Champions 2020
      wrote on 3 Oct 2013, 07:28 last edited by
      #2

      Hi.

      You can test the "AT" commands with use an Terminal example application (please look in QtSerialPort examples).

      Regarding to your problem: you shall send to the modem the strings that terminated by symbols of new line and so on, like "AT\n", "AT\n\r" and so on.

      PS: It is not QtSerialPort problem!

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bkerdev
        wrote on 3 Oct 2013, 21:36 last edited by
        #3

        I look at the example code from the terminal and it should send the data character by character to the port. And the end I add
        @QChar (13)@

        to validate the information.

        Boris Bker

        1 Reply Last reply
        0

        1/3

        2 Oct 2013, 20:02

        • Login

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