2009-08-28 23:21:26 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2009, Haiku, Inc. All rights reserved.
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2002-08-11 02:45:28 +04:00
|
|
|
#ifndef _SERIAL_PORT_H
|
|
|
|
#define _SERIAL_PORT_H
|
|
|
|
|
|
|
|
#include <BeBuild.h>
|
|
|
|
#include <OS.h>
|
|
|
|
#include <SupportDefs.h>
|
|
|
|
|
2009-08-28 23:21:26 +04:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2002-08-11 02:45:28 +04:00
|
|
|
class BList;
|
|
|
|
|
2009-08-28 23:21:26 +04:00
|
|
|
enum data_rate {
|
|
|
|
B_0_BPS = 0,
|
|
|
|
B_50_BPS,
|
|
|
|
B_75_BPS,
|
|
|
|
B_110_BPS,
|
|
|
|
B_134_BPS,
|
|
|
|
B_150_BPS,
|
|
|
|
B_200_BPS,
|
|
|
|
B_300_BPS,
|
|
|
|
B_600_BPS,
|
|
|
|
B_1200_BPS,
|
|
|
|
B_1800_BPS,
|
|
|
|
B_2400_BPS,
|
|
|
|
B_4800_BPS,
|
|
|
|
B_9600_BPS,
|
|
|
|
B_19200_BPS,
|
|
|
|
B_38400_BPS,
|
|
|
|
B_57600_BPS,
|
|
|
|
B_115200_BPS,
|
|
|
|
B_230400_BPS,
|
|
|
|
B_31250_BPS
|
|
|
|
};
|
|
|
|
|
|
|
|
enum data_bits {
|
|
|
|
B_DATA_BITS_7,
|
|
|
|
B_DATA_BITS_8
|
|
|
|
};
|
2002-08-11 02:45:28 +04:00
|
|
|
|
2009-08-28 23:21:26 +04:00
|
|
|
enum stop_bits {
|
|
|
|
B_STOP_BITS_1,
|
|
|
|
B_STOP_BITS_2
|
|
|
|
};
|
2002-08-11 02:45:28 +04:00
|
|
|
|
|
|
|
#define B_STOP_BIT_1 B_STOP_BITS_1
|
|
|
|
|
2009-08-28 23:21:26 +04:00
|
|
|
enum parity_mode {
|
|
|
|
B_NO_PARITY,
|
|
|
|
B_ODD_PARITY,
|
|
|
|
B_EVEN_PARITY
|
|
|
|
};
|
2002-08-11 02:45:28 +04:00
|
|
|
|
2009-08-28 23:21:26 +04:00
|
|
|
enum {
|
|
|
|
B_NOFLOW_CONTROL = 0,
|
|
|
|
B_HARDWARE_CONTROL = 0x00000001,
|
|
|
|
B_SOFTWARE_CONTROL = 0x00000002
|
|
|
|
};
|
2002-08-11 02:45:28 +04:00
|
|
|
|
|
|
|
|
2009-08-28 23:21:26 +04:00
|
|
|
class BSerialPort {
|
2002-08-11 02:45:28 +04:00
|
|
|
public:
|
2009-08-28 23:21:26 +04:00
|
|
|
BSerialPort();
|
|
|
|
virtual ~BSerialPort();
|
2002-08-11 02:45:28 +04:00
|
|
|
|
2009-08-28 23:21:26 +04:00
|
|
|
status_t Open(const char* portName);
|
|
|
|
void Close();
|
2002-08-11 02:45:28 +04:00
|
|
|
|
2009-08-28 23:21:26 +04:00
|
|
|
ssize_t Read(void* buf, size_t count);
|
|
|
|
ssize_t Write(const void* buf, size_t count);
|
|
|
|
void SetBlocking(bool blocking);
|
|
|
|
status_t SetTimeout(bigtime_t microSeconds);
|
2002-08-11 02:45:28 +04:00
|
|
|
|
2009-08-28 23:21:26 +04:00
|
|
|
status_t SetDataRate(data_rate bitsPerSecond);
|
|
|
|
data_rate DataRate();
|
2002-08-11 02:45:28 +04:00
|
|
|
|
2009-08-28 23:21:26 +04:00
|
|
|
void SetDataBits(data_bits numBits);
|
|
|
|
data_bits DataBits();
|
|
|
|
void SetStopBits(stop_bits numBits);
|
|
|
|
stop_bits StopBits();
|
2002-08-11 02:45:28 +04:00
|
|
|
|
2009-08-28 23:21:26 +04:00
|
|
|
void SetParityMode(parity_mode which);
|
|
|
|
parity_mode ParityMode();
|
2002-08-11 02:45:28 +04:00
|
|
|
|
2009-08-28 23:21:26 +04:00
|
|
|
void ClearInput();
|
|
|
|
void ClearOutput();
|
2002-08-11 02:45:28 +04:00
|
|
|
|
2009-08-28 23:21:26 +04:00
|
|
|
void SetFlowControl(uint32 method);
|
|
|
|
uint32 FlowControl();
|
2002-08-11 02:45:28 +04:00
|
|
|
|
2009-08-28 23:21:26 +04:00
|
|
|
status_t SetDTR(bool asserted);
|
|
|
|
status_t SetRTS(bool asserted);
|
|
|
|
status_t NumCharsAvailable(int32* waitThisMany);
|
2002-08-11 02:45:28 +04:00
|
|
|
|
2009-08-28 23:21:26 +04:00
|
|
|
bool IsCTS();
|
|
|
|
bool IsDSR();
|
|
|
|
bool IsRI();
|
|
|
|
bool IsDCD();
|
|
|
|
|
|
|
|
ssize_t WaitForInput();
|
2002-08-11 02:45:28 +04:00
|
|
|
|
2009-08-28 23:21:26 +04:00
|
|
|
int32 CountDevices();
|
|
|
|
status_t GetDeviceName(int32 index, char* name,
|
|
|
|
size_t bufSize = B_OS_NAME_LENGTH);
|
2002-08-11 02:45:28 +04:00
|
|
|
|
|
|
|
private:
|
2009-08-28 23:21:26 +04:00
|
|
|
void _ScanDevices();
|
|
|
|
int _DriverControl();
|
|
|
|
virtual void _ReservedSerialPort1();
|
|
|
|
virtual void _ReservedSerialPort2();
|
|
|
|
virtual void _ReservedSerialPort3();
|
|
|
|
virtual void _ReservedSerialPort4();
|
|
|
|
|
|
|
|
int ffd;
|
|
|
|
data_rate fBaudRate;
|
|
|
|
data_bits fDataBits;
|
|
|
|
stop_bits fStopBits;
|
|
|
|
parity_mode fParityMode;
|
|
|
|
uint32 fFlow;
|
|
|
|
bigtime_t fTimeout;
|
|
|
|
bool fBlocking;
|
|
|
|
BList* fDevices;
|
|
|
|
uint32 fReserved[3];
|
2002-08-11 02:45:28 +04:00
|
|
|
};
|
|
|
|
|
2009-08-28 23:21:26 +04:00
|
|
|
#endif //_SERIAL_PORT_H
|