Demo.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Demo.cpp : 定义控制台应用程序的入口点。
  2. //
  3. #include "stdafx.h"
  4. #include "Demo.h"
  5. #ifdef _DEBUG
  6. #define new DEBUG_NEW
  7. #endif
  8. // 唯一的应用程序对象
  9. CWinApp theApp;
  10. using namespace std;
  11. int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
  12. {
  13. int nRetCode = 0;
  14. // 初始化 MFC 并在失败时显示错误
  15. if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
  16. {
  17. // TODO: 更改错误代码以符合您的需要
  18. _tprintf(_T("错误: MFC 初始化失败\n"));
  19. nRetCode = 1;
  20. }
  21. else
  22. {
  23. // TODO: 在此处为应用程序的行为编写代码。
  24. CBaseSerial sb;
  25. if ( sb.Open(23, _T("baud=115200 parity=N data=8 stop=1") ) )
  26. {
  27. sb.SetTimeouts();
  28. std::vector<CommandParam> vtCommandParams;
  29. parse_cmd_param_from_file("F:\\source\\scbc_repos\\Serail-Demo\\Demo\\command.data", vtCommandParams);
  30. for ( std::vector<CommandParam>::iterator it = vtCommandParams.begin(); it != vtCommandParams.end(); it++ )
  31. {
  32. byte szData[1024] = {0};
  33. std::string cmd = PackingCommand(*it, _T(""), 0);
  34. //sb.Read(szData, 1024, 100);
  35. if ( sb.Write((void*)cmd.c_str(), cmd.size()) )
  36. {
  37. Sleep(it->read_wait_time);
  38. int c = sb.Read(szData, 1024);
  39. int a = 0;
  40. }
  41. }
  42. }
  43. system("pause");
  44. }
  45. return nRetCode;
  46. }