-
Notifications
You must be signed in to change notification settings - Fork 46
/
PrinterManager.cpp
82 lines (61 loc) · 2.57 KB
/
PrinterManager.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
#include "PrinterManager.h"
#include <QDebug>
#include <QProcess>
#include <QFileInfo>
PrinterManager::PrinterManager(const QSharedPointer<QSettings>& settings, QObject *parent)
: QObject(parent), _settings(settings)
{
_fileName = _settings->value("workDirectory").toString() + "/" + _settings->value("Label/fileName").toString();
_labelName = _settings->value("Label/labelName").toString();
_quantity = _settings->value("Label/quantity").toString();
_printer = _settings->value("Label/printer").toString();
_deviceName = _settings->value("Label/deviceName").toString();
_deviceRevision = _settings->value("Label/deviceRevision").toString();
connect(&_timer, &QTimer::timeout, this, &PrinterManager::sendLabeltoPrinter);
_timer.start(10000);
// DutRecord record;
// record.id = "FF121234AB3456CD";
// record.method = "OLC NemaPP";
// record.cycleNo = "1";
// record.no = "7";
// record.runningNumber = "0072";
// addLabel(record);
}
PrinterManager::~PrinterManager()
{
_timer.stop();
}
void PrinterManager::addLabel(DutRecord dutRecord)
{
_labelQueue.enqueue(dutRecord);
}
void PrinterManager::sendLabeltoPrinter()
{
if(_labelQueue.isEmpty() || QFileInfo::exists(_fileName))
return;
auto currentRecord = _labelQueue.dequeue();
if(!currentRecord.no.size())
return;
QFile file(_fileName);
file.open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text);
if (!file.isWritable())
_logger->logError(QString("Cannot open label file '%1' for writing").arg(_fileName));
// file.write(QString("LABELNAME = \"%1\"\n").arg(_labelName).toLocal8Bit());
file.write(QString("LABELNAME = \"%1\"\n").arg(QString(currentRecord.method + ".lab")).toLocal8Bit());
file.write(QString("LABELQUANTITY = \"%1\"\n").arg(_quantity).toLocal8Bit());
if (!_printer.isEmpty())
file.write(QString("PRINTER = \"%1\"\n").arg(_printer).toLocal8Bit());
file.write(QString("Name = \"%1\"\n").arg(currentRecord.method).toLocal8Bit());
file.write(QString("Revision = \"%1\"\n").arg(_deviceRevision).toLocal8Bit());
file.write(QString("cycleNo = \"%1\"\n").arg(currentRecord.cycleNo).toLocal8Bit());
file.write(QString("slot = \"%1\"\n").arg(currentRecord.no).toLocal8Bit());
file.write(QString("runningNumber = \"%1\"\n").arg(currentRecord.runningNumber).toLocal8Bit());
file.write(QString("NID = \"%1\"\n").arg(currentRecord.id).toLocal8Bit());
file.close();
}
bool PrinterManager::isQueueEmpty() const
{
if(_labelQueue.isEmpty())
return true;
return false;
}