configuring pos printer now works
This commit is contained in:
parent
bfe1379e05
commit
dccf260431
3 changed files with 31 additions and 14 deletions
|
@ -6,6 +6,7 @@
|
|||
#include <posprinter.h>
|
||||
|
||||
#include <exception>
|
||||
#include <stdexcept>
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QSettings>
|
||||
|
@ -35,19 +36,33 @@ SettingsDialog::SettingsDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(par
|
|||
PosPrinter printer;
|
||||
printer.printTest();
|
||||
} else {
|
||||
|
||||
std::string posPrinterDeviceString = ui_.posPrinterDeviceEdit->text().toStdString();
|
||||
std::string delimiter = ":";
|
||||
PrinterDevice printerDevice;
|
||||
try {
|
||||
printerDevice.idVendor = std::stoi(
|
||||
posPrinterDeviceString.substr(0, posPrinterDeviceString.find(delimiter)), 0,
|
||||
16);
|
||||
printerDevice.idProduct = std::stoi(
|
||||
posPrinterDeviceString.substr(posPrinterDeviceString.find(delimiter) + 1),
|
||||
0, 16);
|
||||
} catch (std::exception&) {
|
||||
QMessageBox(QMessageBox::Icon::Warning, "Falsche Eingabe",
|
||||
QString("Eingabeformat für den Bondrucker (hexadezimale IDs): "
|
||||
"<VendorID>:<ProductID>\nBeispiel: 0416:5011"),
|
||||
QMessageBox::StandardButton::Ok, this)
|
||||
.exec();
|
||||
return;
|
||||
}
|
||||
/* if (printer.isValid())
|
||||
this->ui_.posPrinterDeviceEdit->setText("<gefunden>");
|
||||
else
|
||||
this->ui_.posPrinterDeviceEdit->setText("<nicht gefunden>"); */
|
||||
|
||||
PosPrinter printer(printerDevice);
|
||||
printer.printTest();
|
||||
}
|
||||
} catch (std::runtime_error& err) {
|
||||
QMessageBox(QMessageBox::Icon::Warning, "Bondrucker Fehler",
|
||||
QString("Test schlug fehl: ") + err.what(), QMessageBox::StandardButton::Ok,
|
||||
this)
|
||||
.exec();
|
||||
// this->ui_.posPrinterDeviceEdit->setText("<Fehler>");
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -20,7 +20,13 @@ const std::string PosPrinter::Command::FONT_SIZE_BIG = {'\x1b', '\x21', '\x10'};
|
|||
const std::string PosPrinter::Command::FONT_SIZE_NORMAL = {'\x1b', '\x21', '\x00'};
|
||||
const std::string PosPrinter::Command::FEED = {0x1b, 0x64, 0x03};
|
||||
|
||||
PosPrinter::PosPrinter()
|
||||
PosPrinter::PosPrinter() : PosPrinter(PrinterDevice())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
PosPrinter::PosPrinter(const PrinterDevice& printerDevice)
|
||||
: printerDevice_(printerDevice)
|
||||
{
|
||||
int retValue;
|
||||
|
||||
|
@ -53,6 +59,7 @@ PosPrinter::PosPrinter()
|
|||
if (desc.idVendor == printerDevice_.idVendor &&
|
||||
desc.idProduct == printerDevice_.idProduct) {
|
||||
numDevice = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -85,11 +92,6 @@ PosPrinter::PosPrinter()
|
|||
libusb_free_device_list(devList, 1);
|
||||
}
|
||||
|
||||
PosPrinter::PosPrinter(const PrinterDevice& printerDevice) : printerDevice_{printerDevice}
|
||||
{
|
||||
PosPrinter();
|
||||
}
|
||||
|
||||
PosPrinter::~PosPrinter()
|
||||
{
|
||||
if (devicePtr_) {
|
||||
|
|
|
@ -49,7 +49,7 @@ class PosPrinter
|
|||
libusb_context* contextPtr_{};
|
||||
libusb_device_handle* devicePtr_{};
|
||||
SupportedPrinters supportedPrinters_;
|
||||
PrinterDevice printerDevice_;
|
||||
PrinterDevice printerDevice_{};
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue