wheelsmanx

ArduinoToC++ SerialClass.h

May 29th, 2017
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #pragma once
  2. #ifndef SERIALCLASS_H_INCLUDED
  3. #define SERIALCLASS_H_INCLUDED
  4.  
  5. #define ARDUINO_WAIT_TIME 2000
  6.  
  7. #include <windows.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. class Serial
  12. {
  13. private:
  14. //Serial comm handler
  15. HANDLE hSerial;
  16. //Connection status
  17. bool connected;
  18. //Get various information about the connection
  19. COMSTAT status;
  20. //Keep track of last error
  21. DWORD errors;
  22.  
  23. public:
  24. //Initialize Serial communication with the given COM port
  25. Serial(const char *portName);
  26. //Close the connection
  27. ~Serial();
  28. //Read data in a buffer, if nbChar is greater than the
  29. //maximum number of bytes available, it will return only the
  30. //bytes available. The function return -1 when nothing could
  31. //be read, the number of bytes actually read.
  32. int ReadData(char *buffer, unsigned int nbChar);
  33. //Writes data from a buffer through the Serial connection
  34. //return true on success.
  35. bool WriteData(const char *buffer, unsigned int nbChar);
  36. //Check if we are actually connected
  37. bool IsConnected();
  38.  
  39.  
  40. };
  41.  
  42. #endif // SERIALCLASS_H_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment