Advertisement
Guest User

Serial Port Write Example

a guest
Jul 12th, 2012
862
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. // Construct command to turn off telemetry.
  2. // This is specific to my application, you could write whatever you want to your serial port.
  3. // Or you could read whatever you want.
  4. CString stop_tlm_msg;
  5. stop_tlm_msg = "toff\r";
  6.  
  7. try
  8. {
  9. COMMCONFIG config;
  10. Serial_Port::GetDefaultConfig(3, config);
  11.  
  12. Serial_Port port;
  13. port.open_port(3,
  14. 115200,
  15. Serial_Port::NoParity,
  16. 8,
  17. Serial_Port::OneStopBit,
  18. Serial_Port::NoFlowControl,
  19. false);
  20.  
  21. port.Set0WriteTimeout();
  22. port.Set0ReadTimeout();
  23.  
  24. // First stop telemetry output.
  25. char * sBuf1 = stop_tlm_msg.GetBuffer();
  26. port.Write(sBuf1, strlen(sBuf1));
  27.  
  28. port.ClearWriteBuffer();
  29.  
  30. port.ClearReadBuffer();
  31.  
  32. port.Flush();
  33.  
  34. port.close_port();
  35. }
  36. catch (CSerialException* pEx)
  37. {
  38. TRACE(_T("Serial Port Error:%s\n"), pEx->GetErrorMessage());
  39. pEx->Delete();
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement