Ver Fonte

修正VC9.0运行配置。

sat23 há 4 anos atrás
pai
commit
884810069f

+ 14 - 11
Serail-Demo/Demo/Demo.cpp

@@ -30,7 +30,7 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
 	else
 	{
 		// TODO: 在此处为应用程序的行为编写代码。
-#if 1
+#if 0
 		TCLCommand tcl(true);
 		if (tcl.Open(23, _T("baud=115200 parity=N data=8 stop=1")) )
 		{
@@ -59,30 +59,33 @@ int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
 			}
 		}
 #else
-		CBaseSerial sb;
-		if ( sb.Open(23, _T("baud=115200 parity=N data=8 stop=1") ) )
+		TCLCommand tcl(false);
+		if ( tcl.Open(23, _T("baud=115200 parity=N data=8 stop=1") ) )
 		{
-			sb.SetTimeouts();
+			tcl.SetTimeouts();
 			std::vector<CommandParam> vtCommandParams;
-			parse_cmd_param_from_file("F:\\source\\scbc_repos\\Serail-Demo\\Demo\\command.data", vtCommandParams);
+			tcl.parse_cmd_param_from_file("F:\\source\\scbc_repos\\Serail-Demo\\Demo\\command.data", vtCommandParams);
 			for ( std::vector<CommandParam>::iterator it = vtCommandParams.begin(); it != vtCommandParams.end(); it++ )
 			{
 				if ( !_tcsicmp(it->name.c_str(), _T("LeaveFactory")) )
 					break;
 				byte szData[1024] = {0};
-				std::string cmd = PackingCommand(*it, _T(""), 0);
+				std::string cmd = tcl.PackingCommand(*it, _T(""), 0);
 				//sb.Read(szData, 1024, 100);
-				if ( sb.Write((void*)cmd.c_str(), cmd.size()) )
+				if ( tcl.Write((void*)cmd.c_str(), cmd.size()) )
 				{
 					Sleep(it->read_wait_time);
-					int c = sb.Read(szData, 1024, 200);
-					std::string str = BytesToHexString(szData, c, ' ');
-					_dprintf("结果:%s", str.c_str());
+					int c = tcl.Read(szData, 1024, 200);
+					std::string str = utils::BytesToHexString(szData, c, ' ');
+					utils::_dprintf("结果:%s", str.c_str());
 
+					str = "";
+					str.append((char*)szData, c);
+					tcl.ParseResultString(*it, str, str.size());
 					Sleep(it->cmd_wait_time);
 				}
 
-				sb.ClearCommBuffer();
+				tcl.ClearCommBuffer();
 			}
 		}
 #endif

+ 8 - 0
Serail-Demo/Demo/Demo.vcproj

@@ -204,6 +204,10 @@
 				RelativePath=".\TCLCommand.cpp"
 				>
 			</File>
+			<File
+				RelativePath=".\utils.cpp"
+				>
+			</File>
 		</Filter>
 		<Filter
 			Name="Í·Îļþ"
@@ -234,6 +238,10 @@
 				RelativePath=".\TCLCommand.h"
 				>
 			</File>
+			<File
+				RelativePath=".\utils.h"
+				>
+			</File>
 		</Filter>
 		<Filter
 			Name="×ÊÔ´Îļþ"

+ 2 - 3
Serail-Demo/Demo/TCLCommand.cpp

@@ -76,8 +76,7 @@ bool TCLCommand::parse_pair_key(std::string& RetValue, std::string strLine, TCHA
 	if (2 == _stscanf_s(strLine.c_str(), _T("%[^=]=%s"), szText, MAX_PATH, szValue, MAX_PATH))
 #endif
 	{
-		if (_tcsstr(szText, lpszText))
-		{
+		if (_tcsstr(szText, lpszText)) {
 			RetValue = szValue;
 			return true;
 		}
@@ -174,7 +173,7 @@ bool TCLCommand::TheFirstPart(CommandParam& cmdPara, std::string data)
 			// 长度;
 			int nPackageLen = (byte)data[1];
 			if (nPackageLen != NoneOptLen) {
-				cmdPara._rtnError = utils::_dprintf("None长度错误:%ld", (byte)data[1]);
+				cmdPara._rtnError = utils::_dprintf("长度错误:%ld", (byte)data[1]);
 				return false;
 			}
 

+ 1 - 1
Serail-Demo/Demo/TCLCommand.h

@@ -21,7 +21,7 @@ typedef struct __CMDPARAM__ {
 	int nOption;
 	bool bMulticode;		// 命令码是否多参数;
 	int cmd_wait_time;		// 两条串口指令间隔时间;
-	int read_wait_time;	// 写完串口后,等待多久读;
+	int read_wait_time;		// 写完串口后,等待多久读;
 	byte _rtnCode;
 	byte _rtnStatus;
 	std::string _rtnData;