|
|
@@ -33,6 +33,16 @@ void CPosPrinter::InitUsb(int usbType)
|
|
|
|
|
|
while(i < nDevice)
|
|
|
{
|
|
|
+ std::string setting_biaoqian_printer_usb = CSetting::GetParam("setting_biaoqian_printer_usb");
|
|
|
+ std::wstring ws_setting_biaoqian_printer_usb = CLewaimaiString::UTF8ToUnicode(setting_biaoqian_printer_usb);
|
|
|
+
|
|
|
+ if (CSetting::GetParam("setting_is_new_waimai_biaoqian_printer") == "1" && ws_setting_biaoqian_printer_usb == m_usb_devices[i])
|
|
|
+ {
|
|
|
+ //碰到了一个标签打印机
|
|
|
+ i++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
LOG_INFO("准备打开端口 Port = " << m_usb_devices[i].c_str());
|
|
|
|
|
|
HANDLE hPort = CreateFile(m_usb_devices[i].c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
|
|
|
@@ -76,8 +86,13 @@ void CPosPrinter::InitUsb(int usbType)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void CPosPrinter::InitOneUsb(wstring usb_path)
|
|
|
+bool CPosPrinter::InitOneUsb(wstring usb_path)
|
|
|
{
|
|
|
+ if (usb_path == L"")
|
|
|
+ {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
HANDLE hPort = CreateFile(usb_path.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
|
|
|
|
|
|
if(hPort == INVALID_HANDLE_VALUE)
|
|
|
@@ -94,6 +109,8 @@ void CPosPrinter::InitOneUsb(wstring usb_path)
|
|
|
{
|
|
|
LOG_INFO("usb端口被占用!");
|
|
|
}
|
|
|
+
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
LOG_INFO("打开usb端口,准备进行打印机检测! hPort:" << hPort);
|
|
|
@@ -111,10 +128,14 @@ void CPosPrinter::InitOneUsb(wstring usb_path)
|
|
|
{
|
|
|
//端口打印机没有连接,那么就直接关闭掉并口,避免占用
|
|
|
CloseHandle(hPort);
|
|
|
+
|
|
|
+ return false;
|
|
|
}
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
-void CPosPrinter::InitBingkou()
|
|
|
+bool CPosPrinter::InitBingkou()
|
|
|
{
|
|
|
std::wstring LptStr = L"lpt1";
|
|
|
|
|
|
@@ -133,6 +154,8 @@ void CPosPrinter::InitBingkou()
|
|
|
{
|
|
|
LOG_INFO("并口被占用!");
|
|
|
}
|
|
|
+
|
|
|
+ return false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -152,8 +175,12 @@ void CPosPrinter::InitBingkou()
|
|
|
{
|
|
|
//并口打印机没有连接,那么就直接关闭掉并口,避免占用
|
|
|
CloseHandle(hPort);
|
|
|
+
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
void CPosPrinter::InitCom()
|
|
|
@@ -228,6 +255,7 @@ void CPosPrinter::InitCom()
|
|
|
|
|
|
/*
|
|
|
*找到所有可用的小票打印机,包括USB、并口、串口3个类型,注意这里不包含网口
|
|
|
+ *智能识别模式不再自动处理串口,串口的需要人工去选择类型
|
|
|
**/
|
|
|
void CPosPrinter::InitShouyin()
|
|
|
{
|
|
|
@@ -236,9 +264,6 @@ void CPosPrinter::InitShouyin()
|
|
|
|
|
|
//开始添加并口的端口
|
|
|
InitBingkou();
|
|
|
-
|
|
|
- //智能识别模式不再自动处理串口,串口的需要人工去选择类型
|
|
|
- //InitCom();
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -393,6 +418,11 @@ int CPosPrinter::GetPrinterType(wstring vid, wstring pid)
|
|
|
//佳博标签打印机
|
|
|
return 2;
|
|
|
}
|
|
|
+ else if (vid == L"1fc9" && pid == L"2016")
|
|
|
+ {
|
|
|
+ //芯烨XP-365B
|
|
|
+ return 2;
|
|
|
+ }
|
|
|
|
|
|
return 1;
|
|
|
}
|
|
|
@@ -416,11 +446,19 @@ void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
|
|
|
std::string printer_usb = CSetting::GetParam("setting_printer_usb");
|
|
|
std::wstring ws_printer_usb = CLewaimaiString::UTF8ToUnicode(printer_usb);
|
|
|
|
|
|
- InitOneUsb(ws_printer_usb);
|
|
|
+ bool ret = InitOneUsb(ws_printer_usb);
|
|
|
+ if (ret == false)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
else if(printer_leixing == "bingkou")
|
|
|
{
|
|
|
- InitBingkou();
|
|
|
+ bool ret = InitBingkou();
|
|
|
+ if (ret == false)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
else if(printer_leixing == "chuankou")
|
|
|
{
|
|
|
@@ -805,7 +843,7 @@ void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
|
|
|
|
|
|
//POS_OutQRCode(order_no);
|
|
|
|
|
|
- POS_OutBmp(L"D:\\200.jpg");
|
|
|
+ //POS_OutBmp(L"D:\\200.jpg");
|
|
|
|
|
|
//走纸几行再切
|
|
|
POS_FeedLine();
|
|
|
@@ -837,8 +875,8 @@ void CPosPrinter::PrintWaimaiOrderBiaoqian(CWaimaiOrder& order)
|
|
|
//连接usb端口
|
|
|
InitOneUsb(ws_printer_usb);
|
|
|
|
|
|
- //初始化标签打印机
|
|
|
- BIAOQIAN_Reset();
|
|
|
+ //初始化标签打印机
|
|
|
+ BIAOQIAN_Reset();
|
|
|
|
|
|
std::vector<CWaimaiOrderItem> cur_printer_use = order.m_order_items;
|
|
|
|
|
|
@@ -866,15 +904,17 @@ void CPosPrinter::PrintWaimaiOrderBiaoqian(CWaimaiOrder& order)
|
|
|
|
|
|
for(int i = 0; i < nQuantity; i++)
|
|
|
{
|
|
|
+ std::string textData = "";
|
|
|
+
|
|
|
curFoodNum++;
|
|
|
|
|
|
std::string restaurant_number = order.m_restaurant_number;
|
|
|
std::string order_num_info = "外卖 #" + CLewaimaiString::UTF8ToANSI(restaurant_number);
|
|
|
- BIAOQIAN_TEXTOUT(order_num_info, 16, 16, 1, 1);
|
|
|
+ textData += BIAOQIAN_TEXTGet(order_num_info, 16, 24, 1, 1);
|
|
|
|
|
|
//打印份数
|
|
|
std::string numInfo = to_string(curFoodNum) + "/" + to_string(foodNum);
|
|
|
- BIAOQIAN_TEXTOUT(numInfo, 160, 16, 1, 1);
|
|
|
+ textData += BIAOQIAN_TEXTGet(numInfo, 160, 24, 1, 1);
|
|
|
|
|
|
//每行最多显示12个汉字,这里要计算一下换行(要先转成ANSI格式)
|
|
|
std::string handle_food_name = CLewaimaiString::UTF8ToANSI(food_name);
|
|
|
@@ -899,11 +939,11 @@ void CPosPrinter::PrintWaimaiOrderBiaoqian(CWaimaiOrder& order)
|
|
|
|
|
|
if(is_big_name)
|
|
|
{
|
|
|
- BIAOQIAN_TEXTOUT(*it, 16, 56 + 64 * nRow, 1, 2);
|
|
|
+ textData += BIAOQIAN_TEXTGet(*it, 16, 64 + 64 * nRow, 1, 2);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- BIAOQIAN_TEXTOUT(*it, 16, 56 + 32 * nRow, 1, 1);
|
|
|
+ textData += BIAOQIAN_TEXTGet(*it, 16, 64 + 32 * nRow, 1, 1);
|
|
|
}
|
|
|
|
|
|
nRow++;
|
|
|
@@ -911,15 +951,17 @@ void CPosPrinter::PrintWaimaiOrderBiaoqian(CWaimaiOrder& order)
|
|
|
|
|
|
//打印价格
|
|
|
std::string priceInfo = CLewaimaiString::UTF8ToANSI(food_price) + "元";
|
|
|
- BIAOQIAN_TEXTOUT(priceInfo, 16, 180, 1, 1);
|
|
|
+ textData += BIAOQIAN_TEXTGet(priceInfo, 16, 188, 1, 1);
|
|
|
|
|
|
//打印订单号
|
|
|
std::string order_num = "订单号:" + CLewaimaiString::UTF8ToANSI(order.m_order_num);
|
|
|
- BIAOQIAN_TEXTOUT(order_num, 16, 210, 1, 1);
|
|
|
+ textData += BIAOQIAN_TEXTGet(order_num, 16, 218, 1, 1);
|
|
|
|
|
|
- BIAOQIAN_PRINT();
|
|
|
+ WriteData(textData);
|
|
|
|
|
|
- BIAOQIAN_CLS();
|
|
|
+ BIAOQIAN_PRINT();
|
|
|
+
|
|
|
+ BIAOQIAN_CLS();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1243,9 +1285,7 @@ int CPosPrinter::WriteBuf(const unsigned char* buf, int len)
|
|
|
if((*it).type == 3)
|
|
|
{
|
|
|
//串口,同步写数据
|
|
|
- //LOG_INFO("before com writefile handle:" << hPort);
|
|
|
WriteFile(hPort, buf, len, &dwWrite, NULL);
|
|
|
- //LOG_INFO("after com writefile handle:" << hPort);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -1263,9 +1303,7 @@ int CPosPrinter::WriteBuf(const unsigned char* buf, int len)
|
|
|
{
|
|
|
if(GetLastError() == ERROR_IO_PENDING)
|
|
|
{
|
|
|
- //LOG_INFO("Request queued, waiting... handle:" << hPort);
|
|
|
- WaitForSingleObject(hPort, 3000);
|
|
|
- //LOG_INFO("Request completed, handle:" << hPort);
|
|
|
+ WaitForSingleObject(hPort, 1000);
|
|
|
|
|
|
//计算写入了多少字节的数据
|
|
|
DWORD numread;
|
|
|
@@ -1668,7 +1706,7 @@ void CPosPrinter::BIAOQIAN_Reset()
|
|
|
std::string gap = "GAP 2 mm,0 mm";
|
|
|
gap += endTag;
|
|
|
|
|
|
- std::string speed = "SPEED 2.0";
|
|
|
+ std::string speed = "SPEED 4.0";
|
|
|
speed += endTag;
|
|
|
|
|
|
std::string density = "DENSITY 12";
|
|
|
@@ -1720,6 +1758,22 @@ void CPosPrinter::BIAOQIAN_TEXTOUT(std::string content, int x, int y, int x_mult
|
|
|
WriteData(text);
|
|
|
}
|
|
|
|
|
|
+std::string CPosPrinter::BIAOQIAN_TEXTGet(std::string content, int x, int y, int x_multiplication, int y_multiplication)
|
|
|
+{
|
|
|
+ char endTag[3] = { 0x0d, 0x0a, 0x00 };
|
|
|
+
|
|
|
+ string text = "TEXT ";
|
|
|
+
|
|
|
+ text += to_string(x) + "," + to_string(y) + ",";
|
|
|
+ text += "\"TSS24.BF2\",";
|
|
|
+ text += to_string(0) + ",";
|
|
|
+ text += to_string(x_multiplication) + "," + to_string(y_multiplication) + ",";
|
|
|
+ text += "\"" + content + "\"";
|
|
|
+ text += endTag;
|
|
|
+
|
|
|
+ return text;
|
|
|
+}
|
|
|
+
|
|
|
void CPosPrinter::BIAOQIAN_PRINT()
|
|
|
{
|
|
|
char endTag[3] = { 0x0d, 0x0a, 0x00 };
|