QT串口通讯协议
近期由于需要,加入了电子指北针,因此通过串口协议获取回传数据,以下是个人在探索过程中解析协议一点心得:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
m_Timer = new QTimer;
// 在解析数据中,会出现接收数据内容不完整的情况,因此在接受的过程中使用了定时器来设定一定间隔接收数据,这样就会避免数据不完整的情况
connect(m_Timer, SIGNAL(timeout()), this, SLOT(sl_NorthTimeout()));
m_Timer->start(100);
}
void MainWindow::sl_NorthTimeout()
{
getAngle();
}
// 指北针获取角度协议 通过发送该协议指令来获取数据
void MainWindow::getAngle()
{
str = "68 04 00 04 08";
list = str.split(" ");
for