Question

I'm working in Qt creator c++ and linux os, and I'm trying to create program that reads and sends sms messages. Everything works fine, but when I try to read cmti signal that signals that new message is received it brakes and os sends me SIGBUS, bus error.

My code is simply:

port->setPortName(s);

bool status = port->open(QSerialPort::ReadWrite); 

if(status)
{
    port->setBaudRate(115200, QSerialPort::AllDirections);
    port->setDataBits(QSerialPort::Data8);
    port->setParity(QSerialPort::NoParity);

    QByteArray in;

    if(port->waitForReadyRead(300)) 
        {
            in = port->readAll();
            while (port->waitForReadyRead(64))
            {
                in += in->readAll();
            }
        }

    //...
}

When modem sends cmti and port gets that signal in port->watiForReadyRead() it gives me error and never gets to port->readAll(). Also, when this error occurs it changes ttyUSB port for modem.

My best guess is that modem blocks port so my app can read. In c# in widows I have solved this by setting read timeout on serial port, but I can't do this in qt.

Can anyone help with this???

Était-ce utile?

La solution

You must always explicitly enable all the different UR codes you want to listen to on a specific given serial interface. If you have several serial interfaces open and run AT+CNMI=2 on one of them you cannot assume that +CNMI: ... will occur on any other interfaces than the on that ran the AT+CNMI command. Assume nothing is remembered if you open, close and then reopen.

So, in your code above, add a call to write AT+CNMI with the mode you want, and then read and parse everything you get back from the moden until you get the OK final result code before continuing with the code expecting to receive +CNMI: ... UR codes. (BTW you should rather use readLine than readAll since AT command responses should always be handled line by line.)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top