Преглед изворни кода

称重的串口这里还有问题,要调试

张洋 пре 4 година
родитељ
комит
aa9918d021

+ 1 - 1
bin/Win32/Debug/zhipuzi_pos_windows/skin/chengzhong_wnd.xml

@@ -13,7 +13,7 @@
 		<HorizontalLayout padding="0,30,0,0">
 			<Label text="重量:"  height="30" width="60" padding="30,0,0,0" align="left"/>
 			<Edit name="content" enabled="false" text="" width="250" height="50" padding="30,0,0,0" textcolor="0xFF3CB371" bkcolor="#FFF2F2F2" nativebkcolor="#FFF2F2F2" font="1"/>
-			<Label text="公斤"  height="30" width="60" padding="30,0,0,0" align="left"/>
+			<Label text="公斤"  height="30" width="60" padding="30,10,0,0" align="left"/>
 		</HorizontalLayout>
 		
 		<Label name="errinfo" text=""  height="60" width="250" float="true" pos="30,230,280,290" align="left" textcolor="#FFFF0000" visible="false"/>

+ 27 - 9
zhipuzi_pos_windows/wnd/CChengzhongWnd.cpp

@@ -245,6 +245,8 @@ void CChengzhongWnd::ReadChuankouValue()
 		//开始读取串口的数据
 		DWORD nReaded = 0;
 
+		Sleep(2000);
+
 		serial.readFromComm(a, 1024, &nReaded);
 
 		if (nReaded > 0)
@@ -252,6 +254,13 @@ void CChengzhongWnd::ReadChuankouValue()
 			//把所有读到的内容,拼接到m_chuankou_string后面,避免有的数据中间截断导致格式混乱
 			m_chuankou_string += a;
 
+			if (m_chuankou_string.length() < 7)
+			{
+				//没有读到足够的长度,继续读(稳定模式7个字符,极速模式22个字符)
+				continue;
+			}
+
+			//已经有7个字符了,那么判断是稳定模式还是极速模式
 			std::string show_command = "\n\r";
 
 			int nPos = m_chuankou_string.find(show_command);
@@ -264,12 +273,6 @@ void CChengzhongWnd::ReadChuankouValue()
 			if (nPos == 0)
 			{
 				//稳定模式
-				if (m_chuankou_string.length() < 7)
-				{
-					//没有读到足够的长度,继续读
-					continue;
-				}
-
 				std::string weight;
 				weight = m_chuankou_string.substr(nPos + 2, 5);
 				m_chuankou_string = m_chuankou_string.substr(7);
@@ -302,7 +305,7 @@ void CChengzhongWnd::ReadChuankouValue()
 			}
 			else
 			{
-				//稳定模式
+				//极速模式
 				if (m_chuankou_string.length() < 22)
 				{
 					//没有读到足够的长度,继续读
@@ -342,8 +345,10 @@ void CChengzhongWnd::ReadChuankouValue()
 
 			SendMessage(WM_CHENGZHONG_SUCCESS, 0, 0);
 		}
-
-		Sleep(100);
+		else
+		{
+			Sleep(100);
+		}
 	}
 
 	serial.closeComm();
@@ -353,6 +358,19 @@ void CChengzhongWnd::ReadChuankouValue()
 
 void CChengzhongWnd::SaveWeight()
 {
+	if (m_is_watching == false || m_is_chuangkou_working == false)
+	{
+		return;
+	}
+
+	m_is_watching = false;
+
+	//等待串口关闭
+	while (m_is_chuangkou_working)
+	{
+		Sleep(100);
+	}
+
 	CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
 	wstring wsReason = pContent->GetText();