VectorNav C++ Library
serialport.h
1 #ifndef _VN_XPLAT_SERIALPORT_H_
2 #define _VN_XPLAT_SERIALPORT_H_
3 
4 #if _MSC_VER && _WIN32
5  #pragma comment(lib, "setupapi.lib")
6 #endif
7 
8 #include <string>
9 #include <vector>
10 #include <list>
11 
12 #if PYTHON
13  #include "boostpython.h"
14 #endif
15 
16 #include "int.h"
17 #include "port.h"
18 #include "nocopy.h"
19 #include "export.h"
20 
21 namespace vn {
22 namespace xplat {
23 
34 class vn_proglib_DLLEXPORT SerialPort : public IPort, util::NoCopy
35 {
36 
37  // Types //////////////////////////////////////////////////////////////////
38 
39 public:
40 
41  enum StopBits
42  {
43  ONE_STOP_BIT,
44  TWO_STOP_BITS
45  };
46 
47  // Constructors ///////////////////////////////////////////////////////////
48 
49 public:
50 
56  SerialPort(const std::string& portName, uint32_t baudrate);
57 
58  ~SerialPort();
59 
60  // Public Methods /////////////////////////////////////////////////////////
61 
62 public:
63 
68  static std::vector<std::string> getPortNames();
69 
70  virtual void open();
71 
72  virtual void close();
73 
74  virtual bool isOpen();
75 
76  virtual void write(const char data[], size_t length);
77 
78  virtual void read(char dataBuffer[], size_t numOfBytesToRead, size_t &numOfBytesActuallyRead);
79 
80  virtual void registerDataReceivedHandler(void* userData, DataReceivedHandler handler);
81 
82  virtual void unregisterDataReceivedHandler();
83 
87  uint32_t baudrate();
88 
92  std::string port();
93 
97  void changeBaudrate(uint32_t br);
98 
102  StopBits stopBits();
103 
107  void setStopBits(StopBits stopBits);
108 
110 
115  size_t NumberOfReceiveDataDroppedSections();
116 
122  static bool determineIfPortIsOptimized(std::string portName);
123 
130  static void optimizePort(std::string portName);
131 
132  #if PYTHON && !PL156_ORIGINAL && !PL156_FIX_ATTEMPT_1
133 
134  virtual void stopThread();
135  virtual void resumeThread();
136  virtual bool threadStopped();
137 
138  #endif
139 
140  // Private Members ////////////////////////////////////////////////////////
141 
142 private:
143 
144  // Contains internal data, mainly stuff that is required for cross-platform
145  // support.
146  struct Impl;
147  Impl *_pi;
148 
149 };
150 
151 }
152 }
153 
154 #endif
Interface for a simple port.
Definition: port.h:12
Represents a cross-platform serial port.
Definition: serialport.h:34
Definition: mock.h:4
Identifies a derived class as being unable to be copied and prevents copy attempts.
Definition: nocopy.h:21
Definition: attitude.h:8