Przeglądaj źródła

继续优化并口打印

zhangyang 6 lat temu
rodzic
commit
4e1d3e7805

BIN
bin/Win32/Debug/lewaimai_pos_windows.zip


BIN
bin/Win32/Release/lewaimai_pos_windows/lewaimai_pos_windows.exe


BIN
bin/Win32/Release/setup/lewaimai_pos_windows_setup_1.0.0.7.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.0.7"
+!define PRODUCT_VERSION "1.0.0.8"
 !define PRODUCT_PUBLISHER "深圳市迅享科技有限公司"
 !define PRODUCT_WEB_SITE "https://www.lewaimai.com"
 !define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\${PRODUCT_NAME}.exe"

+ 1 - 1
lewaimai_pos_windows/network/CMessagePush.cpp

@@ -267,7 +267,7 @@ void CMessagePush::ReceiveMessage()
 		catch (std::exception& e)
 		{
 			std::string err = e.what();
-			LOG_INFO("read err:" << err.c_str());
+			//LOG_INFO("read err:" << err.c_str());
 
 			//如果这里异常了,说明socket失效了,等2秒重新读
 			CSystem::my_sleep(2);

BIN
lewaimai_pos_windows/resource/lewaimai_pos_windows.aps


BIN
lewaimai_pos_windows/resource/lewaimai_pos_windows.rc


+ 275 - 203
lewaimai_pos_windows/tool/CPosPrinter.cpp

@@ -21,29 +21,34 @@ CPosPrinter::~CPosPrinter()
 bool CPosPrinter::InitShouyin()
 {
     //先找USB的
+
     //设备路径
     TCHAR* szDevicePath[MAX_DEVICE];
+
     //设置中文字符
     setlocale(LC_CTYPE, "chs");
+
     TCHAR* Port = NULL;
 
     //分配需要的空间
     for(int i = 0; i < MAX_DEVICE; i++)
     {
-        szDevicePath[i] = new TCHAR[256];
+        szDevicePath[i] = new TCHAR[MAX_PATH];
     }
 
     //取设备路径
     int nDevice = GetDevicePath((LPGUID)&USB_GUID, szDevicePath);
-    LOG_INFO("USB nDevice:" << nDevice);
-    int i = 0;
+    LOG_INFO("可用的USB打印机数量:" << nDevice);
 
     //添加usb端口
+    int i = 0;
+
     while(i < nDevice)
     {
         Port = szDevicePath[i++];
-        LOG_INFO(L"device.Port = " << Port);
-        HANDLE hPort = CreateFile(Port, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
+        LOG_INFO("device.Port = " << Port);
+
+        HANDLE hPort = CreateFile(Port, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
 
         if(hPort == INVALID_HANDLE_VALUE)
         {
@@ -52,40 +57,65 @@ bool CPosPrinter::InitShouyin()
             continue;
         }
 
-        LOG_INFO("open port success usb, handle" << hPort);
+        //LOG_INFO("open port success usb, handle" << hPort);
+
         //把当前发现的保存下来
-        m_hPorts.push_back(hPort);
+        PrinterHandle newHandle;
+        newHandle.hPort = hPort;
+        newHandle.type = 1;
+
+        m_hPorts.push_back(newHandle);
     }
 
     //开始添加并口的端口
     std::wstring LptStr = L"lpt1";
+
     HANDLE hPort = CreateFile(LptStr.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
 
     if(hPort == INVALID_HANDLE_VALUE)
     {
         DWORD error = GetLastError();
-        LOG_INFO("lpt error:" << error);
+        //LOG_INFO("lpt error:" << error);
 
         if(error == 2)
         {
             //没有指定的文件
-            LOG_INFO("no lpt1!");
+            LOG_INFO("本机器没有并口!");
         }
+		else if (error == 5)
+		{
+			LOG_INFO("并口被占用!");
+		}
     }
     else
     {
         //这个表示并口可以使用
-        LOG_INFO("lpt success, handle:" << hPort);
-        m_hPorts.push_back(hPort);
+        LOG_INFO("找到并口,准备进行打印机检测!");
+
+		if (lptTest(hPort) == true)
+		{
+			//并口测试连通,保存起来
+			PrinterHandle newHandle;
+			newHandle.hPort = hPort;
+			newHandle.type = 2;
+
+			m_hPorts.push_back(newHandle);
+		}
+		else
+		{
+			//并口打印机没有连接,那么就直接关闭掉并口,避免占用
+			CloseHandle(hPort);
+		}
     }
 
     //开始添加串口
-    int comNum = 9;
+    int comNum = 10;
 
-    for(int i = 1; i <= 9; i++)
+    for(int i = 1; i <= 10; i++)
     {
         std::wstring com2Str = L"com" + CLewaimaiString::ANSIToUnicode(to_string(i));
-        hPort = CreateFile(com2Str.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
+
+        hPort = CreateFile(com2Str.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
 
         if(hPort == INVALID_HANDLE_VALUE)
         {
@@ -100,30 +130,187 @@ bool CPosPrinter::InitShouyin()
         }
         else
         {
+            LOG_INFO(com2Str.c_str() << " success, handle:" << hPort);
+
             //扎到了可用的串口,设置串口波特率
             DCB dcb;
             dcb.DCBlength = sizeof(dcb);
             GetCommState(hPort, &dcb);
+
             //佳博的串口打印机,默认是这个波特率
             dcb.BaudRate = 19200;
 
             if(!SetCommState(hPort, &dcb))
             {
                 LOG_INFO("set baudRate failed!");
+				continue;
             }
 
-            m_hPorts.push_back(hPort);
-            LOG_INFO(com2Str.c_str() << " success, handle:" << hPort);
+            //设置端口缓冲
+            SetupComm(hPort, 1024, 1024);
+
+            //设定通讯端口超时参数
+            COMMTIMEOUTS tmouts;
+            tmouts.ReadIntervalTimeout = 100;
+            tmouts.ReadTotalTimeoutMultiplier = 100;
+            tmouts.ReadTotalTimeoutConstant = 100;
+            tmouts.WriteTotalTimeoutConstant = 100;
+            tmouts.WriteTotalTimeoutMultiplier = 100;
+            SetCommTimeouts(hPort, &tmouts);
+
+            //清除通讯端口缓存
+            PurgeComm(hPort, PURGE_TXCLEAR | PURGE_RXCLEAR | PURGE_TXABORT | PURGE_RXABORT);
+
+			//保存端口
+            PrinterHandle newHandle;
+            newHandle.hPort = hPort;
+            newHandle.type = 3;
+
+            m_hPorts.push_back(newHandle);
         }
     }
 
     return true;
 }
 
+////////////////////////////////////////////////////////////////////////////////////////////////////////
+//获取CreateFile的USB端口号
+////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+// 根据GUID获得设备路径
+// lpGuid: GUID指针
+// pszDevicePath: 设备路径指针的指针,用于返回找到的路径
+// 返回: 成功得到的设备路径个数,可能不止1个
+int CPosPrinter::GetDevicePath(LPGUID lpGuid, LPTSTR* pszDevicePath)
+{
+    HDEVINFO hDevInfoSet;
+    SP_DEVINFO_DATA spDevInfoData;
+    SP_DEVICE_INTERFACE_DATA ifData;
+    PSP_DEVICE_INTERFACE_DETAIL_DATA pDetail;
+    int nCount;
+    int nTotle;
+    BOOL bResult;
+
+    //这2个字符串,用于根据usb的名字对比是否为打印机设备
+    wstring strUSBPrint = TEXT("USB 打印支持");
+
+	//xp上是英文
+    wstring strUSBPrint_EN = L"USB Printing Support";
+
+    // 取得一个该GUID相关的设备信息集句柄
+    hDevInfoSet = ::SetupDiGetClassDevs(lpGuid,     // class GUID
+                                        NULL,                    // 无关键字
+                                        NULL,                    // 不指定父窗口句柄
+                                        DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);    // 目前存在的设备
+
+	// 失败...
+    if(hDevInfoSet == INVALID_HANDLE_VALUE)
+    {
+        LOG_INFO("SetupDiGetClassDevs failed \r\n");
+        return 0;
+    }
+
+    // 申请设备接口数据空间
+    pDetail = (PSP_DEVICE_INTERFACE_DETAIL_DATA)::GlobalAlloc(LMEM_ZEROINIT, INTERFACE_DETAIL_SIZE);
+    pDetail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
+    nTotle = -1;
+    nCount = 0;
+    bResult = TRUE;
+
+    // 设备序号=0,1,2... 逐一测试设备接口,到失败为止
+    while(bResult)
+    {
+        nTotle++;
+        spDevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
+
+        // 枚举符合该GUID的设备接口
+        bResult = ::SetupDiEnumDeviceInfo(
+                      hDevInfoSet,     // 设备信息集句柄
+                      (ULONG)nTotle,   // 设备信息集里的设备序号
+                      &spDevInfoData);        // 设备接口信息
+
+        if(bResult)
+        {
+            DWORD DataT;
+            TCHAR buf[MAX_PATH] = { 0 };
+            DWORD nSize = 0;
+
+            // get Friendly Name or Device Description
+            if(SetupDiGetDeviceRegistryProperty(hDevInfoSet, &spDevInfoData,
+                                                SPDRP_FRIENDLYNAME, &DataT, (PBYTE)buf, sizeof(buf), &nSize))
+            {
+            }
+            else if(SetupDiGetDeviceRegistryProperty(hDevInfoSet, &spDevInfoData,
+                    SPDRP_DEVICEDESC, &DataT, (PBYTE)buf, sizeof(buf), &nSize))
+            {
+            }
+            else
+            {
+                lstrcpy(buf, _T("Unknown"));
+            }
+
+            wstring ws_buf = buf;
+
+            //是否是要找的设备类型
+            if(ws_buf != strUSBPrint && ws_buf != strUSBPrint_EN)
+            {
+                LOG_INFO("not good usb, buf:" << CLewaimaiString::UnicodeToANSI(ws_buf).c_str());
+                continue;
+            }
+
+            LOG_INFO("good usb, buf:" << CLewaimaiString::UnicodeToANSI(ws_buf).c_str());
+            ifData.cbSize = sizeof(ifData);
+
+            // 枚舉符合該GUID的設備接口
+            bResult = ::SetupDiEnumDeviceInterfaces(
+                          hDevInfoSet,     // 設備信息集句柄
+                          NULL,            // 不需額外的設備描述
+                          lpGuid,          // GUID
+                          (ULONG)nTotle,   // 設備信息集里的設備序號
+                          &ifData);        // 設備接口信息
+
+            if(bResult)
+            {
+                // 取得该设备接口的细节(设备路径)
+                bResult = SetupDiGetInterfaceDeviceDetail(
+                              hDevInfoSet,    // 设备信息集句柄
+                              &ifData,        // 设备接口信息
+                              pDetail,        // 设备接口细节(设备路径)
+                              INTERFACE_DETAIL_SIZE,    // 输出缓冲区大小
+                              NULL,           // 不需计算输出缓冲区大小(直接用设定值)
+                              NULL);          // 不需额外的设备描述
+
+                if(bResult)
+                {
+                    // 复制设备路径到输出缓冲区
+                    ::_tcscpy_s(pszDevicePath[nCount], 256, pDetail->DevicePath);
+
+                    // 调整计数值
+                    nCount++;
+
+                    //LOG_INFO("Cnt = " << nCount << ",pDetail->DevicePath =" << pDetail->DevicePath);
+                }
+            }
+        }
+        else
+        {
+            //LOG_INFO("SetupDiEnumDeviceInfo FAILED!@");
+        }
+    }
+
+    // 释放设备接口数据空间
+    ::GlobalFree(pDetail);
+
+    // 关闭设备信息集句柄
+    ::SetupDiDestroyDeviceInfoList(hDevInfoSet);
+    return nCount;
+}
+
 void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
 {
     //设置模式,后面输出数据不会错
     m_type = 1;
+
     //初始化收银打印机的链接
     bool ret = InitShouyin();
 
@@ -473,9 +660,9 @@ void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
     }
 
     //关闭设备
-    for(std::vector<HANDLE>::iterator it = m_hPorts.begin(); it != m_hPorts.end(); it++)
+    for(std::vector<PrinterHandle>::iterator it = m_hPorts.begin(); it != m_hPorts.end(); it++)
     {
-        CloseHandle(*it);
+        CloseHandle((*it).hPort);
     }
 }
 
@@ -719,161 +906,52 @@ void CPosPrinter::PrintWaimaiOrderChufang(CWaimaiOrder& order)
     }
 }
 
-////////////////////////////////////////////////////////////////////////////////////////////////////////
-//获取CreateFile的USB端口号
-////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-// 根据GUID获得设备路径
-// lpGuid: GUID指针
-// pszDevicePath: 设备路径指针的指针,用于返回找到的路径
-// 返回: 成功得到的设备路径个数,可能不止1个
-int CPosPrinter::GetDevicePath(LPGUID lpGuid, LPTSTR* pszDevicePath)
+int CPosPrinter::WriteData(string msg)
 {
-    HDEVINFO hDevInfoSet;
-    SP_DEVINFO_DATA spDevInfoData;
-    SP_DEVICE_INTERFACE_DATA ifData;
-    PSP_DEVICE_INTERFACE_DETAIL_DATA pDetail;
-    int nCount;
-    int nTotle;
-    BOOL bResult;
-    //这2个字符串,用于根据usb的名字对比是否为打印机设备
-    wstring strUSBPrint = TEXT("USB 打印支持");
-    wstring strUSBPrint_EN = L"USB Printing Support";
-    // 取得一个该GUID相关的设备信息集句柄
-    hDevInfoSet = ::SetupDiGetClassDevs(lpGuid,     // class GUID
-                                        NULL,                    // 无关键字
-                                        NULL,                    // 不指定父窗口句柄
-                                        DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);    // 目前存在的设备
-
-    // 失败...
-    if(hDevInfoSet == INVALID_HANDLE_VALUE)
-    {
-        LOG_INFO("SetupDiGetClassDevs failed \r\n");
-        return 0;
-    }
-
-    // 申请设备接口数据空间
-    pDetail = (PSP_DEVICE_INTERFACE_DETAIL_DATA)::GlobalAlloc(LMEM_ZEROINIT, INTERFACE_DETAIL_SIZE);
-    pDetail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
-    nTotle = -1;
-    nCount = 0;
-    bResult = TRUE;
-
-    // 设备序号=0,1,2... 逐一测试设备接口,到失败为止
-    while(bResult)
-    {
-        nTotle++;
-        spDevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
-        // 枚举符合该GUID的设备接口
-        bResult = ::SetupDiEnumDeviceInfo(
-                      hDevInfoSet,     // 设备信息集句柄
-                      (ULONG)nTotle,   // 设备信息集里的设备序号
-                      &spDevInfoData);        // 设备接口信息
-
-        if(bResult)
-        {
-            DWORD DataT;
-            TCHAR buf[MAX_PATH] = {0};
-            DWORD nSize = 0;
-
-            // get Friendly Name or Device Description
-            if(SetupDiGetDeviceRegistryProperty(hDevInfoSet, &spDevInfoData,
-                                                SPDRP_FRIENDLYNAME, &DataT, (PBYTE)buf, sizeof(buf), &nSize))
-            {
-            }
-            else if(SetupDiGetDeviceRegistryProperty(hDevInfoSet, &spDevInfoData,
-                    SPDRP_DEVICEDESC, &DataT, (PBYTE)buf, sizeof(buf), &nSize))
-            {
-            }
-            else
-            {
-                lstrcpy(buf, _T("Unknown"));
-            }
-
-            wstring ws_buf = buf;
-            LOG_INFO("buf:" << CLewaimaiString::UnicodeToANSI(ws_buf).c_str());
-
-            //是否是要找的设备类型
-            if(ws_buf != strUSBPrint && ws_buf != strUSBPrint_EN)
-            {
-                LOG_INFO("not found usb, buf:" << CLewaimaiString::UnicodeToANSI(ws_buf).c_str());
-                continue;
-            }
-
-            LOG_INFO("found usb, buf:" << CLewaimaiString::UnicodeToANSI(ws_buf).c_str());
-            ifData.cbSize = sizeof(ifData);
-            // 枚舉符合該GUID的設備接口
-            bResult = ::SetupDiEnumDeviceInterfaces(
-                          hDevInfoSet,     // 設備信息集句柄
-                          NULL,            // 不需額外的設備描述
-                          lpGuid,          // GUID
-                          (ULONG)nTotle,   // 設備信息集里的設備序號
-                          &ifData);        // 設備接口信息
-
-            if(bResult)
-            {
-                // 取得该设备接口的细节(设备路径)
-                bResult = SetupDiGetInterfaceDeviceDetail(
-                              hDevInfoSet,    // 设备信息集句柄
-                              &ifData,        // 设备接口信息
-                              pDetail,        // 设备接口细节(设备路径)
-                              INTERFACE_DETAIL_SIZE,    // 输出缓冲区大小
-                              NULL,           // 不需计算输出缓冲区大小(直接用设定值)
-                              NULL);          // 不需额外的设备描述
-
-                if(bResult)
-                {
-                    // 复制设备路径到输出缓冲区
-                    ::_tcscpy_s(pszDevicePath[nCount], 256, pDetail->DevicePath);
-                    // 调整计数值
-                    nCount++;
-                    LOG_INFO("Cnt = " << nCount << ",pDetail->DevicePath =" << pDetail->DevicePath);
-                }
-            }
-        }
-        else
-        {
-            LOG_INFO("SetupDiEnumDeviceInfo FAILED!@");
-        }
-    }
-
-    // 释放设备接口数据空间
-    ::GlobalFree(pDetail);
-    // 关闭设备信息集句柄
-    ::SetupDiDestroyDeviceInfoList(hDevInfoSet);
-    return nCount;
+	return WriteBuf(msg.c_str(), msg.length());
 }
 
-int CPosPrinter::WriteData(string msg)
+int CPosPrinter::WriteBuf(const char* buf, int len)
 {
     if(m_type == 1)
     {
         DWORD dwWrite;
 
-        for(std::vector<HANDLE>::iterator it = m_hPorts.begin(); it != m_hPorts.end(); it++)
+        for(std::vector<PrinterHandle>::iterator it = m_hPorts.begin(); it != m_hPorts.end(); it++)
         {
-            OVERLAPPED overlap;
-            memset(&overlap, 0, sizeof(overlap));
-            BOOL rc = WriteFile(*it, msg.c_str(), (DWORD)msg.length(), &dwWrite, &overlap);
+            HANDLE hPort = (*it).hPort;
 
-            if(rc)
+            if((*it).type == 1 || (*it).type == 3)
             {
-                LOG_INFO("writefile success immediately");
+                //usb或者串口,同步写数据
+                WriteFile(hPort, buf, len, &dwWrite, NULL);
             }
             else
             {
-                if(GetLastError() == ERROR_IO_PENDING)
+                //并口,异步写数据
+                OVERLAPPED overlap;
+                memset(&overlap, 0, sizeof(overlap));
+                BOOL rc = WriteFile(hPort, buf, len, &dwWrite, &overlap);
+
+                if(rc)
                 {
-                    LOG_INFO("Request queued, waiting... handle:" << *it);
-                    WaitForSingleObject(*it, INFINITE);
-                    LOG_INFO("Request completed, handle:" << *it);
-                    DWORD numread;
-                    rc = GetOverlappedResult(
-                             *it,
-                             &overlap,
-                             &numread,
-                             FALSE
-                         );
+                    //LOG_INFO("writefile success immediately, handle:" << hPort);
+                }
+                else
+                {
+                    if(GetLastError() == ERROR_IO_PENDING)
+                    {
+                        //LOG_INFO("Request queued, waiting... handle:" << hPort);
+                        WaitForSingleObject(hPort, 5000);
+                        //LOG_INFO("Request completed, handle:" << hPort);
+                        DWORD numread;
+                        rc = GetOverlappedResult(
+                                 hPort,
+                                 &overlap,
+                                 &numread,
+                                 FALSE
+                             );
+                    }
                 }
             }
         }
@@ -884,7 +962,7 @@ int CPosPrinter::WriteData(string msg)
     {
         try
         {
-            m_socket.write_some(boost::asio::buffer(msg.c_str(), msg.length()));
+            m_socket.write_some(boost::asio::buffer(buf, len));
         }
         catch(const std::exception& e)
         {
@@ -895,55 +973,49 @@ int CPosPrinter::WriteData(string msg)
     }
 }
 
-int CPosPrinter::WriteBuf(char* buf, int len)
+/*
+ *测试这个并口是否连通的
+ **/
+bool CPosPrinter::lptTest(HANDLE hPort)
 {
-    if(m_type == 1)
-    {
-        DWORD dwWrite;
+	char chInitCode[] = "\x1B\x40";
 
-        for(std::vector<HANDLE>::iterator it = m_hPorts.begin(); it != m_hPorts.end(); it++)
-        {
-            OVERLAPPED overlap;
-            memset(&overlap, 0, sizeof(overlap));
-            BOOL rc = WriteFile(*it, buf, len, &dwWrite, &overlap);
+	DWORD dwWrite;
 
-            if(rc)
-            {
-                LOG_INFO("writefile success immediately, handle:" << *it);
-            }
-            else
-            {
-                if(GetLastError() == ERROR_IO_PENDING)
-                {
-                    LOG_INFO("Request queued, waiting... handle:" << *it);
-                    WaitForSingleObject(*it, INFINITE);
-                    LOG_INFO("Request completed, handle:" << *it);
-                    DWORD numread;
-                    rc = GetOverlappedResult(
-                             *it,
-                             &overlap,
-                             &numread,
-                             FALSE
-                         );
-                }
-            }
-        }
+	OVERLAPPED overlap;
+	memset(&overlap, 0, sizeof(overlap));
 
-        return 1;
-    }
-    else
-    {
-        try
-        {
-            m_socket.write_some(boost::asio::buffer(buf, len));
-        }
-        catch(const std::exception& e)
-        {
-            LOG_INFO(e.what());
-        }
+	BOOL rc = WriteFile(hPort, chInitCode, (DWORD)2L, &dwWrite, &overlap);
 
-        return 0;
-    }
+	if (rc)
+	{
+		LOG_INFO("writefile success immediately, handle:" << hPort);
+
+		return true;
+	}
+	else
+	{
+		if (GetLastError() == ERROR_IO_PENDING)
+		{
+			//LOG_INFO("before lpt test, handle:" << hPort);
+
+			DWORD ret = WaitForSingleObject(hPort, 1000);
+
+			//LOG_INFO("after lpt test, handle" << hPort);
+
+			if (ret == 0)
+			{
+				LOG_INFO("并口打印机已经连接!");
+				return true;
+			}
+			else
+			{
+				LOG_INFO("并口打印机未连接!");
+			}
+		}
+	}
+
+	return false;
 }
 
 int CPosPrinter::POS_Reset(void)

+ 12 - 3
lewaimai_pos_windows/tool/CPosPrinter.h

@@ -12,6 +12,14 @@
 //USB类的GUID
 const GUID USB_GUID = {0xa5dcbf10, 0x6530, 0x11d2, {0x90, 0x1f, 0x00, 0xc0, 0x4f, 0xb9, 0x51, 0xed}};
 
+//存储打印端口句柄的结构
+class PrinterHandle
+{
+public:
+	HANDLE hPort;
+	int type; //句柄类型 1:usb 2:并口 3:串口
+};
+
 class CPosPrinter
 {
 public:
@@ -23,11 +31,12 @@ public:
 
 private:
 	bool InitShouyin();
-
 	int GetDevicePath(LPGUID lpGuid, LPTSTR* pszDevicePath);
 
 	int WriteData(string meg);
-	int WriteBuf(char *buf, int len);
+	int WriteBuf(const char* buf, int len);
+
+	bool lptTest(HANDLE hPort);
 
 	int POS_Reset(void);
 	int POS_FeedLine(void);
@@ -55,7 +64,7 @@ private:
 	std::string HandleFoodTotalPrice(std::string oldprice, int guige = 1);
 
 private:
-	std::vector<HANDLE> m_hPorts;
+	std::vector<PrinterHandle> m_hPorts;
 
 	boost::asio::io_service m_io;
 	boost::asio::ip::tcp::socket m_socket;

+ 1 - 1
lewaimai_pos_windows/tool/CSqlite3.cpp

@@ -32,7 +32,7 @@ CSqlite3::CSqlite3()
 
     else
     {
-        LOG_INFO("Opened database successfully");
+        //LOG_INFO("Opened database successfully");
     }
 }