blob: 192771e15e8db4c6101ee22e099abb4225cab454 [file] [log] [blame]
jerrymf1579332013-02-07 01:56:28 +00001/*----------------------------------------------------------------------------*/
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
13/**
14 * Driver for the RS-232 serial port on the cRIO.
15 *
16 * The current implementation uses the VISA formatted I/O mode. This means that
17 * all traffic goes through the fomatted buffers. This allows the intermingled
18 * use of Printf(), Scanf(), and the raw buffer accessors Read() and Write().
19 *
20 * More information can be found in the NI-VISA User Manual here:
21 * http://www.ni.com/pdf/manuals/370423a.pdf
22 * and the NI-VISA Programmer's Reference Manual here:
23 * http://www.ni.com/pdf/manuals/370132c.pdf
24 */
25class SerialPort : public ErrorBase
26{
27public:
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 baudRate, UINT8 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 GetBytesReceived();
39 void Printf(const char *writeFmt, ...);
40 void Scanf(const char *readFmt, ...);
41 UINT32 Read(char *buffer, INT32 count);
42 UINT32 Write(const char *buffer, INT32 count);
43 void SetTimeout(float timeout);
44 void SetReadBufferSize(UINT32 size);
45 void SetWriteBufferSize(UINT32 size);
46 void SetWriteBufferMode(WriteBufferMode mode);
47 void Flush();
48 void Reset();
49
50 /*
51 * Do not call me!
52 */
53 //void _internalHandler(UINT32 port, UINT32 eventType, UINT32 event);
54private:
55 UINT32 m_resourceManagerHandle;
56 UINT32 m_portHandle;
57 bool m_consoleModeEnabled;
58 DISALLOW_COPY_AND_ASSIGN(SerialPort);
59};
60
61#endif