Browse Source

电子秤的设置弄完了

张洋 4 years ago
parent
commit
5043e282c8

File diff suppressed because it is too large
+ 30 - 0
bin/Win32/Debug/zhipuzi_pos_windows/skin/setting_dianzicheng.xml


+ 7 - 2
bin/Win32/Debug/zhipuzi_pos_windows/skin/setting_page.xml

@@ -3,17 +3,18 @@
 	<SettingPage name="setting_page" bkcolor="#FFEFF6EE">
 		<HorizontalLayout>
 			<HorizontalLayout width="250" padding="20,20,20,0">
-				<VerticalLayout height="540" bkcolor="#FFFFFFFF" childpadding="15" inset="20,20,20,0">
+				<VerticalLayout height="600" bkcolor="#FFFFFFFF" childpadding="15" inset="20,20,20,0">
 					<Option name="setting_waimai_order_switch" selected="true" text="外卖订单设置" group="setting_switch" align="center" height="38" normalimage="file='Btn_White.png' corner='5,5,5,5'" selectedimage="file='Btn_Green_Click.png' corner='5,5,5,5'" hotimage="file='Btn_White_Hover.png' corner='5,5,5,5'" hottextcolor="#CC1010" selectedtextcolor="#FFFFFFFF" />
 					<Option name="setting_diannei_order_switch" text="店内订单设置" group="setting_switch" align="center" height="38" normalimage="file='Btn_White.png' corner='5,5,5,5'" selectedimage="file='Btn_Green_Click.png' corner='5,5,5,5'" hotimage="file='Btn_White_Hover.png' corner='5,5,5,5'" hottextcolor="#CC1010" selectedtextcolor="#FFFFFFFF" />
 					<Option name="setting_printer_switch" text="小票打印设置" group="setting_switch" align="center" height="38" normalimage="file='Btn_White.png' corner='5,5,5,5'" selectedimage="file='Btn_Green_Click.png' corner='5,5,5,5'" hotimage="file='Btn_White_Hover.png' corner='5,5,5,5'" hottextcolor="#CC1010" selectedtextcolor="#FFFFFFFF" />
 					<Option name="setting_biaoqian_printer_switch" text="标签打印设置" group="setting_switch" align="center" height="38" normalimage="file='Btn_White.png' corner='5,5,5,5'" selectedimage="file='Btn_Green_Click.png' corner='5,5,5,5'" hotimage="file='Btn_White_Hover.png' corner='5,5,5,5'" hottextcolor="#CC1010" selectedtextcolor="#FFFFFFFF" />
 					<Option name="setting_chufang_printer_switch" text="厨房打印设置" group="setting_switch" align="center" height="38" normalimage="file='Btn_White.png' corner='5,5,5,5'" selectedimage="file='Btn_Green_Click.png' corner='5,5,5,5'" hotimage="file='Btn_White_Hover.png' corner='5,5,5,5'" hottextcolor="#CC1010" selectedtextcolor="#FFFFFFFF" />
+					<Option name="setting_dianzicheng_switch" text="电子秤设置" group="setting_switch" align="center" height="38" normalimage="file='Btn_White.png' corner='5,5,5,5'" selectedimage="file='Btn_Green_Click.png' corner='5,5,5,5'" hotimage="file='Btn_White_Hover.png' corner='5,5,5,5'" hottextcolor="#CC1010" selectedtextcolor="#FFFFFFFF" />
 					<Option name="setting_xianshi_switch" text="显示设置" group="setting_switch" align="center" height="38" normalimage="file='Btn_White.png' corner='5,5,5,5'" selectedimage="file='Btn_Green_Click.png' corner='5,5,5,5'" hotimage="file='Btn_White_Hover.png' corner='5,5,5,5'" hottextcolor="#CC1010" selectedtextcolor="#FFFFFFFF" />
 					<Option name="setting_system_switch" text="系统设置" group="setting_switch" align="center" height="38" normalimage="file='Btn_White.png' corner='5,5,5,5'" selectedimage="file='Btn_Green_Click.png' corner='5,5,5,5'" hotimage="file='Btn_White_Hover.png' corner='5,5,5,5'" hottextcolor="#CC1010" selectedtextcolor="#FFFFFFFF" />
 					<Option name="setting_system_about" text="关于" group="setting_switch" align="center" height="38" normalimage="file='Btn_White.png' corner='5,5,5,5'" selectedimage="file='Btn_Green_Click.png' corner='5,5,5,5'" hotimage="file='Btn_White_Hover.png' corner='5,5,5,5'" hottextcolor="#CC1010" selectedtextcolor="#FFFFFFFF" />
 
-					<Button name="setting_logout" padding="0,50,0,0" width="300" height="38" text="退出登陆" textcolor="#FFFFFFFF" normalimage="file='Btn_Red.png' corner='5,5,5,5'" hotimage="file='Btn_Red_Hover.png' corner='5,5,5,5'" pushedimage="file='Btn_Green_Click.png' corner='5,5,5,5'" />
+					<Button name="setting_logout" padding="0,30,0,0" width="300" height="38" text="退出登陆" textcolor="#FFFFFFFF" normalimage="file='Btn_Red.png' corner='5,5,5,5'" hotimage="file='Btn_Red_Hover.png' corner='5,5,5,5'" pushedimage="file='Btn_Green_Click.png' corner='5,5,5,5'" />
 				</VerticalLayout>
 			</HorizontalLayout>
 
@@ -39,6 +40,10 @@
 				</VerticalLayout>
 				
 				<VerticalLayout bkcolor="#FFFFFFFF" padding="0,20,20,20" inset="15,15,15,15">
+					<Include source="setting_dianzicheng.xml" />
+				</VerticalLayout>
+				
+				<VerticalLayout bkcolor="#FFFFFFFF" padding="0,20,20,20" inset="15,15,15,15">
 					<Include source="setting_xianshi.xml" />
 				</VerticalLayout>
 

+ 6 - 1
bin/Win32/Debug/zhipuzi_pos_windows/skin/setting_print.xml

@@ -30,7 +30,12 @@
 	</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 name="setting_printer_usb" padding="0,9,0,0" width="800" height="26" tooltip="请点击这里选择您的打印机USB端口" 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="44" name="setting_printer_chuankou_layout">
+		<Label text="串口端口选择" width="260"/>
+		<Combo name="setting_printer_com" padding="0,9,0,0" width="200" 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">

+ 3 - 5
zhipuzi_pos_windows/helper/CSerialPort.cpp

@@ -59,15 +59,13 @@ bool CSerialPort::openComm()
     {
 		SetupComm(m_hComm, MAX_BUFFER_SIZE, MAX_BUFFER_SIZE);	// 设置读写缓冲区大小
 
-		/*
 		COMMTIMEOUTS TimeOuts; //设定读超时
-		TimeOuts.ReadIntervalTimeout = 1000;
-		TimeOuts.ReadTotalTimeoutMultiplier = 500;
-		TimeOuts.ReadTotalTimeoutConstant = 5000; //设定写超时
+		TimeOuts.ReadIntervalTimeout = MAXDWORD;
+		TimeOuts.ReadTotalTimeoutMultiplier = 0;
+		TimeOuts.ReadTotalTimeoutConstant = 0; //设定写超时
 		TimeOuts.WriteTotalTimeoutMultiplier = 500;
 		TimeOuts.WriteTotalTimeoutConstant = 2000;
 		SetCommTimeouts(m_hComm, &TimeOuts); //设置超时
-		*/
 
         DCB dcb;
         GetCommState(m_hComm, &dcb);

+ 207 - 6
zhipuzi_pos_windows/page/CSettingPageUI.cpp

@@ -4,6 +4,7 @@
 #include "../wnd/CChufangSettingWnd.h"
 
 #include "../print/CPosPrinter.h"
+#include "../helper/CComHelper.h"
 
 CSettingPageUI::CSettingPageUI()
 {
@@ -161,6 +162,7 @@ void CSettingPageUI::InitShow()
 	std::string setting_printer_leixing = CSetting::GetParam("setting_printer_leixing");
 
 	CHorizontalLayoutUI* usb_layout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("setting_printer_usb_layout")));
+	CHorizontalLayoutUI* chuankou_layout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("setting_printer_chuankou_layout")));
 	CHorizontalLayoutUI* wangkou_layout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("setting_printer_wangkou_layout")));
 
 	if (setting_printer_leixing == "auto")
@@ -169,8 +171,9 @@ void CSettingPageUI::InitShow()
 		com->SelectItem(0, false, false);
 		com->SetText(L"智能识别模式");
 
-		//智能识别模式隐藏这2
+		//智能识别模式隐藏这3
 		usb_layout->SetVisible(false);
+		chuankou_layout->SetVisible(false);
 		wangkou_layout->SetVisible(false);
 	}
 	else if (setting_printer_leixing == "usb")
@@ -181,6 +184,7 @@ void CSettingPageUI::InitShow()
 
 		//显示usb布局
 		usb_layout->SetVisible(true);
+		chuankou_layout->SetVisible(false);
 		wangkou_layout->SetVisible(false);
 
 		//usb下拉框默认选中
@@ -221,6 +225,7 @@ void CSettingPageUI::InitShow()
 		com->SetText(L"并口");
 
 		usb_layout->SetVisible(false);
+		chuankou_layout->SetVisible(false);
 		wangkou_layout->SetVisible(false);
 	}
 	else if (setting_printer_leixing == "chuankou")
@@ -230,7 +235,40 @@ void CSettingPageUI::InitShow()
 		com->SetText(L"串口");
 
 		usb_layout->SetVisible(false);
+		chuankou_layout->SetVisible(true);
 		wangkou_layout->SetVisible(false);
+
+		//串口下拉框默认选中
+		CComboUI* com_chuankou = static_cast<CComboUI*>(this->FindSubControl(_T("setting_printer_com")));
+		com_chuankou->RemoveAll();
+
+		//数据库中保存的之前的设置
+		std::string setting_printer_com = CSetting::GetParam("setting_printer_com");
+		std::wstring ws_setting_printer_com = CLewaimaiString::UTF8ToUnicode(setting_printer_com);
+
+		CComHelper helper;
+		std::vector<std::wstring> com_devices = helper.getComPort();
+
+		int i = 0;
+		int nSelect = -1;
+
+		for (std::vector<std::wstring>::iterator it = com_devices.begin(); it != com_devices.end(); it++)
+		{
+			CListLabelElementUI* elem = new CListLabelElementUI();
+			elem->SetText((*it).c_str());
+			com_chuankou->Add(elem);
+
+			if (*it == ws_setting_printer_com)
+			{
+				nSelect = i;
+			}
+
+			i++;
+		}
+
+		com_chuankou->SetInternVisible(true);
+		com_chuankou->SelectItem(nSelect, false, false);
+		com_chuankou->SetText(CLewaimaiString::UTF8ToUnicode(setting_printer_com).c_str());
 	}
 	else if (setting_printer_leixing == "wangkou")
 	{
@@ -239,6 +277,7 @@ void CSettingPageUI::InitShow()
 		com->SetText(L"网口");
 
 		usb_layout->SetVisible(false);
+		chuankou_layout->SetVisible(false);
 		wangkou_layout->SetVisible(true);
 
 		std::string setting_printer_wangkou_ip = CSetting::GetParam("setting_printer_wangkou_ip");
@@ -357,6 +396,95 @@ void CSettingPageUI::InitShow()
 		box->Selected(false, false);
 	}
 
+	//电子秤设置
+	com = static_cast<CComboUI*>(this->FindSubControl(_T("setting_dianzicheng_xinghao")));
+	std::string setting_dianzicheng_xinghao = CSetting::GetParam("setting_dianzicheng_xinghao");
+
+	if (setting_dianzicheng_xinghao == "dahua_acs")
+	{
+		com->SetInternVisible(true);
+		com->SelectItem(0, false, false);
+		com->SetText(L"大华ACS-30Ab");
+	}
+
+	//串口下拉框默认选中
+	CComboUI* com_dianzicheng = static_cast<CComboUI*>(this->FindSubControl(_T("setting_dianzicheng_chuankou")));
+	com_dianzicheng->RemoveAll();
+
+	//数据库中保存的之前的设置
+	std::string setting_dianzicheng_com = CSetting::GetParam("setting_dianzicheng_com");
+	std::wstring ws_setting_dianzicheng_com = CLewaimaiString::UTF8ToUnicode(setting_dianzicheng_com);
+
+	CComHelper helper;
+	std::vector<std::wstring> com_devices = helper.getComPort();
+
+	int i = 0;
+	int nSelect = -1;
+
+	for (std::vector<std::wstring>::iterator it = com_devices.begin(); it != com_devices.end(); it++)
+	{
+		CListLabelElementUI* elem = new CListLabelElementUI();
+		elem->SetText((*it).c_str());
+		com_dianzicheng->Add(elem);
+
+		if (*it == ws_setting_dianzicheng_com)
+		{
+			nSelect = i;
+		}
+
+		i++;
+	}
+
+	com_dianzicheng->SetInternVisible(true);
+	com_dianzicheng->SelectItem(nSelect, false, false);
+	com_dianzicheng->SetText(CLewaimaiString::UTF8ToUnicode(setting_dianzicheng_com).c_str());
+
+	com = static_cast<CComboUI*>(this->FindSubControl(_T("setting_dianzicheng_botelv")));
+	std::string setting_dianzicheng_botelv = CSetting::GetParam("setting_dianzicheng_botelv");
+
+	if (setting_dianzicheng_botelv == "600")
+	{
+		com->SetInternVisible(true);
+		com->SelectItem(0, false, false);
+		com->SetText(L"600");
+	}
+	else if (setting_dianzicheng_botelv == "1200")
+	{
+		com->SetInternVisible(true);
+		com->SelectItem(1, false, false);
+		com->SetText(L"1200");
+	}
+	else if (setting_dianzicheng_botelv == "2400")
+	{
+		com->SetInternVisible(true);
+		com->SelectItem(2, false, false);
+		com->SetText(L"2400");
+	}
+	else if (setting_dianzicheng_botelv == "4800")
+	{
+		com->SetInternVisible(true);
+		com->SelectItem(3, false, false);
+		com->SetText(L"4800");
+	}
+	else if (setting_dianzicheng_botelv == "9600")
+	{
+		com->SetInternVisible(true);
+		com->SelectItem(4, false, false);
+		com->SetText(L"9600");
+	}
+	else if (setting_dianzicheng_botelv == "19200")
+	{
+		com->SetInternVisible(true);
+		com->SelectItem(5, false, false);
+		com->SetText(L"19200");
+	}
+	else if (setting_dianzicheng_botelv == "38400")
+	{
+		com->SetInternVisible(true);
+		com->SelectItem(6, false, false);
+		com->SetText(L"38400");
+	}
+
 	//系统设置
 	box = static_cast<CCheckBoxUI*>(this->FindSubControl(_T("setting_is_auto_start")));
 	if (CSetting::GetParam("setting_is_auto_start") == "1")
@@ -402,8 +530,8 @@ void CSettingPageUI::InitShow()
 
 	std::vector<std::wstring> usb_devices = CPosPrinterQueue::GetInstance()->getUsbDevices();
 
-	int i = 0;
-	int nSelect = -1;
+	i = 0;
+	nSelect = -1;
 
 	for (std::vector<std::wstring>::iterator it = usb_devices.begin(); it != usb_devices.end(); it++)
 	{
@@ -1119,21 +1247,26 @@ void CSettingPageUI::HandleSelectChangeMsg(TNotifyUI& msg)
 		CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(this->FindSubControl(_T("setting_switch")));
 		pControl->SelectItem(4);
 	}
-	else if (name == _T("setting_xianshi_switch"))
+	else if (name == _T("setting_dianzicheng_switch"))
 	{
 		CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(this->FindSubControl(_T("setting_switch")));
 		pControl->SelectItem(5);
 	}
-	else if (name == _T("setting_system_switch"))
+	else if (name == _T("setting_xianshi_switch"))
 	{
 		CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(this->FindSubControl(_T("setting_switch")));
 		pControl->SelectItem(6);
 	}
-	else if (name == _T("setting_system_about"))
+	else if (name == _T("setting_system_switch"))
 	{
 		CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(this->FindSubControl(_T("setting_switch")));
 		pControl->SelectItem(7);
 	}
+	else if (name == _T("setting_system_about"))
+	{
+		CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(this->FindSubControl(_T("setting_switch")));
+		pControl->SelectItem(8);
+	}
 	else if (name == _T("xianshi_setting_youtu"))
 	{
 		CSetting::SetParam("setting_xianshi_is_youtu", "1");
@@ -1188,6 +1321,7 @@ void CSettingPageUI::HandleItemSelectMsg(TNotifyUI& msg)
 		CComboUI* com = static_cast<CComboUI*>(this->FindSubControl(_T("setting_printer_leixing")));
 
 		CHorizontalLayoutUI* usb_layout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("setting_printer_usb_layout")));
+		CHorizontalLayoutUI* chuankou_layout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("setting_printer_chuankou_layout")));
 		CHorizontalLayoutUI* wangkou_layout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("setting_printer_wangkou_layout")));
 
 		if (com->GetCurSel() == 0)
@@ -1195,6 +1329,7 @@ void CSettingPageUI::HandleItemSelectMsg(TNotifyUI& msg)
 			CSetting::SetParam("setting_printer_leixing", "auto");
 
 			usb_layout->SetVisible(false);
+			chuankou_layout->SetVisible(false);
 			wangkou_layout->SetVisible(false);
 		}
 		else if (com->GetCurSel() == 1)
@@ -1203,6 +1338,7 @@ void CSettingPageUI::HandleItemSelectMsg(TNotifyUI& msg)
 
 			//显示usb布局
 			usb_layout->SetVisible(true);
+			chuankou_layout->SetVisible(false);
 			wangkou_layout->SetVisible(false);
 
 			//usb下拉框默认选中
@@ -1241,6 +1377,7 @@ void CSettingPageUI::HandleItemSelectMsg(TNotifyUI& msg)
 			CSetting::SetParam("setting_printer_leixing", "bingkou");
 
 			usb_layout->SetVisible(false);
+			chuankou_layout->SetVisible(false);
 			wangkou_layout->SetVisible(false);
 		}
 		else if (com->GetCurSel() == 3)
@@ -1248,13 +1385,47 @@ void CSettingPageUI::HandleItemSelectMsg(TNotifyUI& msg)
 			CSetting::SetParam("setting_printer_leixing", "chuankou");
 
 			usb_layout->SetVisible(false);
+			chuankou_layout->SetVisible(true);
 			wangkou_layout->SetVisible(false);
+
+			//串口下拉框默认选中
+			CComboUI* com_chuankou = static_cast<CComboUI*>(this->FindSubControl(_T("setting_printer_com")));
+			com_chuankou->RemoveAll();
+
+			//数据库中保存的之前的设置
+			std::string setting_printer_com = CSetting::GetParam("setting_printer_com");
+			std::wstring ws_setting_printer_com = CLewaimaiString::UTF8ToUnicode(setting_printer_com);
+
+			CComHelper helper;
+			std::vector<std::wstring> com_devices = helper.getComPort();
+
+			int i = 0;
+			int nSelect = -1;
+
+			for (std::vector<std::wstring>::iterator it = com_devices.begin(); it != com_devices.end(); it++)
+			{
+				CListLabelElementUI* elem = new CListLabelElementUI();
+				elem->SetText((*it).c_str());
+				com_chuankou->Add(elem);
+
+				if (*it == ws_setting_printer_com)
+				{
+					nSelect = i;
+				}
+
+				i++;
+			}
+
+			com_chuankou->SetInternVisible(true);
+			com_chuankou->SelectItem(nSelect, false, false);
+			com_chuankou->SetText(CLewaimaiString::UTF8ToUnicode(setting_printer_com).c_str());
 		}
 		else if (com->GetCurSel() == 4)
 		{
 			CSetting::SetParam("setting_printer_leixing", "wangkou");
 
 			usb_layout->SetVisible(false);
+			chuankou_layout->SetVisible(false);
 			wangkou_layout->SetVisible(true);
 
 			std::string setting_printer_wangkou_ip = CSetting::GetParam("setting_printer_wangkou_ip");
@@ -1270,6 +1441,36 @@ void CSettingPageUI::HandleItemSelectMsg(TNotifyUI& msg)
 
 		CSetting::SetParam("setting_printer_usb", CLewaimaiString::UnicodeToUTF8(usb_device));
 	}
+	else if (name == _T("setting_printer_com"))
+	{
+		CComboUI* com = static_cast<CComboUI*>(this->FindSubControl(_T("setting_printer_com")));
+		wstring com_device = com->GetText();
+
+		CSetting::SetParam("setting_printer_com", CLewaimaiString::UnicodeToUTF8(com_device));
+	}
+	else if (name == _T("setting_dianzicheng_xinghao"))
+	{
+		CComboUI* com = static_cast<CComboUI*>(this->FindSubControl(_T("setting_dianzicheng_xinghao")));
+
+		if (com->GetCurSel() == 0)
+		{
+			CSetting::SetParam("setting_dianzicheng_xinghao", "dahua_acs");
+		}
+	}
+	else if (name == _T("setting_dianzicheng_chuankou"))
+	{
+		CComboUI* com = static_cast<CComboUI*>(this->FindSubControl(_T("setting_dianzicheng_chuankou")));
+		wstring com_device = com->GetText();
+
+		CSetting::SetParam("setting_dianzicheng_com", CLewaimaiString::UnicodeToUTF8(com_device));
+	}
+	else if (name == _T("setting_dianzicheng_botelv"))
+	{
+		CComboUI* com = static_cast<CComboUI*>(this->FindSubControl(_T("setting_dianzicheng_botelv")));
+		wstring com_device = com->GetText();
+
+		CSetting::SetParam("setting_dianzicheng_botelv", CLewaimaiString::UnicodeToUTF8(com_device));
+	}
 	else if (name == _T("setting_biaoqian_printer_usb"))
 	{
 		CComboUI* com = static_cast<CComboUI*>(this->FindSubControl(_T("setting_biaoqian_printer_usb")));

+ 1 - 1
zhipuzi_pos_windows/print/CPosPrinterQueue.cpp

@@ -231,7 +231,7 @@ void CPosPrinterQueue::SendDataToShouyinPirnter(std::string data)
 			std::string err = e.what();
 			LOG_INFO("网口打印机连接失败,IP地址:" << wangkou_ip.c_str() << ",错误信息:" << err.c_str());
 
-			MessageBoxW(NULL, (L"厨房网口打印机连接失败,IP地址:" + CLewaimaiString::UTF8ToUnicode(wangkou_ip)).c_str(), L"打印机连接失败", MB_OK);
+			MessageBoxW(NULL, (L"小票网口打印机连接失败,IP地址:" + CLewaimaiString::UTF8ToUnicode(wangkou_ip)).c_str(), L"打印机连接失败", MB_OK);
 			return;
 		}
 	}

+ 25 - 0
zhipuzi_pos_windows/tool/CSetting.cpp

@@ -136,6 +136,12 @@ void CSetting::Init()
 		m_paramsMap[setting_printer_usb] = "";
 	}
 
+	std::string setting_printer_com = "setting_printer_com";
+	if (m_paramsMap.find(setting_printer_com) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_printer_com] = "";
+	}
+
 	std::string setting_printer_wangkou_ip = "setting_printer_wangkou_ip";
 	if (m_paramsMap.find(setting_printer_wangkou_ip) == m_paramsMap.end())
 	{
@@ -228,6 +234,25 @@ void CSetting::Init()
 		m_paramsMap[setting_biaoqian_printer_fangxiang] = "1";
 	}
 
+	//电子秤参数
+	std::string setting_dianzicheng_xinghao = "setting_dianzicheng_xinghao";
+	if (m_paramsMap.find(setting_dianzicheng_xinghao) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_dianzicheng_xinghao] = "dahua_acs";
+	}
+
+	std::string setting_dianzicheng_com = "setting_dianzicheng_com";
+	if (m_paramsMap.find(setting_dianzicheng_com) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_dianzicheng_com] = "";
+	}
+
+	std::string setting_dianzicheng_botelv = "setting_dianzicheng_botelv";
+	if (m_paramsMap.find(setting_dianzicheng_botelv) == m_paramsMap.end())
+	{
+		m_paramsMap[setting_dianzicheng_botelv] = "9600";
+	}
+
 	//系统设置的参数
 	std::string setting_is_auto_start = "setting_is_auto_start";
 	if (CSystem::IsAutoStart() == true)

+ 71 - 62
zhipuzi_pos_windows/wnd/CChengzhongWnd.cpp

@@ -214,13 +214,12 @@ void CChengzhongWnd::SetPrice(std::string price)
 
 void CChengzhongWnd::ReadChuankouValue()
 {
-	//std::string system_setting_jinezhuaqu_setting_xunichuankou_num_2 = CSetting::GetParam("system_setting_jinezhuaqu_setting_xunichuankou_num_2");
-	//std::string system_setting_jinezhuaqu_setting_xunichuankou_botelv = CSetting::GetParam("system_setting_jinezhuaqu_setting_xunichuankou_botelv");
+	std::string setting_dianzicheng_xinghao = CSetting::GetParam("setting_dianzicheng_xinghao");
+	std::string dianzicheng_com = CSetting::GetParam("setting_dianzicheng_com");
+	std::string setting_dianzicheng_botelv = CSetting::GetParam("setting_dianzicheng_botelv");
 
-	//CSerialPort serial(CLewaimaiString::UTF8ToUnicode(system_setting_jinezhuaqu_setting_xunichuankou_num_2), atoi(system_setting_jinezhuaqu_setting_xunichuankou_botelv.c_str()));
-
-	m_serial.setPortNum(L"COM3");
-	m_serial.setBaudRate(9600);
+	m_serial.setPortNum(CLewaimaiString::UTF8ToUnicode(dianzicheng_com));
+	m_serial.setBaudRate(atoi(setting_dianzicheng_botelv.c_str()));
 
 	bool ret = m_serial.openComm();
 	if (!ret)
@@ -229,7 +228,7 @@ void CChengzhongWnd::ReadChuankouValue()
 		m_is_watching = true;
 
 		CLabelUI* pErrorInfo = static_cast<CLabelUI*>(m_pm.FindControl(_T("errinfo")));
-		pErrorInfo->SetText(L"串口打开失败!");
+		pErrorInfo->SetText(L"电子秤连接失败,请检查电子秤连接设置");
 		pErrorInfo->SetVisible(true);
 
 		return;
@@ -240,87 +239,97 @@ void CChengzhongWnd::ReadChuankouValue()
 
 	m_chuankou_string = "";
 
-	char a[1024] = { 0 };
+	char a[100] = { 0 };
 
 	//检查监控模式和波特率,如果变了就关闭掉
 	while (m_is_watching)
 	{
-		memset(a, 0, 1024);
+		memset(a, 0, 100);
 
 		//开始读取串口的数据
 		DWORD nReaded = 0;
 
-		m_serial.readFromComm(a, 1024, &nReaded);
+		m_serial.readFromComm(a, 100, &nReaded);
 
 		if (nReaded > 0)
 		{
-			//把所有读到的内容,拼接到m_chuankou_string后面,避免有的数据中间截断导致格式混乱
-			m_chuankou_string += a;
+			//不同型号的电子秤,数据格式可能不一样,处理方式不一样
+			
+			if (setting_dianzicheng_xinghao == "dahua_acs")
+			{
+				//把所有读到的内容,拼接到m_chuankou_string后面,避免有的数据中间截断导致格式混乱
+				m_chuankou_string += a;
 
-			std::string show_command = "\n\r";
+				std::string show_command = "\n\r";
 
-			size_t nPos = m_chuankou_string.find(show_command);
-			if (nPos == m_chuankou_string.npos)
-			{
-				//没有读到足够的长度,继续读
-				continue;
-			}
+				size_t nPos = m_chuankou_string.find(show_command);
+				if (nPos == m_chuankou_string.npos)
+				{
+					//没有读到足够的长度,继续读
+					continue;
+				}
 
-			std::string weight;
+				std::string weight;
 
-			//如果前2个不是标志符,那么就判断标志符后面的数字长度够不够5个
-			if (m_chuankou_string.length() >= nPos + 7)
-			{
-				//这个情况是,标志符后面有5个数字
-				weight = m_chuankou_string.substr(nPos + 2, 5);
+				//如果前2个不是标志符,那么就判断标志符后面的数字长度够不够5个
+				if (m_chuankou_string.length() >= nPos + 7)
+				{
+					//这个情况是,标志符后面有5个数字
+					weight = m_chuankou_string.substr(nPos + 2, 5);
 
-				//然后把前面的字符都删掉
-				m_chuankou_string = m_chuankou_string.substr(nPos + 7);
-			}
-			else if (nPos >= 20)
-			{
-				//说明前面有20个字符,首先肯定不是稳定模式而是极速模式,另外在极速模式下可以直接得到重量了
-				weight = m_chuankou_string.substr(nPos - 20, 5);
+					//然后把前面的字符都删掉
+					m_chuankou_string = m_chuankou_string.substr(nPos + 7);
+				}
+				else if (nPos >= 20)
+				{
+					//说明前面有20个字符,首先肯定不是稳定模式而是极速模式,另外在极速模式下可以直接得到重量了
+					weight = m_chuankou_string.substr(nPos - 20, 5);
 
-				m_chuankou_string = m_chuankou_string.substr(nPos + 2);
-			}
-			else
-			{
-				//标志符后面前面都不够读取重量,继续读取串口
-				continue;
-			}
+					m_chuankou_string = m_chuankou_string.substr(nPos + 2);
+				}
+				else
+				{
+					//标志符后面前面都不够读取重量,继续读取串口
+					continue;
+				}
 
-			if (weight.at(0) == ' ')
-			{
-				weight = weight.substr(1);
-			}
+				if (weight.at(0) == ' ')
+				{
+					weight = weight.substr(1);
+				}
 
-			std::string zhengshu;
-			std::string xiaoshu;
-			if (weight.length() == 4)
-			{
-				//重量小于10公斤,第一个数字为空
-				zhengshu = weight.substr(0, 1);
-				xiaoshu = weight.substr(1, 3);
-			}
-			else if (weight.length() == 5)
-			{
-				//重量大于10公斤,第一个数字为空
-				zhengshu = weight.substr(0, 2);
-				xiaoshu = weight.substr(2, 3);
+				std::string zhengshu;
+				std::string xiaoshu;
+				if (weight.length() == 4)
+				{
+					//重量小于10公斤,第一个数字为空
+					zhengshu = weight.substr(0, 1);
+					xiaoshu = weight.substr(1, 3);
+				}
+				else if (weight.length() == 5)
+				{
+					//重量大于10公斤,第一个数字为空
+					zhengshu = weight.substr(0, 2);
+					xiaoshu = weight.substr(2, 3);
+				}
+				else
+				{
+					continue;
+				}
+
+				m_weight = zhengshu + "." + xiaoshu;
+
+				SendMessage(WM_CHENGZHONG_SUCCESS, 0, 0);
 			}
 			else
 			{
-				continue;
+				//暂时不支持的其他型号
+				Sleep(100);
 			}
-
-			m_weight = zhengshu + "." + xiaoshu;
-
-			SendMessage(WM_CHENGZHONG_SUCCESS, 0, 0);
 		}
 		else
 		{
-			Sleep(200);
+			Sleep(100);
 		}
 	}