Ver código fonte

发布1.0.2.2,打印改为同步观察一下看看

zhangyang 5 anos atrás
pai
commit
c178436e73

BIN
bin/Win32/Release/lewaimai_pos_windows/dump/2020-03-05-19-59-49.dmp


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

@@ -1 +0,0 @@
-2020-03-05 19:59:49[INFO] - н¨ dump Ŀ¼³É¹¦£¡ [e:\work\code\lewaimai_pos_windows\lewaimai_pos_windows\tool\cexceptiondmp.cpp:22]

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


BIN
bin/Win32/Release/setup/lewaimai_pos_windows_setup_1.0.2.1.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.2.1"
+!define PRODUCT_VERSION "1.0.2.2"
 !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
bin/x64/Release/lewaimai_pos_windows_server_linux/lewaimai_pos_windows_server_linux


BIN
dump/1.0.2.2/lewaimai_pos_windows.exe


BIN
dump/1.0.2.2/lewaimai_pos_windows.iobj


BIN
dump/1.0.2.2/lewaimai_pos_windows.ipdb


BIN
dump/1.0.2.2/lewaimai_pos_windows.pdb


+ 2 - 1
lewaimai_pos_windows/lewaimai_pos_windows.vcxproj

@@ -130,7 +130,7 @@ copy $(ProjectDir)conf\ $(SolutionDir)bin\$(Platform)\$(Configuration)\conf\</Co
       <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
       <AdditionalIncludeDirectories>$(SolutionDir)include;$(ProjectDir)pch</AdditionalIncludeDirectories>
       <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
-      <DisableSpecificWarnings>4099</DisableSpecificWarnings>
+      <DisableSpecificWarnings>4099;4091</DisableSpecificWarnings>
       <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
     </ClCompile>
@@ -142,6 +142,7 @@ copy $(ProjectDir)conf\ $(SolutionDir)bin\$(Platform)\$(Configuration)\conf\</Co
       <IgnoreSpecificDefaultLibraries>LIBCMT</IgnoreSpecificDefaultLibraries>
       <Version>
       </Version>
+      <AdditionalOptions>/ignore:4099 %(AdditionalOptions)</AdditionalOptions>
     </Link>
     <PostBuildEvent>
       <Command>mkdir $(SolutionDir)bin\$(Platform)\$(Configuration)\$(ProjectName)\

+ 0 - 2
lewaimai_pos_windows/network/CMessagePush.cpp

@@ -530,8 +530,6 @@ void CMessagePush::HandleShouyinPrinter()
 
         CPosPrinter printer;
         printer.PrintWaimaiOrderShouyin(order);
-
-		int a = 1;
     }
 
 	AddStopNum();

BIN
lewaimai_pos_windows/resource/lewaimai_pos_windows.aps


BIN
lewaimai_pos_windows/resource/lewaimai_pos_windows.rc


+ 32 - 64
lewaimai_pos_windows/tool/CPosPrinter.cpp

@@ -45,10 +45,12 @@ void CPosPrinter::InitUsb(int usbType)
 
         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);
+        HANDLE hPort = CreateFile(m_usb_devices[i].c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
 
         if(hPort == INVALID_HANDLE_VALUE)
         {
+			LOG_INFO("打开USB端口失败, Port = " << m_usb_devices[i].c_str());
+
             // 打开端口失败
             DWORD error = GetLastError();
 
@@ -65,7 +67,7 @@ void CPosPrinter::InitUsb(int usbType)
             continue;
         }
 
-        LOG_INFO("打开usb端口,准备进行打印机检测! hPort:" << hPort);
+        LOG_INFO("打开usb端口成功,准备进行打印机检测! hPort:" << hPort);
 
         if(PortTest(hPort) == true)
         {
@@ -93,10 +95,12 @@ bool CPosPrinter::InitOneUsb(wstring usb_path)
 		return false;
 	}
 
-    HANDLE hPort = CreateFile(usb_path.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
+    HANDLE hPort = CreateFile(usb_path.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
 
     if(hPort == INVALID_HANDLE_VALUE)
     {
+		LOG_INFO("打开USB端口失败, Port = " << usb_path.c_str());
+
         // 打开端口失败
         DWORD error = GetLastError();
 
@@ -139,10 +143,12 @@ bool CPosPrinter::InitBingkou()
 {
     std::wstring LptStr = L"lpt1";
 
-    HANDLE hPort = CreateFile(LptStr.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
+    HANDLE hPort = CreateFile(LptStr.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
 
     if(hPort == INVALID_HANDLE_VALUE)
     {
+		LOG_INFO("打开并口失败, Port = " << LptStr.c_str());
+
         DWORD error = GetLastError();
 
         if(error == 2)
@@ -254,16 +260,13 @@ void CPosPrinter::InitCom()
 }
 
 /*
- *找到所有可用的小票打印机,包括USB、并口、串口3个类型,注意这里不包含网口
+ *找到所有可用的小票打印机,这里只初始化USB,不包含并口、串口、网口
  *智能识别模式不再自动处理串口,串口的需要人工去选择类型
  **/
 void CPosPrinter::InitShouyin()
 {
     //开始添加usb
     InitUsb();
-
-    //开始添加并口的端口
-    InitBingkou();
 }
 
 /*
@@ -427,6 +430,8 @@ int CPosPrinter::GetPrinterType(wstring vid, wstring pid)
  **/
 void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
 {
+	LOG_INFO("_______________________________开始打印收银小票,订单编号:"<<order.m_order_num.c_str()<<"_________________________");
+
     //设置模式,后面输出数据不会错
     m_type = 1;
 
@@ -905,8 +910,12 @@ void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
 	{
 		m_socket.close();
 	}
+
+	LOG_INFO("_______________________________结束打印收银小票,订单编号:" << order.m_order_num.c_str() << "_________________________");
+	LOG_INFO("                                                                                                              ");
 }
 
+
 void CPosPrinter::PrintWaimaiOrderBiaoqian(CWaimaiOrder& order)
 {
     m_type = 1;
@@ -1314,52 +1323,26 @@ int CPosPrinter::WriteData(string msg)
     return WriteBuf((unsigned char*)msg.c_str(), msg.length());
 }
 
+/*
+ *这个函数只负责把数据拼接到打印缓存里面,不负责实际的发送数据
+ **/
 int CPosPrinter::WriteBuf(const unsigned char* buf, int len)
 {
     if(m_type == 1)
     {
 		//USB、串口、并口,走这里
-        DWORD dwWrite;
-
         for(std::vector<PrinterHandle>::iterator it = m_hPorts.begin(); it != m_hPorts.end(); it++)
         {
             HANDLE hPort = (*it).hPort;
 
-            if((*it).type == 3)
-            {
-                //串口,同步写数据
-                WriteFile(hPort, buf, len, &dwWrite, NULL);
-            }
-            else
-            {
-                //usb和并口,异步写数据
-                OVERLAPPED overlap;
-                memset(&overlap, 0, sizeof(overlap));
-
-                BOOL rc = WriteFile(hPort, buf, len, &dwWrite, &overlap);
-
-                if(rc)
-                {
-                    LOG_INFO("writefile success immediately, handle:" << hPort);
-                }
-                else
-                {
-                    if(GetLastError() == ERROR_IO_PENDING)
-                    {
-                        /*WaitForSingleObject(hPort, 10000);
-
-                        DWORD numread;
-                        rc = GetOverlappedResult(
-                                 hPort,
-                                 &overlap,
-                                 &numread,
-                                 FALSE
-                             );
+            //同步写数据
+			DWORD dwWrite;
 
-                        LOG_INFO("Write success " << numread << " bytes");*/
-                    }
-                }
-            }
+            BOOL ret = WriteFile(hPort, buf, len, &dwWrite, NULL);
+			if (!ret)
+			{
+				LOG_INFO("WriteFile Failed!, hPort:"<<hPort<<", type:"<<(*it).type);
+			}
         }
 
         return 1;
@@ -1376,7 +1359,7 @@ int CPosPrinter::WriteBuf(const unsigned char* buf, int len)
 			LOG_INFO("网口打印机发送消息失败,错误信息:" << e.what());
         }
 
-        return 0;
+        return 1;
     }
 }
 
@@ -1390,34 +1373,19 @@ bool CPosPrinter::PortTest(HANDLE hPort)
 
     DWORD dwWrite;
 
-    OVERLAPPED overlap;
-    memset(&overlap, 0, sizeof(overlap));
-
-    BOOL rc = WriteFile(hPort, chInitCode, 2, &dwWrite, &overlap);
+    BOOL rc = WriteFile(hPort, chInitCode, 2, &dwWrite, NULL);
 
     if(rc)
     {
-        LOG_INFO("writefile success immediately, handle:" << hPort);
+        LOG_INFO("porttest success, handle:" << hPort);
 
         return true;
     }
     else
     {
-        if(GetLastError() == ERROR_IO_PENDING)
-        {
-            DWORD ret = WaitForSingleObject(hPort, 1000);
+		LOG_INFO("porttest fail, handle:" << hPort);
 
-            if(ret == 0)
-            {
-                LOG_INFO("printer is connect, handle:" << hPort);
-
-                return true;
-            }
-            else
-            {
-                LOG_INFO("printer is not connect, handle:" << hPort);
-            }
-        }
+		return true;
     }
 
     return false;