Просмотр исходного кода

标签打印机没问题了,release包打好了

张洋 6 лет назад
Родитель
Сommit
0aadaad273

BIN
bin/Win32/Debug/lewaimai_pos_windows.zip


BIN
bin/Win32/Release/lewaimai_pos_windows/DuiLib_u.dll


BIN
bin/Win32/Release/lewaimai_pos_windows/db/pos.db


+ 0 - 0
bin/Win32/Release/lewaimai_pos_windows/log/pos.log


+ 0 - 0
bin/Win32/Release/lewaimai_pos_windows/log/pos_error.log


BIN
bin/Win32/Release/lewaimai_pos_windows/log4cplusU.dll


BIN
bin/Win32/Release/lewaimai_pos_windows/skin/skin.lwm


BIN
bin/Win32/Release/setup/lewaimai_pos_windows_setup_1.0.1.4.exe


+ 1 - 1
bin/Win32/Release/setup/乐外卖接单软件安装脚本.nsi

@@ -2,7 +2,7 @@
 
 ; HM NIS Edit Wizard helper defines
 !define PRODUCT_NAME "乐外卖接单软件"
-!define PRODUCT_VERSION "1.0.1.4"
+!define PRODUCT_VERSION "1.0.1.5"
 !define PRODUCT_PUBLISHER "深圳市迅享科技有限公司"
 !define PRODUCT_WEB_SITE "https://www.lewaimai.com"
 !define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\${PRODUCT_NAME}.exe"

BIN
dll/release/DuiLib_u.dll


BIN
dll/release/log4cplusU.dll


+ 1 - 1
lewaimai_pos_windows/lewaimai_pos_windows.vcxproj

@@ -179,7 +179,7 @@ copy $(SolutionDir)res\icon\ $(SolutionDir)bin\$(Platform)\$(Configuration)\$(Pr
       <OptimizeReferences>true</OptimizeReferences>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <AdditionalLibraryDirectories>$(SolutionDir)lib\release</AdditionalLibraryDirectories>
-      <AdditionalDependencies>dbghelp.lib;winmm.lib;setupapi.lib;AdvAPI32.lib;Shell32.lib;user32.lib;kernel32.lib;Gdi32.lib;sqlite3.lib;libcurl.lib;DuiLib_u.lib;log4cplusU.lib;version.lib;libboost_date_time-vc141-mt-s-x32-1_70.lib;libboost_regex-vc141-mt-s-x32-1_70.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>dbghelp.lib;winmm.lib;setupapi.lib;AdvAPI32.lib;Shell32.lib;user32.lib;kernel32.lib;Gdi32.lib;sqlite3.lib;libcurl.lib;DuiLib_u.lib;log4cplusU.lib;version.lib;libboost_date_time-vc141-mt-s-x32-1_70.lib;libboost_regex-vc141-mt-s-x32-1_70.lib;libqrencode.lib;%(AdditionalDependencies)</AdditionalDependencies>
     </Link>
     <PostBuildEvent>
       <Command>mkdir $(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName)\

+ 0 - 2
lewaimai_pos_windows/network/CMessagePush.cpp

@@ -548,8 +548,6 @@ void CMessagePush::HandleBiaoqianPrinter()
 
 		CPosPrinter printer;
 		printer.PrintWaimaiOrderBiaoqian(order);
-
-		Sleep(3000);
 	}
 
 	AddStopNum();

BIN
lewaimai_pos_windows/resource/lewaimai_pos_windows.aps


BIN
lewaimai_pos_windows/resource/lewaimai_pos_windows.rc


+ 78 - 24
lewaimai_pos_windows/tool/CPosPrinter.cpp

@@ -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 };

+ 3 - 2
lewaimai_pos_windows/tool/CPosPrinter.h

@@ -35,13 +35,13 @@ public:
 	std::vector<std::wstring> getUsbDevices();
 
 private:
-	void InitBingkou();
+	bool InitBingkou();
 	void InitCom();
 
 	void InitShouyin();
 
 	//打开某一个指定的usb端口
-	void InitOneUsb(wstring usb_path);
+	bool InitOneUsb(wstring usb_path);
 
 	//usb打印机的类型 1:收银小票打印机 2:标签打印机
 	int GetDevicePath(LPGUID lpGuid, int usbType);
@@ -75,6 +75,7 @@ private:
 	void BIAOQIAN_Reset();
 	void BIAOQIAN_FORMFEED();
 	void BIAOQIAN_TEXTOUT(std::string content, int x, int y, int x_multiplication, int y_multiplication);
+	std::string BIAOQIAN_TEXTGet(std::string content, int x, int y, int x_multiplication, int y_multiplication);
 	void BIAOQIAN_PRINT();
 	void BIAOQIAN_CLS();