configuring pos printer now works

This commit is contained in:
Martin Brodbeck 2018-08-15 08:50:46 +02:00
parent bfe1379e05
commit dccf260431
3 changed files with 31 additions and 14 deletions

View file

@ -6,6 +6,7 @@
#include <posprinter.h> #include <posprinter.h>
#include <exception> #include <exception>
#include <stdexcept>
#include <QMessageBox> #include <QMessageBox>
#include <QSettings> #include <QSettings>
@ -35,19 +36,33 @@ SettingsDialog::SettingsDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(par
PosPrinter printer; PosPrinter printer;
printer.printTest(); printer.printTest();
} else { } 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;
}
PosPrinter printer(printerDevice);
printer.printTest();
} }
/* if (printer.isValid())
this->ui_.posPrinterDeviceEdit->setText("<gefunden>");
else
this->ui_.posPrinterDeviceEdit->setText("<nicht gefunden>"); */
} catch (std::runtime_error& err) { } catch (std::runtime_error& err) {
QMessageBox(QMessageBox::Icon::Warning, "Bondrucker Fehler", QMessageBox(QMessageBox::Icon::Warning, "Bondrucker Fehler",
QString("Test schlug fehl: ") + err.what(), QMessageBox::StandardButton::Ok, QString("Test schlug fehl: ") + err.what(), QMessageBox::StandardButton::Ok,
this) this)
.exec(); .exec();
// this->ui_.posPrinterDeviceEdit->setText("<Fehler>");
return; return;
} }
}); });

View file

@ -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::FONT_SIZE_NORMAL = {'\x1b', '\x21', '\x00'};
const std::string PosPrinter::Command::FEED = {0x1b, 0x64, 0x03}; const std::string PosPrinter::Command::FEED = {0x1b, 0x64, 0x03};
PosPrinter::PosPrinter() PosPrinter::PosPrinter() : PosPrinter(PrinterDevice())
{
}
PosPrinter::PosPrinter(const PrinterDevice& printerDevice)
: printerDevice_(printerDevice)
{ {
int retValue; int retValue;
@ -53,6 +59,7 @@ PosPrinter::PosPrinter()
if (desc.idVendor == printerDevice_.idVendor && if (desc.idVendor == printerDevice_.idVendor &&
desc.idProduct == printerDevice_.idProduct) { desc.idProduct == printerDevice_.idProduct) {
numDevice = i; numDevice = i;
break;
} }
} }
} }
@ -85,11 +92,6 @@ PosPrinter::PosPrinter()
libusb_free_device_list(devList, 1); libusb_free_device_list(devList, 1);
} }
PosPrinter::PosPrinter(const PrinterDevice& printerDevice) : printerDevice_{printerDevice}
{
PosPrinter();
}
PosPrinter::~PosPrinter() PosPrinter::~PosPrinter()
{ {
if (devicePtr_) { if (devicePtr_) {

View file

@ -49,7 +49,7 @@ class PosPrinter
libusb_context* contextPtr_{}; libusb_context* contextPtr_{};
libusb_device_handle* devicePtr_{}; libusb_device_handle* devicePtr_{};
SupportedPrinters supportedPrinters_; SupportedPrinters supportedPrinters_;
PrinterDevice printerDevice_; PrinterDevice printerDevice_{};
}; };
#endif #endif