hi all, i'm currently doing an application that will send and receive SMS messages using GSM Modem and by sending AT Commands. I used the QextSerialPort class. I connect to the port using this code:
port = new QextSerialPort("COM1");
port->setBaudRate(BAUD19200);
port->setFlowControl(FLOW_OFF);
port->setParity(PAR_NONE);
port->setDataBits(DATA_8);
port->setStopBits(STOP_2);
port = new QextSerialPort("COM1");
port->setBaudRate(BAUD19200);
port->setFlowControl(FLOW_OFF);
port->setParity(PAR_NONE);
port->setDataBits(DATA_8);
port->setStopBits(STOP_2);
port->open(QIODevice::ReadWrite);
To copy to clipboard, switch view to plain text mode
then send AT COMMANDS:
QString command
="AT\r\n";
//sample command - in Hyperterminal this returns OK byte.clear();
byte.append(command);
port->write(byte);
port->waitForBytesWritten (500);
QString command ="AT\r\n"; //sample command - in Hyperterminal this returns OK
QByteArray byte;
byte.clear();
byte.append(command);
port->write(byte);
port->waitForBytesWritten (500);
To copy to clipboard, switch view to plain text mode
then try to read the response:
char buff[1024];
int numBytes;
numBytes = port->bytesAvailable(); //always returns -1
if(numBytes > 0)
{
if(numBytes > 1024)
numBytes = 1024;
int i = port->read(buff, numBytes);
buff[i] = '\0';
qDebug(msg);
qDebug("bytes available: %d", numBytes);
qDebug("received: %d", i);
}
char buff[1024];
int numBytes;
numBytes = port->bytesAvailable(); //always returns -1
if(numBytes > 0)
{
if(numBytes > 1024)
numBytes = 1024;
int i = port->read(buff, numBytes);
buff[i] = '\0';
QString msg = buff;
qDebug(msg);
qDebug("bytes available: %d", numBytes);
qDebug("received: %d", i);
}
To copy to clipboard, switch view to plain text mode
i'm not sure if im doing it right cause when i read the response the bytesAvailable() always returns -1. Is there anybody here can help me or give me a piece of code on how to do it right? thnks in advance...
Bookmarks