[SOLVED]QSerialPort - send command AT



  • 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"@



  • 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!



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.