|
@@ -4,6 +4,8 @@
|
|
|
#include <winioctl.h>
|
|
#include <winioctl.h>
|
|
|
#include <setupapi.h>
|
|
#include <setupapi.h>
|
|
|
|
|
|
|
|
|
|
+#include "../tool/CComHelper.h"
|
|
|
|
|
+
|
|
|
using boost::asio::ip::tcp;
|
|
using boost::asio::ip::tcp;
|
|
|
|
|
|
|
|
CPosPrinter::CPosPrinter(): m_socket(m_io)
|
|
CPosPrinter::CPosPrinter(): m_socket(m_io)
|
|
@@ -15,13 +17,13 @@ CPosPrinter::~CPosPrinter()
|
|
|
{
|
|
{
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void CPosPrinter::InitUsb()
|
|
|
|
|
|
|
+void CPosPrinter::InitUsb(int usbType)
|
|
|
{
|
|
{
|
|
|
//设置中文字符
|
|
//设置中文字符
|
|
|
setlocale(LC_CTYPE, "chs");
|
|
setlocale(LC_CTYPE, "chs");
|
|
|
|
|
|
|
|
//取设备路径
|
|
//取设备路径
|
|
|
- int nDevice = GetDevicePath((LPGUID)&USB_GUID);
|
|
|
|
|
|
|
+ int nDevice = GetDevicePath((LPGUID)&USB_GUID, usbType);
|
|
|
LOG_INFO("可用的USB打印机数量:" << nDevice);
|
|
LOG_INFO("可用的USB打印机数量:" << nDevice);
|
|
|
|
|
|
|
|
//添加usb端口
|
|
//添加usb端口
|
|
@@ -154,11 +156,12 @@ void CPosPrinter::InitBingkou()
|
|
|
|
|
|
|
|
void CPosPrinter::InitCom()
|
|
void CPosPrinter::InitCom()
|
|
|
{
|
|
{
|
|
|
- int comNum = 10;
|
|
|
|
|
|
|
+ CComHelper helper;
|
|
|
|
|
+ std::vector<std::wstring> comVector = helper.getComPort();
|
|
|
|
|
|
|
|
- for (int i = 1; i <= 10; i++)
|
|
|
|
|
|
|
+ for (std::vector<std::wstring>::iterator it = comVector.begin(); it != comVector.end(); it++)
|
|
|
{
|
|
{
|
|
|
- std::wstring com2Str = L"com" + CLewaimaiString::ANSIToUnicode(to_string(i));
|
|
|
|
|
|
|
+ std::wstring com2Str = *it;
|
|
|
|
|
|
|
|
HANDLE hPort = CreateFile(com2Str.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
HANDLE hPort = CreateFile(com2Str.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
|
|
|
@@ -239,7 +242,7 @@ void CPosPrinter::InitShouyin()
|
|
|
/*
|
|
/*
|
|
|
*获取CreateFile的USB端口号
|
|
*获取CreateFile的USB端口号
|
|
|
**/
|
|
**/
|
|
|
-int CPosPrinter::GetDevicePath(LPGUID lpGuid)
|
|
|
|
|
|
|
+int CPosPrinter::GetDevicePath(LPGUID lpGuid, int usbType)
|
|
|
{
|
|
{
|
|
|
HDEVINFO hDevInfoSet;
|
|
HDEVINFO hDevInfoSet;
|
|
|
SP_DEVINFO_DATA spDevInfoData;
|
|
SP_DEVINFO_DATA spDevInfoData;
|
|
@@ -347,7 +350,7 @@ int CPosPrinter::GetDevicePath(LPGUID lpGuid)
|
|
|
|
|
|
|
|
LOG_INFO("Vid:" << vid.c_str() << ", Pid:" << pid.c_str());
|
|
LOG_INFO("Vid:" << vid.c_str() << ", Pid:" << pid.c_str());
|
|
|
|
|
|
|
|
- if (GetPrinterType(vid, pid) == 2)
|
|
|
|
|
|
|
+ if (usbType == 1 && GetPrinterType(vid, pid) == 2)
|
|
|
{
|
|
{
|
|
|
//标签打印机,暂时不处理打印
|
|
//标签打印机,暂时不处理打印
|
|
|
LOG_INFO("标签打印机,暂时不打印!");
|
|
LOG_INFO("标签打印机,暂时不打印!");
|
|
@@ -383,12 +386,11 @@ int CPosPrinter::GetDevicePath(LPGUID lpGuid)
|
|
|
**/
|
|
**/
|
|
|
int CPosPrinter::GetPrinterType(wstring vid, wstring pid)
|
|
int CPosPrinter::GetPrinterType(wstring vid, wstring pid)
|
|
|
{
|
|
{
|
|
|
-/*
|
|
|
|
|
if (vid == L"6868" && pid == L"0500")
|
|
if (vid == L"6868" && pid == L"0500")
|
|
|
{
|
|
{
|
|
|
//佳博标签打印机
|
|
//佳博标签打印机
|
|
|
return 2;
|
|
return 2;
|
|
|
- }*/
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
@@ -436,7 +438,7 @@ void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
|
|
|
catch (std::exception& e)
|
|
catch (std::exception& e)
|
|
|
{
|
|
{
|
|
|
std::string err = e.what();
|
|
std::string err = e.what();
|
|
|
- LOG_INFO("连接厨房打印机失败,IP地址:" << wangkou_ip.c_str() << ",错误信息:" << err.c_str());
|
|
|
|
|
|
|
+ LOG_INFO("打印机失败,IP地址:" << wangkou_ip.c_str() << ",错误信息:" << err.c_str());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -807,6 +809,7 @@ void CPosPrinter::PrintWaimaiOrderBiaoqian(CWaimaiOrder& order)
|
|
|
std::string printer_usb = CSetting::GetParam("setting_biaoqian_printer_usb");
|
|
std::string printer_usb = CSetting::GetParam("setting_biaoqian_printer_usb");
|
|
|
std::wstring ws_printer_usb = CLewaimaiString::UTF8ToUnicode(printer_usb);
|
|
std::wstring ws_printer_usb = CLewaimaiString::UTF8ToUnicode(printer_usb);
|
|
|
|
|
|
|
|
|
|
+ //连接usb端口
|
|
|
InitOneUsb(ws_printer_usb);
|
|
InitOneUsb(ws_printer_usb);
|
|
|
|
|
|
|
|
//初始化标签打印机
|
|
//初始化标签打印机
|
|
@@ -817,7 +820,19 @@ void CPosPrinter::PrintWaimaiOrderBiaoqian(CWaimaiOrder& order)
|
|
|
|
|
|
|
|
std::vector<CWaimaiOrderItem> cur_printer_use = order.m_order_items;
|
|
std::vector<CWaimaiOrderItem> cur_printer_use = order.m_order_items;
|
|
|
|
|
|
|
|
|
|
+ //先计算商品的总数量
|
|
|
|
|
+ int foodNum = 0;
|
|
|
|
|
+
|
|
|
|
|
+ for (std::vector<CWaimaiOrderItem>::iterator it = cur_printer_use.begin(); it != cur_printer_use.end(); it++)
|
|
|
|
|
+ {
|
|
|
|
|
+ std::string quantity = (*it).m_quantity;
|
|
|
|
|
+
|
|
|
|
|
+ foodNum += atoi(quantity.c_str());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
//商品内容
|
|
//商品内容
|
|
|
|
|
+ int curFoodNum = 0;
|
|
|
|
|
+
|
|
|
for (std::vector<CWaimaiOrderItem>::iterator it = cur_printer_use.begin(); it != cur_printer_use.end(); it++)
|
|
for (std::vector<CWaimaiOrderItem>::iterator it = cur_printer_use.begin(); it != cur_printer_use.end(); it++)
|
|
|
{
|
|
{
|
|
|
std::string food_name = (*it).m_food_name;
|
|
std::string food_name = (*it).m_food_name;
|
|
@@ -829,11 +844,15 @@ void CPosPrinter::PrintWaimaiOrderBiaoqian(CWaimaiOrder& order)
|
|
|
|
|
|
|
|
for (int i = 0; i < nQuantity; i++)
|
|
for (int i = 0; i < nQuantity; i++)
|
|
|
{
|
|
{
|
|
|
|
|
+ curFoodNum++;
|
|
|
|
|
+
|
|
|
std::string order_num_info = "外卖 #" + restaurant_number;
|
|
std::string order_num_info = "外卖 #" + restaurant_number;
|
|
|
BIAOQIAN_TEXTOUT(order_num_info, 16, 16, 1, 1);
|
|
BIAOQIAN_TEXTOUT(order_num_info, 16, 16, 1, 1);
|
|
|
|
|
|
|
|
|
|
+ std::string numInfo = curFoodNum + "/" + foodNum;
|
|
|
|
|
+ BIAOQIAN_TEXTOUT(numInfo, 260, 16, 1, 1);
|
|
|
|
|
+
|
|
|
//每行最多显示12个汉字,这里要计算一下换行
|
|
//每行最多显示12个汉字,这里要计算一下换行
|
|
|
- food_name += CLewaimaiString::UnicodeToUTF8(L" ¥") + food_price;
|
|
|
|
|
std::vector<std::string> foodNameVector = HandleBiaoqianFoodname(food_name);
|
|
std::vector<std::string> foodNameVector = HandleBiaoqianFoodname(food_name);
|
|
|
|
|
|
|
|
int nRow = 0;
|
|
int nRow = 0;
|
|
@@ -842,9 +861,14 @@ void CPosPrinter::PrintWaimaiOrderBiaoqian(CWaimaiOrder& order)
|
|
|
BIAOQIAN_TEXTOUT(CLewaimaiString::UTF8ToANSI(*it), 16, 60 + 40 * nRow, 1, 2);
|
|
BIAOQIAN_TEXTOUT(CLewaimaiString::UTF8ToANSI(*it), 16, 60 + 40 * nRow, 1, 2);
|
|
|
|
|
|
|
|
nRow++;
|
|
nRow++;
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //打印价格
|
|
|
|
|
+ std::wstring priceInfo = L"¥" + CLewaimaiString::UTF8ToUnicode(food_price);
|
|
|
|
|
+ BIAOQIAN_TEXTOUT(CLewaimaiString::UnicodeToUTF8(priceInfo), 16, 180, 1, 1);
|
|
|
|
|
|
|
|
- BIAOQIAN_TEXTOUT(order_num, 16, 200, 1, 1);
|
|
|
|
|
|
|
+ //打印订单号
|
|
|
|
|
+ BIAOQIAN_TEXTOUT(order_num, 16, 210, 1, 1);
|
|
|
|
|
|
|
|
BIAOQIAN_PRINT();
|
|
BIAOQIAN_PRINT();
|
|
|
}
|
|
}
|
|
@@ -1200,7 +1224,7 @@ int CPosPrinter::WriteBuf(const char* buf, int len)
|
|
|
FALSE
|
|
FALSE
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- LOG_INFO("Write success " << numread << " bytes");
|
|
|
|
|
|
|
+ //LOG_INFO("Write success " << numread << " bytes");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1228,7 +1252,6 @@ int CPosPrinter::WriteBuf(const char* buf, int len)
|
|
|
**/
|
|
**/
|
|
|
bool CPosPrinter::PortTest(HANDLE hPort)
|
|
bool CPosPrinter::PortTest(HANDLE hPort)
|
|
|
{
|
|
{
|
|
|
- return true;
|
|
|
|
|
//标签打印机的查询状态指令
|
|
//标签打印机的查询状态指令
|
|
|
char chInitCode[2] = { 0x1b, 0x40};
|
|
char chInitCode[2] = { 0x1b, 0x40};
|
|
|
|
|
|