Implement printing receipts:

- using DC prn_sendText
 - this is a rather general print method
This commit is contained in:
Siegfried Siegert 2023-08-07 17:38:29 +02:00
parent 3bc68ff0ae
commit 6b807fd636
Signed by: SiegfriedSiegert
GPG Key ID: 68371E015E8F0B03
2 changed files with 57 additions and 5 deletions

View File

@ -537,6 +537,56 @@ void ATBDeviceControllerPlugin::requestPrintReceipt(const QHash<QString, QVarian
qCritical() << "ATBDeviceControllerPlugin::requestPrintReceipt() is currently not implemented"; qCritical() << "ATBDeviceControllerPlugin::requestPrintReceipt() is currently not implemented";
} }
void ATBDeviceControllerPlugin::requestPrintReceipt(const QString & printingString)
{
QByteArray ba = printingString.toUtf8();
hw->prn_switchPower(true);
hw->prn_sendText(&ba);
QTimer::singleShot(4000, this, SLOT(onPrinterWaitForPrintingReceipt()));
//QTimer::singleShot(2000, this, [this](){ hw->prn_cut(3); } );
}
void ATBDeviceControllerPlugin::onPrinterWaitForPrintingReceipt()
{
quint8 printerResult = this->hw->prn_getPrintResult();
switch (printerResult) {
case 0: // still printing
qCritical() << "--> printer: WaitForPrintingReceipt";
QTimer::singleShot(2000, this, SLOT(onPrinterWaitForPrintingReceipt()));
break;
case 1: // printing finished, Ok
qCritical() << "DC Finished printing receipt";
emit this->printReceiptFinished(nsDeviceControllerInterface::RESULT_STATE::SUCCESS,
// TODO: TicketNumber
"",
"");
hw->prn_switchPower(true);
hw->prn_cut(3);
break;
case 2: // printing finished, Error
qCritical() << "DC Error: wait for printing receipt";
this->errorCode = "PRINTER"; // TODO: get more detailed error code from low level API
this->errorDescription = "Printer error"; // TODO: get more detailed error description from low level API
emit this->printReceiptFinished(nsDeviceControllerInterface::RESULT_STATE::ERROR_BACKEND,
this->errorCode,
this->errorDescription);
break;
default:
qCritical() << "DC Error: wait for printing receipt";
this->errorCode = "PRINTER"; // TODO: get more detailed error code from low level API
this->errorDescription = "Printer error"; // TODO: get more detailed error description from low level API
emit this->printReceiptFinished(nsDeviceControllerInterface::RESULT_STATE::ERROR_BACKEND,
this->errorCode,
this->errorDescription);
break;
}
}
void ATBDeviceControllerPlugin::requestPrintTicket(const QHash<QString, QVariant> & printingData) void ATBDeviceControllerPlugin::requestPrintTicket(const QHash<QString, QVariant> & printingData)
{ {
@ -662,21 +712,21 @@ void ATBDeviceControllerPlugin::onPrinterDataPrepared()
// note: calling prn_getPrintResult() immediately may result in wrong answer! // note: calling prn_getPrintResult() immediately may result in wrong answer!
// We have to wait "about some seconds" until calling this function! // We have to wait "about some seconds" until calling this function!
QTimer::singleShot(4000, this, SLOT(onPrinterWaitForPrinting())); QTimer::singleShot(4000, this, SLOT(onPrinterWaitForPrintingTicket()));
// old: use printer templates: // old: use printer templates:
// this->currentTemplate = 1; // this->currentTemplate = 1;
// this->onPrinterPrintNextTemplate(); // this->onPrinterPrintNextTemplate();
} }
void ATBDeviceControllerPlugin::onPrinterWaitForPrinting() void ATBDeviceControllerPlugin::onPrinterWaitForPrintingTicket()
{ {
quint8 printerResult = this->hw->prn_getPrintResult(); quint8 printerResult = this->hw->prn_getPrintResult();
switch (printerResult) { switch (printerResult) {
case 0: // still printing case 0: // still printing
qCritical() << "--> printer: WaitForPrinting"; qCritical() << "--> printer: WaitForPrintingTicket";
QTimer::singleShot(2000, this, SLOT(onPrinterWaitForPrinting())); QTimer::singleShot(2000, this, SLOT(onPrinterWaitForPrintingTicket()));
break; break;
case 1: // printing finished, Ok case 1: // printing finished, Ok
this->onPrintFinishedOK(); this->onPrintFinishedOK();

View File

@ -52,6 +52,7 @@ public:
void requestPrintTicket(const QHash<QString, QVariant> & printingData); void requestPrintTicket(const QHash<QString, QVariant> & printingData);
void requestPrintTicket(nsDeviceControllerInterface::TICKET_VARIANT ticketVariant, const QHash<QString, QVariant> & printingData); void requestPrintTicket(nsDeviceControllerInterface::TICKET_VARIANT ticketVariant, const QHash<QString, QVariant> & printingData);
void requestPrintReceipt(const QHash<QString, QVariant> & printingData); void requestPrintReceipt(const QHash<QString, QVariant> & printingData);
void requestPrintReceipt(const QString & printingString);
// TASKS: Account ------------------------------------------------------------- // TASKS: Account -------------------------------------------------------------
void requestAccount(); void requestAccount();
@ -125,7 +126,8 @@ private slots:
void onPrinterDataPrepared(); void onPrinterDataPrepared();
void onPrinterDataPreparedForTemplates(); void onPrinterDataPreparedForTemplates();
void onPrinterPrintNextTemplate(); void onPrinterPrintNextTemplate();
void onPrinterWaitForPrinting(); void onPrinterWaitForPrintingTicket();
void onPrinterWaitForPrintingReceipt();
void onPrintFinishedOK(); void onPrintFinishedOK();
void onPrintFinishedERR(); void onPrintFinishedERR();