I am using QextSerialPort
to access ports
#include <qstring.h>
#include <qdebug.h>
#include <QCoreApplication>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
QextSerialPort *port;
QString portName;
int counter=0;
//Navigate through ports untill you find huwawei USB dongle
while(counter<ports.size())
{
portName = ports[counter].portName;
QString productId= ports[counter].productID;
QString physicalName = ports[counter].physName;
QString vendorId = ports[counter].vendorID;
QString friendName = ports[counter].friendName;
string convertedPortName = portName.toLocal8Bit().constData();
string convertedProductId = productId.toLocal8Bit().constData();
string convertedPhysicalName = physicalName.toLocal8Bit().constData();
string convertedVendorId = vendorId.toLocal8Bit().constData();
string convertedFriendName = friendName.toLocal8Bit().constData();
cout << "Port Name: " << convertedPortName << endl;
cout << "Product ID:" << convertedProductId << endl;
cout << "Physical Name: " << convertedPhysicalName << endl;
cout << "Vendor Id: " << convertedVendorId << endl;
cout << "Friend Name: " << convertedFriendName << endl;
cout << endl;
counter++;
//Break if you found Huwawei USB dongle, assign the port to a new port
if (std::string::npos != convertedFriendName.find("HUAWEI Mobile Connect - 3G Modem"))
{
std::cout << "found!" << std::endl;
port = new QextSerialPort(portName);
break;
}
}
//Write and send the SMS
port->open(QIODevice::ReadWrite) ;
cout << port->isOpen() << endl;
port->write("AT+CFUN=1");
port->write("AT+CMGF=1 ");
port->write("AT+CMGS=1234567");
port->write("Hello Test SMS");
//port->write("0x1A");
port->flush();
port->close();
cout << port->isOpen() << endl;
system("pause");
return 0;
}
In this code, I am trying to send SMS using AT commands. My dongle is a Huawei USB dongle. It's known as "MegaFone Modem" anyway.
In my code, I am unable to send any SMS actually. Why is that? Please note you have to edit the phone number when you run this code. I am very new to QT, USB Programming and AT commands. I even don't know whether I am accessing the correct port, because there are 3 ports belong to Huawei. My output is as follows.
UPDATE
#include <qstring.h>
#include <qdebug.h>
#include <QCoreApplication>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
QextSerialPort *port;
QString portName;
int counter=0;
//Navigate through ports untill you find huwawei USB dongle
while(counter<ports.size())
{
portName = ports[counter].portName;
QString productId= ports[counter].productID;
QString physicalName = ports[counter].physName;
QString vendorId = ports[counter].vendorID;
QString friendName = ports[counter].friendName;
string convertedPortName = portName.toLocal8Bit().constData();
string convertedProductId = productId.toLocal8Bit().constData();
string convertedPhysicalName = physicalName.toLocal8Bit().constData();
string convertedVendorId = vendorId.toLocal8Bit().constData();
string convertedFriendName = friendName.toLocal8Bit().constData();
cout << "Port Name: " << convertedPortName << endl;
cout << "Product ID:" << convertedProductId << endl;
cout << "Physical Name: " << convertedPhysicalName << endl;
cout << "Vendor Id: " << convertedVendorId << endl;
cout << "Friend Name: " << convertedFriendName << endl;
cout << endl;
counter++;
//Break if you found Huwawei USB dongle, assign the port to a new port
if (std::string::npos != convertedFriendName.find("HUAWEI Mobile Connect - 3G Modem"))
{
std::cout << "found!" << std::endl;
port = new QextSerialPort(portName);
break;
}
}
//Write and send the SMS
port->open(QIODevice::ReadWrite) ;
cout << port->isOpen() << endl;
port->write("AT+CFUN=1\n");
cout << "\n";
port->write("AT+CMGF=1 \n ");
cout << "\n";
port->write("AT+CMGS=0776255495\n");
cout << "\n";
port->write("Hello Test SMS\n");
cout << "\n";
//port->write("0x1A");
port->flush();
port->close();
cout << port->isOpen() << endl;
system("pause");
return 0;
}