66 lines
1.6 KiB
C++
66 lines
1.6 KiB
C++
|
#include "serial.inc.h"
|
||
|
|
||
|
extern QApplication a;
|
||
|
using namespace std;
|
||
|
|
||
|
ZigbeeMgr::ZigbeeMgr()
|
||
|
{
|
||
|
//QMessageBox::StandardButton reply;
|
||
|
bool test;
|
||
|
|
||
|
this->setBaudRate(115200);
|
||
|
this->setDataBits(QSerialPort::Data8);
|
||
|
this->setStopBits(QSerialPort::OneStop);
|
||
|
this->setParity(QSerialPort::NoParity);
|
||
|
this->setPortName(this->serialDevicePath);
|
||
|
do
|
||
|
{
|
||
|
test = this->open(QIODevice::ReadWrite);
|
||
|
if (!test)
|
||
|
{
|
||
|
cout << this->errorString().toStdString() << "=>" << this->serialDevicePath.toStdString() << endl;
|
||
|
/*QString str = "Device can not be openened : " + errorString() + "=>" + this->device;
|
||
|
reply = QMessageBox::question(
|
||
|
nullptr,
|
||
|
a.applicationName(),
|
||
|
str,
|
||
|
QMessageBox::Retry|QMessageBox::Abort,
|
||
|
QMessageBox::Retry
|
||
|
);
|
||
|
if (reply == QMessageBox::Abort)
|
||
|
{
|
||
|
exit(1);
|
||
|
}*/
|
||
|
sleep(5);
|
||
|
}
|
||
|
}while(!test);
|
||
|
}
|
||
|
|
||
|
ZigbeeMgr::~ZigbeeMgr()
|
||
|
{
|
||
|
this->close();
|
||
|
}
|
||
|
|
||
|
void ZigbeeMgr::getData()
|
||
|
{
|
||
|
dataRead = this->readAll();
|
||
|
cout << dataRead.toHex().toStdString() << endl;
|
||
|
}
|
||
|
|
||
|
void ZigbeeMgr::confirmWrite(qint16 byte)
|
||
|
{
|
||
|
QString str;
|
||
|
if (byte != dataWriteSize)
|
||
|
{
|
||
|
str = "Bytes written not egal to bytes sent : " + QString::number(byte) + " written for " + dataWriteSize + " sent";
|
||
|
cout << str.toStdString() << endl;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void ZigbeeMgr::write(QString datas)
|
||
|
{
|
||
|
dataWriteSize = datas.count();
|
||
|
this->writeData(datas.toStdString().c_str(), datas.count());
|
||
|
}
|
||
|
|