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

00001 /*
00002  * GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics
00003  *               http://gearbox.sf.net/
00004  * Copyright (c) 2008 Geoffrey Biggs
00005  *
00006  * flexiport flexible hardware data communications library.
00007  * 
00008  * This distribution is licensed to you under the terms described in the LICENSE file included in 
00009  * this distribution.
00010  *
00011  * This work is a product of the National Institute of Advanced Industrial Science and Technology,
00012  * Japan. Registration number: H20PRO-881
00013  * 
00014  * This file is part of flexiport.
00015  *
00016  * flexiport is free software: you can redistribute it and/or modify it under the terms of the GNU
00017  * Lesser General Public License as published by the Free Software Foundation, either version 3 of 
00018  * the License, or (at your option) any later version.
00019  *
00020  * flexiport is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
00021  * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022  * Lesser General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU Lesser General Public License along with flexiport.
00025  * If not, see <http://www.gnu.org/licenses/>.
00026  */
00027 
00028 #ifndef __SERIALPORT_H
00029 #define __SERIALPORT_H
00030 
00031 #include "port.h"
00032 
00033 #include <map>
00034 #include <string>
00035 #if defined (WIN32)
00036         #include <Windows.h>
00037 #endif
00038 
00043 namespace flexiport
00044 {
00045 
00072 class FLEXIPORT_EXPORT SerialPort : public Port
00073 {
00074         public:
00075                 SerialPort (std::map<std::string, std::string> options);
00076                 ~SerialPort (void);
00077 
00079                 void Open (void);
00081                 void Close (void);
00083                 ssize_t Read (void * const buffer, size_t count);
00085                 ssize_t ReadFull (void * const buffer, size_t count);
00087                 ssize_t BytesAvailable (void);
00093                 ssize_t BytesAvailableWait (void);
00095                 ssize_t Write (const void * const buffer, size_t count);
00097                 void Flush (void);
00099                 void Drain (void);
00101                 std::string GetStatus (void) const;
00103                 void SetTimeout (Timeout timeout);
00105                 void SetCanRead (bool canRead);
00107                 void SetCanWrite (bool canWrite);
00109                 bool IsOpen (void) const                        { return _open; }
00110 
00112                 void SetBaudRate (unsigned int baud);
00114                 unsigned int GetBaudRate (void) const           { return _baud; }
00115 
00116         private:
00117 #if defined (WIN32)
00118                 HANDLE _fd;             // Serial device handle
00119 #else
00120                 int _fd;                // Serial device file descriptor
00121 #endif
00122 
00123                 std::string _device;
00124                 unsigned int _baud;
00125                 unsigned int _dataBits;
00126                 unsigned int _stopBits;
00127                 typedef enum {PAR_NONE, PAR_EVEN, PAR_ODD} Parity;
00128                 Parity _parity;
00129                 bool _hwFlowCtrl;
00130                 bool _open;
00131 
00132                 void CheckPort (bool read);
00133                 bool ProcessOption (const std::string &option, const std::string &value);
00134 
00135                 bool IsDataAvailable (void);
00136 #if !defined (WIN32)
00137                 typedef enum {TIMED_OUT, DATA_AVAILABLE, CAN_WRITE} WaitStatus;
00138                 WaitStatus WaitForDataOrTimeout (void);
00139                 WaitStatus WaitForWritableOrTimeout (void);
00140 #endif
00141                 void SetPortSettings (void);
00142 #if defined (WIN32)
00143                 void SetPortTimeout (void);
00144 #endif
00145 };
00146 
00147 } // namespace flexiport
00148 
00151 #endif // __SERIALPORT_H
 

Generated for GearBox by  doxygen 1.4.5