Make sure the printer functions can be called without explicitly openeing the

serial device.
This commit is contained in:
Gerhard Hoffmann 2023-04-14 09:04:35 +02:00
parent e5a8cfd1cd
commit 3e3e1efe7d
3 changed files with 4802 additions and 4790 deletions

View File

@ -148,12 +148,12 @@ public:
QVector<int> templateIdx, QVector<int> templateIdx,
QVector<QString> fnames, QVector<QString> fnames,
QString br, QString br,
QString serial) const override; QString serial = QString()) const override;
bool dc_printTemplate(enum FileTypeJson type, bool dc_printTemplate(enum FileTypeJson type,
QVector<int> templateIdx, QVector<int> templateIdx,
QString br, QString br,
QString serial) const override; QString serial = QString()) const override;
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
// Level 1, control device-controller (functions of µC) // Level 1, control device-controller (functions of µC)
// check serial connection to deviceController // check serial connection to deviceController

View File

@ -310,12 +310,12 @@ public:
QVector<int> templateIdx, QVector<int> templateIdx,
QVector<QString> fnames, QVector<QString> fnames,
QString br, QString br,
QString serial) const = 0; QString serial = QString()) const = 0;
virtual bool dc_printTemplate(enum FileTypeJson type, virtual bool dc_printTemplate(enum FileTypeJson type,
QVector<int> templateIdx, QVector<int> templateIdx,
QString br, QString br,
QString serial) const = 0; QString serial = QString()) const = 0;
virtual void dc_autoRequest(bool on) const =0; virtual void dc_autoRequest(bool on) const =0;
// on = true: select that all READ-Requests are sent automatically // on = true: select that all READ-Requests are sent automatically

View File

@ -438,16 +438,20 @@ bool hwapi::dc_updatePrinterTemplate(enum FileTypeJson type,
qDebug() << "updating: " << fnames << br << serial << "..."; qDebug() << "updating: " << fnames << br << serial << "...";
if (!serial.isNull()) {
if (!openSerial(baudrateMap.value(br), br, serial)) { if (!openSerial(baudrateMap.value(br), br, serial)) {
return false; return false;
} }
}
int nTry = 50; int nTry = 50;
while (!sys_ready4sending()) { // wait max. 5 seconds while (!sys_ready4sending()) { // wait max. 5 seconds
std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::this_thread::sleep_for(std::chrono::milliseconds(100));
if (--nTry <= 0) { if (--nTry <= 0) {
qCritical() << "sys not ready for sending"; qCritical() << "sys not ready for sending";
if (!serial.isNull()) {
closeSerial(serial); closeSerial(serial);
}
return false; return false;
} }
} }
@ -471,7 +475,9 @@ bool hwapi::dc_updatePrinterTemplate(enum FileTypeJson type,
continue; continue;
} }
} }
if (!serial.isNull()) {
closeSerial(serial); closeSerial(serial);
}
return ret; return ret;
} }
@ -496,16 +502,20 @@ bool hwapi::dc_printTemplate(enum FileTypeJson type,
qDebug() << "printing: " << templateIdx << br << serial << "..."; qDebug() << "printing: " << templateIdx << br << serial << "...";
if (!serial.isNull()) {
if (!openSerial(baudrateMap.value(br), br, serial)) { if (!openSerial(baudrateMap.value(br), br, serial)) {
return false; return false;
} }
}
int nTry = 50; int nTry = 50;
while (!sys_ready4sending()) { // wait max. 5 seconds while (!sys_ready4sending()) { // wait max. 5 seconds
std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::this_thread::sleep_for(std::chrono::milliseconds(100));
if (--nTry <= 0) { if (--nTry <= 0) {
qCritical() << "sys not ready for sending"; qCritical() << "sys not ready for sending";
if (!serial.isNull()) {
closeSerial(serial); closeSerial(serial);
}
return false; return false;
} }
} }
@ -520,7 +530,9 @@ bool hwapi::dc_printTemplate(enum FileTypeJson type,
continue; continue;
} }
} }
if (!serial.isNull()) {
closeSerial(serial); closeSerial(serial);
}
return ret; return ret;
} }