#include <QtSerialPort>
#include <QtSerialPort/QSerialPort>
void class::my_class()
{
serial->setPortName("COM9");
if (serial->isOpen()){
serial->close();
qDebug() << "serial close";
}
else{
qDebug() << "serial already close.";
}
if (serial->open(QIODevice::ReadWrite)) {
serial->setBaudRate(19200);
serial->setDataBits(QSerialPort::Data8);
serial->setParity(QSerialPort::EvenParity);
serial->setStopBits(QSerialPort::OneStop);
serial->setFlowControl(QSerialPort::NoFlowControl);
}
}
my_function()
{
char buff[16];
int hhh;
for(hhh=0;hhh<=15;hhh++)
{
buff[0] = hhh;
serial->write(buff,1);
}
}
my_function2()
{
QByteArray input;
char buff[16];
int hhh;
for(hhh=0;hhh<=15;hhh++)
{
buff[0] = hhh;
serial->write(buff,1);
serial->waitForBytesWritten(100);
serial->waitForReadyRead(100);
input = serial->readAll();
if (input == ""){
qDebug() << "status" << hhh << " = Lost.";
}else if( quint8(input[0]) == quint8(0x60+hhh)){
qDebug() << "status" << hhh << " = Hot.";
}
}
serial->flush();
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น