INTRODUCTION
Overview
Download and Install
Documentation
Publications

REPOSITORY
Libraries

DEVELOPER
Dev Guide
Dashboard

PEOPLE
Contributors
Users

SourceForge.net Logo
Project
Download
Mailing lists

 

         
serialport.h
1/*
2 * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics
3 * http://gearbox.sf.net/
4 * Copyright (c) 2008 Geoffrey Biggs
5 *
6 * flexiport flexible hardware data communications library.
7 *
8 * This distribution is licensed to you under the terms described in the LICENSE file included in
9 * this distribution.
10 *
11 * This work is a product of the National Institute of Advanced Industrial Science and Technology,
12 * Japan. Registration number: H20PRO-881
13 *
14 * This file is part of flexiport.
15 *
16 * flexiport is free software: you can redistribute it and/or modify it under the terms of the GNU
17 * Lesser General Public License as published by the Free Software Foundation, either version 3 of
18 * the License, or (at your option) any later version.
19 *
20 * flexiport is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
21 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public License along with flexiport.
25 * If not, see <http://www.gnu.org/licenses/>.
26 */
27
28#ifndef __SERIALPORT_H
29#define __SERIALPORT_H
30
31#include "port.h"
32
33#include <map>
34#include <string>
35#if defined (WIN32)
36 #include <Windows.h>
37#endif
38
42
43namespace flexiport
44{
45
72class FLEXIPORT_EXPORT SerialPort : public Port
73{
74 public:
75 SerialPort (std::map<std::string, std::string> options);
76 ~SerialPort ();
77
79 void Open ();
81 void Close ();
83 ssize_t Read (void * const buffer, size_t count);
85 ssize_t ReadFull (void * const buffer, size_t count);
87 ssize_t BytesAvailable ();
93 ssize_t BytesAvailableWait ();
95 ssize_t Write (const void * const buffer, size_t count);
97 void Flush ();
99 void Drain ();
101 std::string GetStatus () const;
103 void SetTimeout (Timeout timeout);
105 void SetCanRead (bool canRead);
107 void SetCanWrite (bool canWrite);
109 bool IsOpen () const { return _open; }
110
112 void SetBaudRate (unsigned int baud);
114 unsigned int GetBaudRate () const { return _baud; }
115
116 private:
117#if defined (WIN32)
118 HANDLE _fd; // Serial device handle
119#else
120 int _fd; // Serial device file descriptor
121#endif
122
123 std::string _device;
124 unsigned int _baud;
125 unsigned int _dataBits;
126 unsigned int _stopBits;
127 typedef enum {PAR_NONE, PAR_EVEN, PAR_ODD} Parity;
128 Parity _parity;
129 bool _hwFlowCtrl;
130 bool _open;
131
132 void CheckPort (bool read);
133 bool ProcessOption (const std::string &option, const std::string &value);
134
135 bool IsDataAvailable ();
136#if !defined (WIN32)
137 typedef enum {TIMED_OUT, DATA_AVAILABLE, CAN_WRITE} WaitStatus;
138 WaitStatus WaitForDataOrTimeout ();
139 WaitStatus WaitForWritableOrTimeout ();
140#endif
141 void SetPortSettings ();
142 void SetPortTimeout ();
143};
144
145} // namespace flexiport
146
148
149#endif // __SERIALPORT_H
void Open()
Open the port.
Definition serialport.cpp:316
unsigned int GetBaudRate() const
Get the current baud rate.
Definition serialport.h:114
void SetCanWrite(bool canWrite)
Set the write permissions of the port.
Definition serialport.cpp:793
void Close()
Close the port.
Definition serialport.cpp:381
bool IsOpen() const
Check if the port is open.
Definition serialport.h:109
void Flush()
Flush the port's input and output buffers, discarding all data.
Definition serialport.cpp:701
void SetCanRead(bool canRead)
Set the read permissions of the port.
Definition serialport.cpp:783
ssize_t Write(const void *const buffer, size_t count)
Write data to the port.
Definition serialport.cpp:643
ssize_t BytesAvailableWait()
Get the number of bytes waiting after blocking for the timeout.
Definition serialport.cpp:584
ssize_t BytesAvailable()
Get the number of bytes waiting to be read at the port. Returns immediatly.
Definition serialport.cpp:549
std::string GetStatus() const
Get the status of the port (type, device, etc).
Definition serialport.cpp:747
void Drain()
Drain the port's input and output buffers.
Definition serialport.cpp:722
void SetTimeout(Timeout timeout)
Set the timeout value in milliseconds.
Definition serialport.cpp:777
ssize_t Read(void *const buffer, size_t count)
Read from the port.
Definition serialport.cpp:409
ssize_t ReadFull(void *const buffer, size_t count)
Read the requested quantity of data from the port.
Definition serialport.cpp:491
An object used to represent timeouts.
Definition timeout.h:63
FlexiPort data communications library.
 

Generated for GearBox by  doxygen 1.4.5