PDA

View Full Version : Modem communication example



iaguirre
3rd September 2009, 14:05
Could someone indicate me which classs should i use for it? And provide me a code example ussing it to communicate with a modem using AT commands?

I'm trying to send a SMS using a Siemens MC35 GSM modem attached to the
COM port. I'm able to send an SMS using the hyperterminal using the AT
commands.

Thanks

Sorry, the modem model is:

DIAMOND SupraExpress56e PRO

And the platform is windows.

Thanks

nix
3rd September 2009, 15:44
Hi,

Take a look to QextSerialPort at http://qextserialport.sourceforge.net/.
With that you should be able to send/receive data via a serial port. You have to configure the connexion (same parameters hypeterminal used) and then you can send AT commands, check for response from the modem...

iaguirre
4th September 2009, 11:44
Thank you for the suggested class.
I am using it, but I am having some problems. This is the code:

port = new QextSerialPort("COM1");
port->setBaudRate(BAUD9600);
port->setFlowControl(FLOW_XONXOFF);
port->setParity(PAR_NONE);
port->setDataBits(DATA_8);
if_error=port->open(QIODevice::ReadWrite);
if (if_error)
cout<<"port opened\n";
else
{
cout<<"Error opening the port";
return a.exec();
}


QString command ="AT\r\n"; //sample command - this returns OK
QByteArray byte;
byte.clear();
byte.append(command);
qDebug()<< byte;
error_num= port->write(byte);
cout<<"Number of bytes that were actually written: " << error_num <<"\n";
if_error=port->waitForBytesWritten (5000);
if (if_error)
cout<<"Data Sent\n";
{
cout<<"Error sending data: ";
port_error=port->lastError();
cout<< port_error <<"\n";
return a.exec();
}

waitForBytesWritten always returns me an Error 0

Please, any help?

Thanks

nix
4th September 2009, 13:18
First, try to use
tags please, your code will be so more readable.

Then I think you make a mistake with the pasted code, you would probably do this :
[CODE]
error_num= port->write(byte);
cout<<"Number of bytes that were actually written: " << error_num <<"\n";
if_error=port->waitForBytesWritten (5000);
if (if_error)
cout<<"Data Sent\n";
else
{
cout<<"Error sending data: ";
port_error=port->lastError();
cout<< port_error <<"\n";
return a.exec();
}

What string error do you have?

What is the result of the write(byte) call? If it is equal to your command length just call the waitForReadyRead(5000) in order to wait for the response "OK".

nix
4th September 2009, 14:41
I've just seen on this (good) forum readyFor*() functions are not implemented correctly for this device. http://www.qtcentre.org/forum/f-qt-programming-2/t-qextserialport-and-waitforreadyread-problem-9144.html

Maybe you have to do some polling?

Did you try the example in the package, it works fine for me (the last time I tried it). It is a very basic example but if you add a QTimer for polling responses from the modem you will have a "usable" terminal example.