WPILib 2012
WPILibRoboticsLibraryforFRC
SerialPort.h
00001 /*----------------------------------------------------------------------------*/
00002 /* Copyright (c) FIRST 2008. All Rights Reserved.                                                         */
00003 /* Open Source Software - may be modified and shared by FRC teams. The code   */
00004 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib.  */
00005 /*----------------------------------------------------------------------------*/
00006 
00007 #ifndef __SerialPort_h__
00008 #define __SerialPort_h__
00009 
00010 #include "ErrorBase.h"
00011 #include <vxWorks.h>
00012 
00025 class SerialPort : public ErrorBase
00026 {
00027 public:
00028         typedef enum {kParity_None=0, kParity_Odd=1, kParity_Even=2, kParity_Mark=3, kParity_Space=4} Parity;
00029         typedef enum {kStopBits_One=10, kStopBits_OnePointFive=15, kStopBits_Two=20} StopBits;
00030         typedef enum {kFlowControl_None=0, kFlowControl_XonXoff=1, kFlowControl_RtsCts=2, kFlowControl_DtrDsr=4} FlowControl;
00031         typedef enum {kFlushOnAccess=1, kFlushWhenFull=2} WriteBufferMode;
00032 
00033         SerialPort(UINT32 baudRate, UINT8 dataBits = 8, Parity parity = kParity_None, StopBits stopBits = kStopBits_One);
00034         ~SerialPort();
00035         void SetFlowControl(FlowControl flowControl);
00036         void EnableTermination(char terminator = '\n');
00037         void DisableTermination();
00038         INT32 GetBytesReceived();
00039         void Printf(const char *writeFmt, ...);
00040         void Scanf(const char *readFmt, ...);
00041         UINT32 Read(char *buffer, INT32 count);
00042         UINT32 Write(const char *buffer, INT32 count);
00043         void SetTimeout(float timeout);
00044         void SetReadBufferSize(UINT32 size);
00045         void SetWriteBufferSize(UINT32 size);
00046         void SetWriteBufferMode(WriteBufferMode mode);
00047         void Flush();
00048         void Reset();
00049 
00050         /*
00051          * Do not call me!
00052          */
00053         //void _internalHandler(UINT32 port, UINT32 eventType, UINT32 event);
00054 private:
00055         UINT32 m_resourceManagerHandle;
00056         UINT32 m_portHandle;
00057         bool m_consoleModeEnabled;
00058         DISALLOW_COPY_AND_ASSIGN(SerialPort);
00059 };
00060 
00061 #endif
 All Classes Functions Variables