-
Notifications
You must be signed in to change notification settings - Fork 0
/
serial.cpp
64 lines (51 loc) · 1.38 KB
/
serial.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <QtSerialPort/QSerialPort>
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QGraphicsView>
#include <QGraphicsEllipseItem>
#include <QTimer>
#include <QDebug>
#include <QScrollBar>
#include <QPen>
#include <QtConcurrent>
#include <QPainterPath>
#include <QThread>
#include "serialengine.h"
void serialengine::readData()
{
if (serial->isOpen())
{
serial->write("$");
serial->readLine(buffer, 5);
QString donnees=buffer;
while(donnees.size()<5)
{
serial->readLine(buffer, 5);
donnees=buffer;
qDebug()<< donnees << " size: " << donnees.size();
}
if(donnees.toInt()!=0)
temperature=donnees.toInt() ;
}
else
{
temperature = qrand() % m_rand;
}
}
void serialengine::openSerialPort()
{
serial->setPortName(m_ser_name);
serial->setBaudRate(m_baudrate);
serial->setDataBits(QSerialPort::DataBits(m_databits));
serial->setParity(QSerialPort::Parity(m_parity));
serial->setStopBits(QSerialPort::StopBits(m_stopbits));
serial->setFlowControl(QSerialPort::FlowControl(m_flowcontrol));
if(!serial->open(QIODevice::ReadWrite))
{
qDebug()<<"erreur";
}
}
void serialengine::write(QString str)
{
serial->write((const char*)str.data());
}