Browse Source

称重的优化好了

张洋 4 years ago
parent
commit
6544ab3000

+ 2 - 0
zhipuzi_pos_windows/tool/CSerialPort.cpp

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

+ 18 - 3
zhipuzi_pos_windows/wnd/CChengzhongWnd.cpp

@@ -254,10 +254,9 @@ void CChengzhongWnd::ReadChuankouValue()
 			//把所有读到的内容,拼接到m_chuankou_string后面,避免有的数据中间截断导致格式混乱
 			//把所有读到的内容,拼接到m_chuankou_string后面,避免有的数据中间截断导致格式混乱
 			m_chuankou_string += a;
 			m_chuankou_string += a;
 
 
-			//已经有7个字符了,那么判断是稳定模式还是极速模式
 			std::string show_command = "\n\r";
 			std::string show_command = "\n\r";
 
 
-			int nPos = m_chuankou_string.find(show_command);
+			size_t nPos = m_chuankou_string.find(show_command);
 			if (nPos == m_chuankou_string.npos)
 			if (nPos == m_chuankou_string.npos)
 			{
 			{
 				//没有读到足够的长度,继续读
 				//没有读到足够的长度,继续读
@@ -277,7 +276,7 @@ void CChengzhongWnd::ReadChuankouValue()
 			}
 			}
 			else if (nPos >= 20)
 			else if (nPos >= 20)
 			{
 			{
-				//说明前面有20个字符,在极速模式下可以直接得到重量了
+				//说明前面有20个字符,首先肯定不是稳定模式而是极速模式,另外在极速模式下可以直接得到重量了
 				weight = m_chuankou_string.substr(nPos - 20, 5);
 				weight = m_chuankou_string.substr(nPos - 20, 5);
 
 
 				m_chuankou_string = m_chuankou_string.substr(nPos + 2);
 				m_chuankou_string = m_chuankou_string.substr(nPos + 2);
@@ -316,6 +315,10 @@ void CChengzhongWnd::ReadChuankouValue()
 
 
 			SendMessage(WM_CHENGZHONG_SUCCESS, 0, 0);
 			SendMessage(WM_CHENGZHONG_SUCCESS, 0, 0);
 		}
 		}
+		else
+		{
+			Sleep(200);
+		}
 	}
 	}
 
 
 	m_is_chuangkou_working = false;
 	m_is_chuangkou_working = false;
@@ -323,6 +326,12 @@ void CChengzhongWnd::ReadChuankouValue()
 
 
 void CChengzhongWnd::SaveWeight()
 void CChengzhongWnd::SaveWeight()
 {
 {
+	if (m_is_watching == false)
+	{
+		//串口都还没打开,禁止退出
+		return;
+	}
+
 	CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
 	CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
 	wstring wsReason = pContent->GetText();
 	wstring wsReason = pContent->GetText();
 
 
@@ -353,6 +362,12 @@ void CChengzhongWnd::SaveWeight()
 
 
 void CChengzhongWnd::Quit()
 void CChengzhongWnd::Quit()
 {
 {
+	if (m_is_watching == false)
+	{
+		//串口都还没打开,禁止退出
+		return;
+	}
+
 	m_is_watching = false;
 	m_is_watching = false;
 
 
 	//关闭串口,关闭之后读取串口的工作线程会退出
 	//关闭串口,关闭之后读取串口的工作线程会退出