浏览代码

新版本改好了

zhangyang 6 年之前
父节点
当前提交
e04cd73e62

+ 21 - 0
bin/Win32/Debug/lewaimai_pos_windows/skin/setting.xml

@@ -51,6 +51,27 @@
 							<ListLabelElement text="4联" />
 						</Combo>
 					</HorizontalLayout>
+					<HorizontalLayout height="44">
+						<Label text="打印机接口类型" width="260"/>
+						<Combo name="setting_printer_leixing" padding="0,9,0,0" width="140" height="26" tooltip="请点击这里选择您的打印机接口类型" normalimage="file='Setting_Combox_Normal.png' corner='2,2,24,2'" hotimage="file='Setting_Combox_Hover.png' corner='2,2,24,2'" pushedimage="Setting_Combox_Click.png' corner='2,2,24,2'" textpadding="10,1,1,1" >
+							<ListLabelElement text="智能识别模式" selected="true" />
+							<ListLabelElement text="usb" />
+							<ListLabelElement text="并口" />
+							<ListLabelElement text="串口" />
+							<ListLabelElement text="网口" />
+						</Combo>
+					</HorizontalLayout>
+					<HorizontalLayout height="44" name="setting_printer_usb_layout">
+						<Label text="usb打印设备选择" width="260"/>
+						<Combo name="setting_printer_usb" padding="0,9,0,0" width="800" height="26" tooltip="请点击这里选择您的打印机接口类型" normalimage="file='Setting_Combox_Normal.png' corner='2,2,24,2'" hotimage="file='Setting_Combox_Hover.png' corner='2,2,24,2'" pushedimage="Setting_Combox_Click.png' corner='2,2,24,2'" textpadding="10,1,1,1" >
+						</Combo>
+					</HorizontalLayout>
+					<HorizontalLayout height="56" name="setting_printer_wangkou_layout">
+						<Label text="网口IP地址" width="260"/>
+						<Edit name="setting_printer_wangkou_ip" width="200" height="32" padding="0,12,0,12" normalimage="file='Chat_InputBox_BG.png' corner='4,4,4,4'" hotimage="file='Chat_InputBox_BG_Hover.png' corner='4,4,4,4'" />
+
+						<Button name="setting_printer_wangkouk_save_btn" align="center" width="100" height="38" padding="20,8,0,3" text="保存" normalimage="file='Btn_White.png' corner='5,5,5,5'" hotimage="file='Btn_White_Hover.png' corner='5,5,5,5'" pushedimage="file='Btn_White_Click.png' corner='5,5,5,5'" />
+					</HorizontalLayout>
 					<HorizontalLayout height="44" padding="0,20,0,0">
 						<Label text="小票格式设置" width="260" />
 					</HorizontalLayout>

二进制
bin/Win32/Release/lewaimai_pos_windows/skin/skin.lwm


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

二进制
lewaimai_pos_windows/resource/lewaimai_pos_windows.aps


二进制
lewaimai_pos_windows/resource/lewaimai_pos_windows.rc


+ 235 - 206
lewaimai_pos_windows/tool/CPosPrinter.cpp

@@ -15,191 +15,231 @@ CPosPrinter::~CPosPrinter()
 {
 }
 
-/*
- *找到所有可用的小票打印机,包括USB、并口、串口3个类型
- **/
-bool CPosPrinter::InitShouyin()
+void CPosPrinter::InitUsb()
 {
-    //先找USB的
+	//设置中文字符
+	setlocale(LC_CTYPE, "chs");
 
-    //设备路径
-    TCHAR* szDevicePath[MAX_DEVICE];
+	//取设备路径
+	int nDevice = GetDevicePath((LPGUID)&USB_GUID);
+	LOG_INFO("可用的USB打印机数量:" << nDevice);
 
-    //设置中文字符
-    setlocale(LC_CTYPE, "chs");
+	//添加usb端口
+	int i = 0;
 
-    TCHAR* Port = NULL;
+	while (i < nDevice)
+	{
+		LOG_INFO("准备打开端口 Port = " << m_usb_devices[i].c_str());
 
-    //分配需要的空间
-    for(int i = 0; i < MAX_DEVICE; i++)
-    {
-        szDevicePath[i] = new TCHAR[MAX_PATH];
-    }
+		HANDLE hPort = CreateFile(m_usb_devices[i].c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
 
-    //取设备路径
-    int nDevice = GetDevicePath((LPGUID)&USB_GUID, szDevicePath);
-    LOG_INFO("可用的USB打印机数量:" << nDevice);
+		if (hPort == INVALID_HANDLE_VALUE)
+		{
+			// 打开端口失败
+			DWORD error = GetLastError();
 
-    //添加usb端口
-    int i = 0;
+			if (error == 2)
+			{
+				//没有指定的文件
+				LOG_INFO("没有找对对应的usb端口");
+			}
+			else if (error == 5)
+			{
+				LOG_INFO("usb端口被占用!");
+			}
 
-    while(i < nDevice)
-    {
-        Port = szDevicePath[i++];
-        LOG_INFO("准备打开端口 Port = " << Port);
+			continue;
+		}
 
-        HANDLE hPort = CreateFile(Port, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
+		LOG_INFO("打开usb端口,准备进行打印机检测! hPort:" << hPort);
 
-        if(hPort == INVALID_HANDLE_VALUE)
-        {
-            // 打开端口失败
-            DWORD error = GetLastError();
+		if (PortTest(hPort) == true)
+		{
+			//端口测试连通,保存起来
+			PrinterHandle newHandle;
+			newHandle.hPort = hPort;
+			newHandle.type = 1;
 
-            if(error == 2)
-            {
-                //没有指定的文件
-                LOG_INFO("没有找对对应的usb端口");
-            }
-            else if(error == 5)
-            {
-                LOG_INFO("usb端口被占用!");
-            }
+			m_hPorts.push_back(newHandle);
+		}
+		else
+		{
+			//端口打印机没有连接,那么就直接关闭掉并口,避免占用
+			CloseHandle(hPort);
+		}
 
-            continue;
-        }
+		i++;
+	}
+}
 
-        LOG_INFO("打开usb端口,准备进行打印机检测! hPort:" << hPort);
+void CPosPrinter::InitOneUsb(wstring usb_path)
+{
+	HANDLE hPort = CreateFile(usb_path.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
 
-        if(PortTest(hPort) == true)
-        {
-            //端口测试连通,保存起来
-            PrinterHandle newHandle;
-            newHandle.hPort = hPort;
-            newHandle.type = 1;
+	if (hPort == INVALID_HANDLE_VALUE)
+	{
+		// 打开端口失败
+		DWORD error = GetLastError();
 
-            m_hPorts.push_back(newHandle);
-        }
-        else
-        {
-            //端口打印机没有连接,那么就直接关闭掉并口,避免占用
-            CloseHandle(hPort);
-        }
-    }
+		if (error == 2)
+		{
+			//没有指定的文件
+			LOG_INFO("没有找对对应的usb端口");
+		}
+		else if (error == 5)
+		{
+			LOG_INFO("usb端口被占用!");
+		}
+	}
 
-    //开始添加并口的端口
-    std::wstring LptStr = L"lpt1";
+	LOG_INFO("打开usb端口,准备进行打印机检测! hPort:" << hPort);
 
-    HANDLE hPort = CreateFile(LptStr.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
+	if (PortTest(hPort) == true)
+	{
+		//端口测试连通,保存起来
+		PrinterHandle newHandle;
+		newHandle.hPort = hPort;
+		newHandle.type = 1;
 
-    if(hPort == INVALID_HANDLE_VALUE)
-    {
-        DWORD error = GetLastError();
+		m_hPorts.push_back(newHandle);
+	}
+	else
+	{
+		//端口打印机没有连接,那么就直接关闭掉并口,避免占用
+		CloseHandle(hPort);
+	}
+}
 
-        if(error == 2)
-        {
-            //没有指定的文件
-            LOG_INFO("本机器没有并口!");
-        }
-        else if(error == 5)
-        {
-            LOG_INFO("并口被占用!");
-        }
-    }
-    else
-    {
-        //这个表示并口可以使用
-        LOG_INFO("找到并口,准备进行打印机检测! hPort:" << hPort);
+void CPosPrinter::InitBingkou()
+{
+	std::wstring LptStr = L"lpt1";
 
-        if(PortTest(hPort) == true)
-        {
-            //并口测试连通,保存起来
-            PrinterHandle newHandle;
-            newHandle.hPort = hPort;
-            newHandle.type = 2;
+	HANDLE hPort = CreateFile(LptStr.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
 
-            m_hPorts.push_back(newHandle);
-        }
-        else
-        {
-            //并口打印机没有连接,那么就直接关闭掉并口,避免占用
-            CloseHandle(hPort);
-        }
-    }
+	if (hPort == INVALID_HANDLE_VALUE)
+	{
+		DWORD error = GetLastError();
 
-    //开始添加串口
-    int comNum = 10;
+		if (error == 2)
+		{
+			//没有指定的文件
+			LOG_INFO("本机器没有并口!");
+		}
+		else if (error == 5)
+		{
+			LOG_INFO("并口被占用!");
+		}
+	}
+	else
+	{
+		//这个表示并口可以使用
+		LOG_INFO("找到并口,准备进行打印机检测! hPort:" << hPort);
 
-    for(int i = 1; i <= 10; i++)
-    {
-        std::wstring com2Str = L"com" + CLewaimaiString::ANSIToUnicode(to_string(i));
+		if (PortTest(hPort) == true)
+		{
+			//并口测试连通,保存起来
+			PrinterHandle newHandle;
+			newHandle.hPort = hPort;
+			newHandle.type = 2;
 
-        hPort = CreateFile(com2Str.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+			m_hPorts.push_back(newHandle);
+		}
+		else
+		{
+			//并口打印机没有连接,那么就直接关闭掉并口,避免占用
+			CloseHandle(hPort);
+		}
+	}
+}
 
-        if(hPort == INVALID_HANDLE_VALUE)
-        {
-            DWORD error = GetLastError();
+void CPosPrinter::InitCom()
+{
+	int comNum = 10;
 
-            if(error == 2)
-            {
-                //没有指定的文件
-                LOG_INFO("没有找到对应的串口 " << com2Str.c_str());
-            }
-            else if(error == 5)
-            {
-                LOG_INFO("串口被占用 " << com2Str.c_str());
-            }
-        }
-        else
-        {
-            LOG_INFO(com2Str.c_str() << " success, handle:" << hPort);
+	for (int i = 1; i <= 10; i++)
+	{
+		std::wstring com2Str = L"com" + CLewaimaiString::ANSIToUnicode(to_string(i));
 
-            //扎到了可用的串口,设置串口波特率
-            DCB dcb;
-            dcb.DCBlength = sizeof(dcb);
-            GetCommState(hPort, &dcb);
+		HANDLE hPort = CreateFile(com2Str.c_str(), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
 
-            //佳博的串口打印机,默认是这个波特率
-            dcb.BaudRate = 19200;
+		if (hPort == INVALID_HANDLE_VALUE)
+		{
+			DWORD error = GetLastError();
 
-            if(!SetCommState(hPort, &dcb))
-            {
-                LOG_INFO("set baudRate failed!");
+			if (error == 2)
+			{
+				//没有指定的文件
+				LOG_INFO("没有找到对应的串口 " << com2Str.c_str());
+			}
+			else if (error == 5)
+			{
+				LOG_INFO("串口被占用 " << com2Str.c_str());
+			}
+		}
+		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!");
 
 				CloseHandle(hPort);
-                continue;
-            }
+				continue;
+			}
 
-            //设定通讯端口超时参数
-            COMMTIMEOUTS tmouts;
-            tmouts.ReadIntervalTimeout = 100;
-            tmouts.ReadTotalTimeoutMultiplier = 100;
-            tmouts.ReadTotalTimeoutConstant = 100;
-            tmouts.WriteTotalTimeoutConstant = 100;
-            tmouts.WriteTotalTimeoutMultiplier = 100;
-            SetCommTimeouts(hPort, &tmouts);
+			//设定通讯端口超时参数
+			COMMTIMEOUTS tmouts;
+			tmouts.ReadIntervalTimeout = 100;
+			tmouts.ReadTotalTimeoutMultiplier = 100;
+			tmouts.ReadTotalTimeoutConstant = 100;
+			tmouts.WriteTotalTimeoutConstant = 100;
+			tmouts.WriteTotalTimeoutMultiplier = 100;
+			SetCommTimeouts(hPort, &tmouts);
 
 			//设置端口缓冲
 			SetupComm(hPort, 1024, 1024);
 
-            //清除通讯端口缓存
-            PurgeComm(hPort, PURGE_TXCLEAR | PURGE_RXCLEAR | PURGE_TXABORT | PURGE_RXABORT);
+			//清除通讯端口缓存
+			PurgeComm(hPort, PURGE_TXCLEAR | PURGE_RXCLEAR | PURGE_TXABORT | PURGE_RXABORT);
 
-            //保存端口
-            PrinterHandle newHandle;
-            newHandle.hPort = hPort;
-            newHandle.type = 3;
+			//保存端口
+			PrinterHandle newHandle;
+			newHandle.hPort = hPort;
+			newHandle.type = 3;
 
-            m_hPorts.push_back(newHandle);
-        }
-    }
+			m_hPorts.push_back(newHandle);
+		}
+	}
+}
+
+/*
+ *找到所有可用的小票打印机,包括USB、并口、串口3个类型,注意这里不包含网口
+ **/
+void CPosPrinter::InitShouyin()
+{
+	//开始添加usb
+	InitUsb();
+
+    //开始添加并口的端口
+	InitBingkou();
 
-    return true;
+    //开始添加串口
+	InitCom();
 }
 
 /*
  *获取CreateFile的USB端口号
  **/
-int CPosPrinter::GetDevicePath(LPGUID lpGuid, LPTSTR* pszDevicePath)
+int CPosPrinter::GetDevicePath(LPGUID lpGuid)
 {
     HDEVINFO hDevInfoSet;
     SP_DEVINFO_DATA spDevInfoData;
@@ -315,7 +355,7 @@ int CPosPrinter::GetDevicePath(LPGUID lpGuid, LPTSTR* pszDevicePath)
 					}
 
                     // 复制设备路径到输出缓冲区
-                    ::_tcscpy_s(pszDevicePath[nCount], 256, pDetail->DevicePath);					
+					m_usb_devices.push_back(DevicePath);
 
                     // 调整计数值
                     nCount++;
@@ -352,19 +392,52 @@ int CPosPrinter::GetPrinterType(wstring vid, wstring pid)
 	return 1;
 }
 
+/*
+ *打印收银小票
+ **/
 void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
 {
     //设置模式,后面输出数据不会错
     m_type = 1;
 
-    //初始化收银打印机的链接
-    bool ret = InitShouyin();
+	std::string printer_leixing = CSetting::GetParam("setting_printer_leixing");
+	if (printer_leixing == "auto")
+	{
+		InitShouyin();
+	}
+	else if (printer_leixing == "usb")
+	{
+		std::string printer_usb = CSetting::GetParam("setting_printer_usb");
+		std::wstring ws_printer_usb = CLewaimaiString::UTF8ToUnicode(printer_usb);
 
-    if(ret == false)
-    {
-        LOG_INFO("打开收银打印机端口失败!");
-        return;
-    }
+		InitOneUsb(ws_printer_usb);
+	}
+	else if (printer_leixing == "bingkou")
+	{
+		InitBingkou();
+	}
+	else if (printer_leixing == "chuankou")
+	{
+		InitCom();
+	}
+	else if (printer_leixing == "wangkou")
+	{
+		m_type = 2;
+
+		std::string wangkou_ip = CSetting::GetParam("setting_printer_wangkou_ip");
+
+		//初始化连接
+		try
+		{
+			boost::asio::ip::tcp::endpoint ep(boost::asio::ip::address::from_string(wangkou_ip.c_str()), 9100);
+			m_socket.connect(ep);
+		}
+		catch (std::exception& e)
+		{
+			std::string err = e.what();
+			LOG_INFO("连接厨房打印机失败,IP地址:" << wangkou_ip.c_str() << ",错误信息:" << err.c_str());
+		}
+	}
 
     //读取当前收银打印机的设置
     std::string guige = CSetting::GetParam("setting_printer_guige");
@@ -514,6 +587,7 @@ void CPosPrinter::PrintWaimaiOrderShouyin(CWaimaiOrder& order)
 
         POS_TextOut(lines);
         POS_FeedLine();
+
         //商品标题
         bool setting_printer_shangpin_big = false;
 
@@ -1019,6 +1093,11 @@ void CPosPrinter::PrintWaimaiOrderChufang(CWaimaiOrder& order)
     }
 }
 
+std::vector<std::wstring> CPosPrinter::getUsbDevices()
+{
+	return m_usb_devices;
+}
+
 int CPosPrinter::WriteData(string msg)
 {
     return WriteBuf(msg.c_str(), msg.length());
@@ -1046,18 +1125,18 @@ int CPosPrinter::WriteBuf(const char* buf, int len)
                 //usb和并口,异步写数据
                 OVERLAPPED overlap;
                 memset(&overlap, 0, sizeof(overlap));
-                BOOL rc = WriteFile(hPort, buf, len, &dwWrite, &overlap);
 
+                BOOL rc = WriteFile(hPort, buf, len, &dwWrite, &overlap);
                 if(rc)
                 {
-                    LOG_INFO("writefile success immediately, handle:" << hPort);
+                    //LOG_INFO("writefile success immediately, handle:" << hPort);
                 }
                 else
                 {
                     if(GetLastError() == ERROR_IO_PENDING)
                     {
                         //LOG_INFO("Request queued, waiting... handle:" << hPort);
-                        WaitForSingleObject(hPort, 5000);
+                        WaitForSingleObject(hPort, 1000);
                         //LOG_INFO("Request completed, handle:" << hPort);
 
 						//计算写入了多少字节的数据
@@ -1091,22 +1170,19 @@ int CPosPrinter::WriteBuf(const char* buf, int len)
 }
 
 /*
- *测试打印机是否连接,以及是否标签打印机
- *有的标签打印机的vid和pid跟热敏打印机一样,因此不能通过GetPrinterType函数排除,在这里通过标签打印机的查询状态指令,如果返回数据说明肯定是标签打印机
- *这里不能用热敏打印机的查询指令,因为测试发现有的热敏打印机会返回状态,有的不会返回,如果不返回的时候就没法确定这台打印机到底是热敏还是标签
- *当然,这里也不能保证所有标签打印机都会返回,但是只要有返回就可以直接排除(有些热敏和标签两用的咋办。。。)
+ *测试打印机是否连接
  **/
 bool CPosPrinter::PortTest(HANDLE hPort)
 {
 	//标签打印机的查询状态指令
-    char chInitCode[3] = { 0x1b, 0x21, 0x3f };
+    char chInitCode[2] = { 0x1b, 0x40};
 
     DWORD dwWrite;
 
     OVERLAPPED overlap;
     memset(&overlap, 0, sizeof(overlap));
 
-    BOOL rc = WriteFile(hPort, chInitCode, 3, &dwWrite, &overlap);
+    BOOL rc = WriteFile(hPort, chInitCode, 2, &dwWrite, &overlap);
     if(rc)
     {
         LOG_INFO("writefile success immediately, handle:" << hPort);
@@ -1117,53 +1193,11 @@ bool CPosPrinter::PortTest(HANDLE hPort)
     {
         if(GetLastError() == ERROR_IO_PENDING)
         {
-			DWORD ret = WaitForSingleObject(hPort, 500);
+			DWORD ret = WaitForSingleObject(hPort, 1000);
             if(ret == 0)
             {
                 LOG_INFO("printer is connect, handle:" << hPort);				
 
-				//开始读取返回值,如果读到说明这个打印机是一个标签打印机
-				char chBuffer[2];
-				memset(chBuffer, 0, 2);
-
-				OVERLAPPED overlap2;
-				memset(&overlap2, 0, sizeof(overlap2));
-
-				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, 500);
-
-						DWORD numread = 0;
-						BOOL rc = GetOverlappedResult(hPort, &overlap2, &numread, FALSE);
-
-						if (numread == 1)
-						{
-							//这是一个标签打印机
-							LOG_INFO("this is a biaoqian printer, handle:" << hPort);
-							return false;
-						}
-					}
-					else
-					{
-						return false;
-					}
-				}
-				else
-				{
-					if (dwReadSize == 1)
-					{
-						//这是一个标签打印机
-						LOG_INFO("this is a biaoqian printer, handle:" << hPort);
-						return false;
-					}
-				}
-
                 return true;
             }
             else
@@ -1176,11 +1210,6 @@ bool CPosPrinter::PortTest(HANDLE hPort)
     return false;
 }
 
-void CPosPrinter::ReadStatus()
-{
-	
-}
-
 int CPosPrinter::POS_Reset(void)
 {
     char s[2] = {0x1B, 0x40};

+ 14 - 4
lewaimai_pos_windows/tool/CPosPrinter.h

@@ -30,9 +30,18 @@ public:
     void PrintWaimaiOrderShouyin(CWaimaiOrder& order);
 	void PrintWaimaiOrderChufang(CWaimaiOrder& order);
 
+	void InitUsb();
+	std::vector<std::wstring> getUsbDevices();
+
 private:
-	bool InitShouyin();
-	int GetDevicePath(LPGUID lpGuid, LPTSTR* pszDevicePath);
+	void InitBingkou();
+	void InitCom();
+
+	void InitShouyin();
+
+	void InitOneUsb(wstring usb_path);
+
+	int GetDevicePath(LPGUID lpGuid);
 	int GetPrinterType(wstring vid, wstring pid);
 
 	int WriteData(string meg);
@@ -40,8 +49,6 @@ private:
 
 	bool PortTest(HANDLE hPort);
 
-	void ReadStatus();
-
 	int POS_Reset(void);
 	int POS_FeedLine(void);
 	int POS_Feed(void);
@@ -75,4 +82,7 @@ private:
 
 	//这个是当前的输出模式,是收银模式还是厨房打印模式
 	int m_type;
+
+	//usb打印机的描述
+	std::vector<std::wstring> m_usb_devices;
 };

+ 18 - 0
lewaimai_pos_windows/tool/CSetting.cpp

@@ -161,6 +161,24 @@ void CSetting::Init()
 		m_paramsMap[setting_printer_lianshu] = "1";
 	}
 
+	std::string setting_printer_leixing = "setting_printer_leixing";
+	if (m_paramsMap.find(setting_printer_leixing) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_printer_leixing] = "auto";
+	}
+
+	std::string setting_printer_usb = "setting_printer_usb";
+	if (m_paramsMap.find(setting_printer_usb) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_printer_usb] = "";
+	}
+
+	std::string setting_printer_wangkou_ip = "setting_printer_wangkou_ip";
+	if (m_paramsMap.find(setting_printer_wangkou_ip) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_printer_wangkou_ip] = "";
+	}
+
 	std::string setting_printer_quhuo_big = "setting_printer_quhuo_big";
 	if (m_paramsMap.find(setting_printer_quhuo_big) == m_paramsMap.end())
 	{

+ 191 - 0
lewaimai_pos_windows/wnd/CMainWnd.cpp

@@ -27,6 +27,7 @@ void CMainWnd::Init()
 
     //初始化设置中心的状态
     InitSettingStatus();
+
     //登录成功,启动消息和任务处理
     m_push = new CMessagePush(m_hWnd);
     m_push->Start();
@@ -439,6 +440,13 @@ void CMainWnd::HandleClickMsg(TNotifyUI& msg)
             CSetting::SetParam("setting_is_new_waimai_printer", "1");
         }
     }
+	else if (name == _T("setting_printer_wangkouk_save_btn"))
+	{
+		CEditUI* wangkou_ip = static_cast<CEditUI*>(m_pm.FindControl(_T("setting_printer_wangkou_ip")));
+		wstring ip = wangkou_ip->GetText();
+
+		CSetting::SetParam("setting_printer_wangkou_ip", CLewaimaiString::UnicodeToUTF8(ip));
+	}
     else if(name == _T("setting_printer_quhuo_big"))
     {
         CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_quhuo_big")));
@@ -886,6 +894,95 @@ void CMainWnd::HandleItemSelectMsg(TNotifyUI& msg)
             CSetting::SetParam("setting_printer_lianshu", "4");
         }
     }
+    else if(name == _T("setting_printer_leixing"))
+    {
+        CComboUI* com = static_cast<CComboUI*>(m_pm.FindControl(_T("setting_printer_leixing")));
+
+        CHorizontalLayoutUI* usb_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("setting_printer_usb_layout")));
+        CHorizontalLayoutUI* wangkou_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("setting_printer_wangkou_layout")));
+
+        if(com->GetCurSel() == 0)
+        {
+            CSetting::SetParam("setting_printer_leixing", "auto");
+
+            usb_layout->SetVisible(false);
+            wangkou_layout->SetVisible(false);
+        }
+        else if(com->GetCurSel() == 1)
+        {
+            CSetting::SetParam("setting_printer_leixing", "usb");
+
+            //显示usb布局
+            usb_layout->SetVisible(true);
+            wangkou_layout->SetVisible(false);
+
+            //usb下拉框默认选中
+            CComboUI* com_usb = static_cast<CComboUI*>(m_pm.FindControl(_T("setting_printer_usb")));
+            com_usb->RemoveAll();
+
+            //数据库中保存的之前的设置
+            std::string setting_printer_usb = CSetting::GetParam("setting_printer_usb");
+            std::wstring ws_setting_printer_usb = CLewaimaiString::UTF8ToUnicode(setting_printer_usb);
+
+            CPosPrinter printer;
+            printer.InitUsb();
+            std::vector<std::wstring> usb_devices = printer.getUsbDevices();
+
+            int i = 0;
+            int nSelect = -1;
+
+            for(std::vector<std::wstring>::iterator it = usb_devices.begin(); it != usb_devices.end(); it++)
+            {
+                CListLabelElementUI* elem = new CListLabelElementUI();
+                elem->SetText((*it).c_str());
+                com_usb->Add(elem);
+
+                if(*it == ws_setting_printer_usb)
+                {
+                    nSelect = i;
+                }
+
+                i++;
+            }
+
+            com_usb->SetInternVisible(true);
+            com_usb->SelectItem(nSelect, false, false);
+            com_usb->SetText(CLewaimaiString::UTF8ToUnicode(setting_printer_usb).c_str());
+        }
+        else if(com->GetCurSel() == 2)
+        {
+            CSetting::SetParam("setting_printer_leixing", "bingkou");
+
+            usb_layout->SetVisible(false);
+            wangkou_layout->SetVisible(false);
+        }
+        else if(com->GetCurSel() == 3)
+        {
+            CSetting::SetParam("setting_printer_leixing", "chuankou");
+
+            usb_layout->SetVisible(false);
+            wangkou_layout->SetVisible(false);
+        }
+        else if(com->GetCurSel() == 4)
+        {
+            CSetting::SetParam("setting_printer_leixing", "wangkou");
+
+            usb_layout->SetVisible(false);
+            wangkou_layout->SetVisible(true);
+
+            std::string setting_printer_wangkou_ip = CSetting::GetParam("setting_printer_wangkou_ip");
+
+            CEditUI* ip_edit = static_cast<CEditUI*>(m_pm.FindControl(_T("setting_printer_wangkou_ip")));
+            ip_edit->SetText(CLewaimaiString::UTF8ToUnicode(setting_printer_wangkou_ip).c_str());
+        }
+    }
+    else if(name == _T("setting_printer_usb"))
+    {
+        CComboUI* com = static_cast<CComboUI*>(m_pm.FindControl(_T("setting_printer_usb")));
+		wstring usb_device = com->GetText();
+
+		CSetting::SetParam("setting_printer_usb", CLewaimaiString::UnicodeToUTF8(usb_device));
+    }
 }
 
 LRESULT CMainWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
@@ -1247,8 +1344,10 @@ void CMainWnd::InitSettingStatus()
 {
     CLabelUI* name_version = static_cast<CLabelUI*>(m_pm.FindControl(_T("main_name_version")));
     name_version->SetText((L"乐外卖接单软件 " + CLewaimaiString::UTF8ToUnicode(CSystem::GetVersion())).c_str());
+
     CLabelUI* version = static_cast<CLabelUI*>(m_pm.FindControl(_T("setting_version")));
     version->SetText((L"版本号:" + CLewaimaiString::UTF8ToUnicode(CSystem::GetVersion())).c_str());
+
     CCheckBoxUI* box = NULL;
     CComboUI* com = NULL;
     box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_new_waimai_voice")));
@@ -1336,6 +1435,98 @@ void CMainWnd::InitSettingStatus()
         com->SetText(L"4联");
     }
 
+    com = static_cast<CComboUI*>(m_pm.FindControl(_T("setting_printer_leixing")));
+    std::string setting_printer_leixing = CSetting::GetParam("setting_printer_leixing");
+
+    CHorizontalLayoutUI* usb_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("setting_printer_usb_layout")));
+    CHorizontalLayoutUI* wangkou_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("setting_printer_wangkou_layout")));
+
+    if(setting_printer_leixing == "auto")
+    {
+        com->SetInternVisible(true);
+        com->SelectItem(0, false, false);
+        com->SetText(L"智能识别模式");
+
+        //智能识别模式隐藏这2个
+        usb_layout->SetVisible(false);
+        wangkou_layout->SetVisible(false);
+    }
+    else if(setting_printer_leixing == "usb")
+    {
+        com->SetInternVisible(true);
+        com->SelectItem(1, false, false);
+        com->SetText(L"usb");
+
+        //显示usb布局
+        usb_layout->SetVisible(true);
+        wangkou_layout->SetVisible(false);
+
+        //usb下拉框默认选中
+        CComboUI* com_usb = static_cast<CComboUI*>(m_pm.FindControl(_T("setting_printer_usb")));
+        com_usb->RemoveAll();
+
+        //数据库中保存的之前的设置
+        std::string setting_printer_usb = CSetting::GetParam("setting_printer_usb");
+        std::wstring ws_setting_printer_usb = CLewaimaiString::UTF8ToUnicode(setting_printer_usb);
+
+        CPosPrinter printer;
+        printer.InitUsb();
+        std::vector<std::wstring> usb_devices = printer.getUsbDevices();
+
+        int i = 0;
+        int nSelect = -1;
+
+        for(std::vector<std::wstring>::iterator it = usb_devices.begin(); it != usb_devices.end(); it++)
+        {
+            CListLabelElementUI* elem = new CListLabelElementUI();
+            elem->SetText((*it).c_str());
+            com_usb->Add(elem);
+
+            if(*it == ws_setting_printer_usb)
+            {
+                nSelect = i;
+            }
+
+            i++;
+        }
+
+        com_usb->SetInternVisible(true);
+        com_usb->SelectItem(nSelect, false, false);
+        com_usb->SetText(CLewaimaiString::UTF8ToUnicode(setting_printer_usb).c_str());
+    }
+    else if(setting_printer_leixing == "bingkou")
+    {
+        com->SetInternVisible(true);
+        com->SelectItem(2, false, false);
+        com->SetText(L"并口");
+
+        usb_layout->SetVisible(false);
+        wangkou_layout->SetVisible(false);
+    }
+    else if(setting_printer_leixing == "chuankou")
+    {
+        com->SetInternVisible(true);
+        com->SelectItem(3, false, false);
+        com->SetText(L"串口");
+
+        usb_layout->SetVisible(false);
+        wangkou_layout->SetVisible(false);
+    }
+    else if(setting_printer_leixing == "wangkou")
+    {
+        com->SetInternVisible(true);
+        com->SelectItem(4, false, false);
+        com->SetText(L"网口");
+
+        usb_layout->SetVisible(false);
+        wangkou_layout->SetVisible(true);
+
+        std::string setting_printer_wangkou_ip = CSetting::GetParam("setting_printer_wangkou_ip");
+
+        CEditUI* ip_edit = static_cast<CEditUI*>(m_pm.FindControl(_T("setting_printer_wangkou_ip")));
+        ip_edit->SetText(CLewaimaiString::UTF8ToUnicode(setting_printer_wangkou_ip).c_str());
+    }
+
     box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_quhuo_big")));
 
     if(CSetting::GetParam("setting_printer_quhuo_big") == "1")