// Demo.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include "Demo.h" #include "TCLCommand.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // 唯一的应用程序对象 CWinApp theApp; using namespace std; int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; // 初始化 MFC 并在失败时显示错误 if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: 更改错误代码以符合您的需要 _tprintf(_T("错误: MFC 初始化失败\n")); nRetCode = 1; } else { // TODO: 在此处为应用程序的行为编写代码。 #if 0 TCLCommand tcl(true); if (tcl.Open(23, _T("baud=115200 parity=N data=8 stop=1")) ) { tcl.SetTimeouts(); std::vector vtCommandParams; tcl.parse_cmd_param_from_file("F:\\source\\scbc_repos\\Serail-Demo\\Demo\\command.data", vtCommandParams); for ( std::vector::iterator it = vtCommandParams.begin(); it != vtCommandParams.end(); it++ ) { if ( !_tcsicmp(it->name.c_str(), _T("LeaveFactory")) ) break; byte szData[1024] = {0}; std::string cmd = tcl.PackingCommand(*it, _T(""), 0); if (tcl.WriteSync((void*)cmd.c_str(), cmd.size()) ) { Sleep(it->read_wait_time); int c = tcl.ReadSync(szData, 1024); 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); } } } #else TCLCommand tcl(false); if ( tcl.Open(23, _T("baud=115200 parity=N data=8 stop=1") ) ) { tcl.SetTimeouts(); std::vector vtCommandParams; tcl.parse_cmd_param_from_file("F:\\source\\scbc_repos\\Serail-Demo\\Demo\\command.data", vtCommandParams); for ( std::vector::iterator it = vtCommandParams.begin(); it != vtCommandParams.end(); it++ ) { if ( !_tcsicmp(it->name.c_str(), _T("LeaveFactory")) ) break; byte szData[1024] = {0}; std::string cmd = tcl.PackingCommand(*it, _T(""), 0); //sb.Read(szData, 1024, 100); if ( tcl.Write((void*)cmd.c_str(), cmd.size()) ) { Sleep(it->read_wait_time); 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); } tcl.ClearCommBuffer(); } } #endif system("pause"); } return nRetCode; }