Restore the "GPL licensing not permitted" in GLUT license headers.
[haiku.git] / headers / os / device / SerialPort.h
blob93a70cb4e6371e66410668575ae49790f35830bf
1 /*
2 * Copyright 2009, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _SERIAL_PORT_H
6 #define _SERIAL_PORT_H
8 #include <BeBuild.h>
9 #include <OS.h>
10 #include <SupportDefs.h>
12 #include <stddef.h>
14 class BList;
16 enum data_rate {
17 B_0_BPS = 0,
18 B_50_BPS,
19 B_75_BPS,
20 B_110_BPS,
21 B_134_BPS,
22 B_150_BPS,
23 B_200_BPS,
24 B_300_BPS,
25 B_600_BPS,
26 B_1200_BPS,
27 B_1800_BPS,
28 B_2400_BPS,
29 B_4800_BPS,
30 B_9600_BPS,
31 B_19200_BPS,
32 B_38400_BPS,
33 B_57600_BPS,
34 B_115200_BPS,
35 B_230400_BPS,
36 B_31250_BPS
39 enum data_bits {
40 B_DATA_BITS_7,
41 B_DATA_BITS_8
44 enum stop_bits {
45 B_STOP_BITS_1,
46 B_STOP_BITS_2
49 #define B_STOP_BIT_1 B_STOP_BITS_1
51 enum parity_mode {
52 B_NO_PARITY,
53 B_ODD_PARITY,
54 B_EVEN_PARITY
57 enum {
58 B_NOFLOW_CONTROL = 0,
59 B_HARDWARE_CONTROL = 0x00000001,
60 B_SOFTWARE_CONTROL = 0x00000002
64 class BSerialPort {
65 public:
66 BSerialPort();
67 virtual ~BSerialPort();
69 status_t Open(const char* portName);
70 void Close();
72 ssize_t Read(void* buf, size_t count);
73 ssize_t Write(const void* buf, size_t count);
74 void SetBlocking(bool blocking);
75 status_t SetTimeout(bigtime_t microSeconds);
77 status_t SetDataRate(data_rate bitsPerSecond);
78 data_rate DataRate();
80 void SetDataBits(data_bits numBits);
81 data_bits DataBits();
82 void SetStopBits(stop_bits numBits);
83 stop_bits StopBits();
85 void SetParityMode(parity_mode which);
86 parity_mode ParityMode();
88 void ClearInput();
89 void ClearOutput();
91 void SetFlowControl(uint32 method);
92 uint32 FlowControl();
94 status_t SetDTR(bool asserted);
95 status_t SetRTS(bool asserted);
96 status_t NumCharsAvailable(int32* waitThisMany);
98 bool IsCTS();
99 bool IsDSR();
100 bool IsRI();
101 bool IsDCD();
103 ssize_t WaitForInput();
105 int32 CountDevices();
106 status_t GetDeviceName(int32 index, char* name,
107 size_t bufSize = B_OS_NAME_LENGTH);
109 private:
110 void _ScanDevices();
111 int _DriverControl();
112 virtual void _ReservedSerialPort1();
113 virtual void _ReservedSerialPort2();
114 virtual void _ReservedSerialPort3();
115 virtual void _ReservedSerialPort4();
117 int ffd;
118 data_rate fBaudRate;
119 data_bits fDataBits;
120 stop_bits fStopBits;
121 parity_mode fParityMode;
122 uint32 fFlow;
123 bigtime_t fTimeout;
124 bool fBlocking;
125 BList* fDevices;
126 uint32 fReserved[3];
129 #endif //_SERIAL_PORT_H