-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharduino1.cpp
163 lines (107 loc) · 2.9 KB
/
arduino1.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include "arduino1.h"
#include <QDebug>
#include <QObject>
arduino1::arduino1()
{
data="";
arduino_port_name="";
arduino_is_available=false;
serial =new QSerialPort;
}
QString arduino1::getarduino_port_name()
{
return arduino_port_name;
}
QSerialPort *arduino1::getserial()
{
return serial;
}
int arduino1::connect_arduino()
{
foreach (const QSerialPortInfo &serial_port_info,QSerialPortInfo::availablePorts())
{
if(serial_port_info.hasVendorIdentifier()&& serial_port_info.hasProductIdentifier())
{
qDebug()<<serial_port_info.productIdentifier() ;
if(serial_port_info.vendorIdentifier() == arduino_uno_vendor_id && serial_port_info.productIdentifier()== arduino_uno_producy_id)
{
arduino_is_available=true;
arduino_port_name=serial_port_info.portName();
}
}
}
qDebug() << "arduino_port_name is :"<<arduino_port_name;
if (arduino_is_available)
{
serial->setPortName(arduino_port_name);
if(serial->open(QSerialPort::ReadWrite))
{
serial->setBaudRate(QSerialPort::Baud9600);
serial->setDataBits(QSerialPort::Data8);
serial->setParity(QSerialPort::NoParity);
serial->setStopBits(QSerialPort::OneStop);
serial->setFlowControl(QSerialPort::NoFlowControl);
return 0;
}
return 1;
}
return -1 ;
}
int arduino1::close_arduino()
{
if(serial->isOpen())
{
serial->close();
return 0;
}
return 1;
}
QByteArray arduino1::read_from_arduino()
{
if (serial->isReadable()) {
data=serial->readAll() ;
/*if(serial->waitForReadyRead()&&serial->isReadable())
{
data=serial->readAll() ;
QString temp=QString::fromStdString(data.toStdString()) ;
qDebug() <<temp ;
return data;
}
else
{
qDebug() <<"Couldn't read to serial!";
}
*/
}
return data ;
}
int arduino1::write_to_arduino(QByteArray d)
{
if(serial->isWritable())
{
serial->write(d);
}
else
{
qDebug() <<"Couldn't write to serial!";
}
return 0;
}
QSqlQueryModel * arduino1:: afficher()
{
QSqlQueryModel * model= new QSqlQueryModel();
model->setQuery("select * from POINTAGE ");
model->setHeaderData(0, Qt::Horizontal, QObject::tr("CIN"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("NOM "));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("PRENOM"));
return model ;
}
QSqlQueryModel * arduino1:: afficher2()
{
QSqlQueryModel * model= new QSqlQueryModel();
model->setQuery("select p.CIN,p.NOM,p.PRENOM,p.D,p.TIME from POINTAGE p ,TABLE1 t where t.CIN=p.CIN AND t.cin=:cin ");
model->setHeaderData(0, Qt::Horizontal, QObject::tr("CIN"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("NOM "));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("PRENOM"));
return model ;
}