-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.cpp
65 lines (52 loc) · 1.28 KB
/
interface.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
#include "interface.h"
SerialInterface::SerialInterface(const PortSettings &settings, QObject *parent) :
Interface(parent),
d_port(new QSerialPort(this)),
d_settings(settings)
{
}
SerialInterface::~SerialInterface()
{
}
bool SerialInterface::open()
{
d_port->setPortName(d_settings.portName);
if (d_port->open(QIODevice::ReadWrite) == true) {
if (d_port->setBaudRate(d_settings.baudRate)
&& d_port->setDataBits(d_settings.dataBits)
&& d_port->setFlowControl(d_settings.flowControl)
&& d_port->setParity(d_settings.parity)
&& d_port->setStopBits(d_settings.stopBits)) {
return true;
}
}
return false;
}
void SerialInterface::close()
{
d_port->close();
}
qint64 SerialInterface::bytesAvailable()
{
return d_port->bytesAvailable();
}
qint64 SerialInterface::read(char *data, qint64 maxlen)
{
return d_port->read(data, maxlen);
}
qint64 SerialInterface::write(const char *data, qint64 len)
{
return d_port->write(data, len);
}
bool SerialInterface::isOpen()
{
return d_port->isOpen();
}
void SerialInterface::setPortSettings(const PortSettings &settings)
{
d_settings = settings;
}
const PortSettings &SerialInterface::portSettings()
{
return d_settings;
}