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

暂时还没搞定检测USB打印机的问题

zhangyang 6 лет назад
Родитель
Сommit
a5c642a779

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


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

@@ -0,0 +1,2 @@
+2019-07-25 21:04:18[INFO] - folderPath:E:\work\code\lewaimai_pos_windows\bin\Win32\Release\lewaimai_pos_windows\db,没有找到对应的目录,即将创建 [e:\work\code\lewaimai_pos_windows\lewaimai_pos_windows\tool\csqlite3.cpp:11]
+2019-07-25 21:04:18[INFO] - 新建 db 目录成功! [e:\work\code\lewaimai_pos_windows\lewaimai_pos_windows\tool\csqlite3.cpp:18]

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


BIN
bin/Win32/Release/setup/lewaimai_pos_windows_setup_1.0.1.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.1.1"
+!define PRODUCT_VERSION "1.0.1.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
lewaimai_pos_windows/resource/lewaimai_pos_windows.aps


BIN
lewaimai_pos_windows/resource/lewaimai_pos_windows.rc


+ 38 - 9
lewaimai_pos_windows/tool/CPosPrinter.cpp

@@ -48,7 +48,7 @@ bool CPosPrinter::InitShouyin()
         Port = szDevicePath[i++];
         LOG_INFO("准备打开端口 Port = " << Port);
 
-        HANDLE hPort = CreateFile(Port, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
+        HANDLE hPort = CreateFile(Port, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
 
         if(hPort == INVALID_HANDLE_VALUE)
         {
@@ -348,10 +348,6 @@ int CPosPrinter::GetPrinterType(wstring vid, wstring pid)
 		//佳博标签打印机
 		return 2;
 	}
-	else if (vid == L"0fe6" && pid == L"811e")
-	{
-		return 2;
-	}
 
 	return 1;
 }
@@ -1063,6 +1059,8 @@ int CPosPrinter::WriteBuf(const char* buf, int len)
                         //LOG_INFO("Request queued, waiting... handle:" << hPort);
                         WaitForSingleObject(hPort, 5000);
                         //LOG_INFO("Request completed, handle:" << hPort);
+
+						//计算写入了多少字节的数据
                         DWORD numread;
                         rc = GetOverlappedResult(
                                  hPort,
@@ -1097,15 +1095,14 @@ int CPosPrinter::WriteBuf(const char* buf, int len)
  **/
 bool CPosPrinter::PortTest(HANDLE hPort)
 {
-    char chInitCode[] = "\x1B\x40";
+    char chInitCode[3] = { 0x1D, 0x49, 0x42 };
 
     DWORD dwWrite;
 
     OVERLAPPED overlap;
     memset(&overlap, 0, sizeof(overlap));
 
-    BOOL rc = WriteFile(hPort, chInitCode, (DWORD)2L, &dwWrite, &overlap);
-
+    BOOL rc = WriteFile(hPort, chInitCode, 3, &dwWrite, &overlap);
     if(rc)
     {
         LOG_INFO("writefile success immediately, handle:" << hPort);
@@ -1117,10 +1114,42 @@ bool CPosPrinter::PortTest(HANDLE hPort)
         if(GetLastError() == ERROR_IO_PENDING)
         {
             DWORD ret = WaitForSingleObject(hPort, 500);
-
             if(ret == 0)
             {
                 LOG_INFO("printer is connect, handle:" << hPort);
+
+				char chBuffer[2];
+				memset(chBuffer, 0, 2);
+
+				OVERLAPPED overlap2 = { 0 };
+
+				overlap2.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);;//创建时无信号的事件
+
+				DWORD dwReadSize = 0;
+				BOOL bResult = ReadFile(hPort, chBuffer, 1, &dwReadSize, &overlap2);
+				if (!bResult)
+				{
+					if (ERROR_IO_PENDING == GetLastError()) //函数返回ERROR_IO_PENDING,表明USB正在进行读操作
+					{
+						WaitForSingleObject(overlap2.hEvent, 2000);
+						DWORD numread;
+						BOOL rc = GetOverlappedResult(hPort, &overlap2, &numread, FALSE);
+
+						LOG_INFO("numread:" << numread);
+
+						LOG_INFO("buffer:" << chBuffer);
+					}
+					else
+					{
+						int a = GetLastError();
+						int b = a;
+					}
+				}
+				else
+				{
+					int a = 1;
+				}
+
                 return true;
             }
             else