WPILib  2014.0
WPIRoboticsLibraryforFRC
 All Classes Functions Variables Pages
SerialPort.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
5 /*----------------------------------------------------------------------------*/
6 
7 #ifndef __SerialPort_h__
8 #define __SerialPort_h__
9 
10 #include "ErrorBase.h"
11 #include <vxWorks.h>
12 
25 class SerialPort : public ErrorBase
26 {
27 public:
28  typedef enum {kParity_None=0, kParity_Odd=1, kParity_Even=2, kParity_Mark=3, kParity_Space=4} Parity;
29  typedef enum {kStopBits_One=10, kStopBits_OnePointFive=15, kStopBits_Two=20} StopBits;
30  typedef enum {kFlowControl_None=0, kFlowControl_XonXoff=1, kFlowControl_RtsCts=2, kFlowControl_DtrDsr=4} FlowControl;
31  typedef enum {kFlushOnAccess=1, kFlushWhenFull=2} WriteBufferMode;
32 
33  SerialPort(uint32_t baudRate, uint8_t dataBits = 8, Parity parity = kParity_None, StopBits stopBits = kStopBits_One);
34  ~SerialPort();
35  void SetFlowControl(FlowControl flowControl);
36  void EnableTermination(char terminator = '\n');
37  void DisableTermination();
38  int32_t GetBytesReceived();
39  void Printf(const char *writeFmt, ...);
40  void Scanf(const char *readFmt, ...);
41  uint32_t Read(char *buffer, int32_t count);
42  uint32_t Write(const char *buffer, int32_t count);
43  void SetTimeout(float timeout);
44  void SetReadBufferSize(uint32_t size);
45  void SetWriteBufferSize(uint32_t size);
46  void SetWriteBufferMode(WriteBufferMode mode);
47  void Flush();
48  void Reset();
49 
50  /*
51  * Do not call me!
52  */
53  //void _internalHandler(uint32_t port, uint32_t eventType, uint32_t event);
54 private:
55  uint32_t m_resourceManagerHandle;
56  uint32_t m_portHandle;
57  bool m_consoleModeEnabled;
58  DISALLOW_COPY_AND_ASSIGN(SerialPort);
59 };
60 
61 #endif
void SetReadBufferSize(uint32_t size)
Definition: SerialPort.cpp:247
void SetFlowControl(FlowControl flowControl)
Definition: SerialPort.cpp:80
void Reset()
Definition: SerialPort.cpp:313
void Scanf(const char *readFmt,...)
Definition: SerialPort.cpp:162
void SetTimeout(float timeout)
Definition: SerialPort.cpp:226
~SerialPort()
Definition: SerialPort.cpp:65
void DisableTermination()
Definition: SerialPort.cpp:111
void Flush()
Definition: SerialPort.cpp:299
Definition: ErrorBase.h:37
SerialPort(uint32_t baudRate, uint8_t dataBits=8, Parity parity=kParity_None, StopBits stopBits=kStopBits_One)
Definition: SerialPort.cpp:22
uint32_t Write(const char *buffer, int32_t count)
Definition: SerialPort.cpp:207
void Printf(const char *writeFmt,...)
Definition: SerialPort.cpp:143
int32_t GetBytesReceived()
Definition: SerialPort.cpp:125
uint32_t Read(char *buffer, int32_t count)
Definition: SerialPort.cpp:181
void EnableTermination(char terminator= '\n')
Definition: SerialPort.cpp:98
void SetWriteBufferSize(uint32_t size)
Definition: SerialPort.cpp:264
Definition: SerialPort.h:25
void SetWriteBufferMode(WriteBufferMode mode)
Definition: SerialPort.cpp:284