您的位置:首页 > 编程语言 > Qt开发

qt通过驱动打开钱箱

2015-10-12 10:44 459 查看

1.前言

此前通过默认打印机驱动打开钱箱,会打印一段空白纸。在网上查找到可以通过向打印机发送命令来打开钱箱

2.代码片段

myqtcash.cpp

void myqtcash::on_openCash_clicked()
{
//这里看下直接调用打开钱箱是否可以
//这里如果不能用qt实现 我直接用windows来搞
QString strdllpath("");
strdllpath = QCoreApplication::applicationDirPath();
strdllpath += "/dll/";

QString strhttpdllpath("");
strhttpdllpath = strdllpath + "PrinterDLL.dll";

QLibrary myLib(strhttpdllpath);
typedef int (*pWz_Open)(const char* szPrinterName, enum PRINTER_TYPE printerType);
pWz_Open cat_Open = (pWz_Open) myLib.resolve("Wz_Open");

typedef int (*pWz_Close)();
pWz_Close cat_Close = (pWz_Close) myLib.resolve("Wz_Close");

typedef int (*pWz_OpenCashBox)();
pWz_OpenCashBox cat_OpenCashBox = (pWz_OpenCashBox) myLib.resolve("Wz_OpenCashBox");
if (cat_Open != NULL && cat_Close != NULL && cat_OpenCashBox != NULL)
{
if (cat_Open("USB", POS_OPEN_BYUSB_PORT) != POS_SUCCESS)
{
QMessageBox::information(this, "msg", QStringLiteral("打开usb端口失败"));
return;
}

int nret = cat_OpenCashBox();
if (nret != POS_SUCCESS)
{
QString strError("");
strError = QString("failed open cashbox, error:%1").arg(nret);
QMessageBox::information(this, "msg", strError);

cat_Close();
return;
}
cat_Close();
}
}


3.备注

1.在win7+vs2010+qt5.40+佳博80160测试通过

2.完整测试url:http://download.csdn.net/detail/zhang_ruiqiang/9173131
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  qt 打开钱箱