I still do not get any answer from com port number two(GSMcomm). My code is like:
The constructor:
EikeTesten
::EikeTesten(QWidget *parent
) :{ ....
qDebug("Creating QextSerialPort instance");
CommPort = new QextSerialPort();
CommPort
->setPortName
(QString("/dev/ttyUSB0"));
CommPort->setDataBits(DATA_8);
CommPort->setParity(PAR_NONE);
CommPort->setFlowControl(FLOW_OFF);
CommPort->setStopBits(STOP_1);
CommPort->setBaudRate(BAUD300);
CommPort->open();
connect(receiveTimer, SIGNAL(timeout()), SLOT(receiveMsg())); // receiveMsg get the message from ttyUSB0 and call saveData();
receiveTimer->start(0);
..
}
EikeTesten::EikeTesten(QWidget *parent) :
QWidget(parent)
{ ....
qDebug("Creating QextSerialPort instance");
CommPort = new QextSerialPort();
CommPort->setPortName(QString("/dev/ttyUSB0"));
CommPort->setDataBits(DATA_8);
CommPort->setParity(PAR_NONE);
CommPort->setFlowControl(FLOW_OFF);
CommPort->setStopBits(STOP_1);
CommPort->setBaudRate(BAUD300);
CommPort->open();
QTimer *receiveTimer = new QTimer(this);
connect(receiveTimer, SIGNAL(timeout()), SLOT(receiveMsg())); // receiveMsg get the message from ttyUSB0 and call saveData();
receiveTimer->start(0);
..
}
To copy to clipboard, switch view to plain text mode
in saveData:
{ ....
GSMcomm = new GSMkommunikasjon();
GSMcomm -> sendAlarmSMS(text);
....}
{ ....
GSMcomm = new GSMkommunikasjon();
GSMcomm -> sendAlarmSMS(text);
....}
To copy to clipboard, switch view to plain text mode
in GSMkommunikasjon constructor:
{/*create and init communications port*/
qDebug("Creating SMSCommPort instance");
SMSCommPort = new QextSerialPort();
SMSCommPort
->setPortName
(QString("/dev/ttyUSB1"));
SMSCommPort->setDataBits(DATA_8);
SMSCommPort->setParity(PAR_NONE);
SMSCommPort->setFlowControl(FLOW_OFF);
SMSCommPort->setStopBits(STOP_1);
SMSCommPort->setBaudRate(BAUD19200);
SMSCommPort->open();
SMSCommPort->setDtr(0);
SMSCommPort->setDtr(1);
//SMSCommPort->close();
//sendAlarmSMS();
connect(receiveTimer2, SIGNAL(timeout()), SLOT(receiveFromSMS()));
receiveTimer2->start(0);
}
in receiveFromSMS()
{
int numBytes = SMSCommPort->bytesAvailable();
if(numBytes > 0)
{
if (numBytes > 80) numBytes = 80;
char buff[80];
int i = SMSCommPort->readData(buff, numBytes);
buff[numBytes] = '\0';
}}
... // But the program never receive anything
}
{/*create and init communications port*/
qDebug("Creating SMSCommPort instance");
SMSCommPort = new QextSerialPort();
SMSCommPort->setPortName(QString("/dev/ttyUSB1"));
SMSCommPort->setDataBits(DATA_8);
SMSCommPort->setParity(PAR_NONE);
SMSCommPort->setFlowControl(FLOW_OFF);
SMSCommPort->setStopBits(STOP_1);
SMSCommPort->setBaudRate(BAUD19200);
SMSCommPort->open();
SMSCommPort->setDtr(0);
SMSCommPort->setDtr(1);
//SMSCommPort->close();
//sendAlarmSMS();
QTimer *receiveTimer2 = new QTimer(this);
connect(receiveTimer2, SIGNAL(timeout()), SLOT(receiveFromSMS()));
receiveTimer2->start(0);
}
in receiveFromSMS()
{
int numBytes = SMSCommPort->bytesAvailable();
if(numBytes > 0)
{
if (numBytes > 80) numBytes = 80;
char buff[80];
int i = SMSCommPort->readData(buff, numBytes);
buff[numBytes] = '\0';
QChar byte0 = buff[0];
QChar byte1 = buff[1];
}}
... // But the program never receive anything
}
To copy to clipboard, switch view to plain text mode
Can you please help me?
Bookmarks