nidas  v1.2-1520
SerialPortIODevice.h
Go to the documentation of this file.
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2 // vim: set shiftwidth=4 softtabstop=4 expandtab:
3 /*
4  ********************************************************************
5  ** NIDAS: NCAR In-situ Data Acquistion Software
6  **
7  ** 2011, Copyright University Corporation for Atmospheric Research
8  **
9  ** This program is free software; you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation; either version 2 of the License, or
12  ** (at your option) any later version.
13  **
14  ** This program is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** The LICENSE.txt file accompanying this software contains
20  ** a copy of the GNU General Public License. If it is not found,
21  ** write to the Free Software Foundation, Inc.,
22  ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  **
24  ********************************************************************
25 */
26 #ifndef NIDAS_CORE_SERIALPORTIODEVICE_H
27 #define NIDAS_CORE_SERIALPORTIODEVICE_H
28 
29 #include "UnixIODevice.h"
30 #include <nidas/util/Termios.h>
32 
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <sys/ioctl.h>
37 
38 #ifdef DEBUG
39 #include <iostream>
40 #endif
41 
42 namespace nidas { namespace core {
43 
48 
49 public:
50 
56  {
57  _termios.setRaw(true);
60  }
61 
66  SerialPortIODevice(const std::string& name):
68  {
69  _termios.setRaw(true);
72  }
73 
78 
82  void open(int flags) throw(nidas::util::IOException);
83 
87  void applyTermios() throw(nidas::util::IOException)
88  {
90  }
91 
93 
116  int getUsecsPerByte() const;
117 
165  void setRTS485(int val) throw(nidas::util::IOException);
166 
170  size_t write(const void *buf, size_t len) throw(nidas::util::IOException);
171 
172 protected:
173 
175 
176  int _rts485;
177 
178  unsigned int _usecsperbyte;
179 
180 };
181 
182 }} // namespace nidas namespace core
183 
184 #endif
A serial port.
Definition: SerialPortIODevice.h:47
void open(int flags)
open the device.
Definition: SerialPortIODevice.cc:45
size_t write(const void *buf, size_t len)
Write to the device.
Definition: SerialPortIODevice.cc:110
unsigned int _usecsperbyte
Definition: SerialPortIODevice.h:178
~SerialPortIODevice()
Destructor.
Definition: SerialPortIODevice.h:77
SerialPortIODevice()
Constructor.
Definition: SerialPortIODevice.h:54
nidas::util::Termios & termios()
Definition: SerialPortIODevice.h:92
void setRawTimeout(unsigned char val)
Definition: Termios.cc:349
virtual const std::string & getName() const
Definition: IODevice.h:57
void apply(int fd, const std::string &devname)
Set the termios options on a serial port.
Definition: Termios.cc:104
int _fd
Definition: UnixIODevice.h:149
int _rts485
Definition: SerialPortIODevice.h:176
A basic Unix I/O device, such as a named pipe, or a watched file.
Definition: UnixIODevice.h:49
int len
Definition: sing.cc:934
Definition: IOException.h:37
void setRTS485(int val)
Is this a RS485 half-duplex device, and if so, can the transmitter on the data system be enabled/disa...
Definition: SerialPortIODevice.cc:88
int getUsecsPerByte() const
Calculate the transmission time of each byte from this serial port.
Definition: SerialPortIODevice.cc:70
nidas::util::Termios _termios
Definition: SerialPortIODevice.h:174
SerialPortIODevice(const std::string &name)
Constructor, passing the name of the device.
Definition: SerialPortIODevice.h:66
void applyTermios()
Apply the current Termios to an opened port.
Definition: SerialPortIODevice.h:87
void setRaw(bool val)
Sets termios options for raw or non-raw(cooked) mode.
Definition: Termios.cc:307
void setRawLength(unsigned char val)
Definition: Termios.cc:342
A class providing get/set methods into a termios structure.
Definition: Termios.h:48