rs232-cygwin.h
Go to the documentation of this file.
1 //======================================================================
28 //======================================================================
29 
30 #ifndef RS232_CYGWIN_H_
31 #define RS232_CYGWIN_H_
32 
33 //----------------------------------------------------------------------
34 // System Includes - include with <>
35 //----------------------------------------------------------------------
36 
37 #include <string>
38 #include <termios.h>
39 
40 //----------------------------------------------------------------------
41 // Project Includes - include with ""
42 //----------------------------------------------------------------------
43 
44 #include "sdhexception.h"
45 #include "serialbase.h"
46 #include "sdhlibrary_settings.h"
47 
48 //----------------------------------------------------------------------
49 // Defines, enums, unions, structs,
50 //----------------------------------------------------------------------
51 
53 
54 
55 //----------------------------------------------------------------------
56 // Global variables
57 //----------------------------------------------------------------------
58 
59 
60 //----------------------------------------------------------------------
61 // Function and class member declarations
62 //----------------------------------------------------------------------
63 
64 
65 
66 
67 
72 {
73 public:
74  cRS232Exception( cMsg const & _msg )
75  : cSerialBaseException( "cRS232Exception", _msg )
76  {}
77 };
78 //======================================================================
79 
80 
84 class cRS232 : public cSerialBase
85 {
86 
87 protected:
89  int port;
90 
92  std::string device_format_string;
93 
95  unsigned long baudrate;
96 
98  int fd;
99 
101  tcflag_t BaudrateToBaudrateCode( unsigned long baudrate );
102 
103  int status;
104 
105  termios io_set_old;
106 
107 public:
118  cRS232( int _port, unsigned long _baudrate, double _timeout, char const* _device_format_string = "/dev/ttyS%d" );
119 
132  void Open( void );
133 
135  bool IsOpen( void )
136  throw();
137 
139  void Close( void );
140 
142 
150  int write( char const *ptr, int len=0 );
151 
160  ssize_t Read( void *data, ssize_t size, long timeout_us, bool return_on_less_data );
161 
163  virtual bool UseCRC16()
164  {
165  return true;
166  }
167 
168 };
169 //======================================================================
170 
172 
173 #endif
174 
175 
176 //======================================================================
177 /*
178  Here are some settings for the emacs/xemacs editor (and can be safely ignored):
179  (e.g. to explicitely set C++ mode for *.h header files)
180 
181  Local Variables:
182  mode:C++
183  mode:ELSE
184  End:
185 */
186 //======================================================================
serialbase.h
Interface of class #SDH::cSerialBase, a virtal base class to access serial communication channels lik...
size
UInt16 size
Definition: dsa.h:269
NAMESPACE_SDH_END
#define NAMESPACE_SDH_END
Definition: sdhlibrary_settings.h:80
cSerialBase
Low-level communication class to access a serial port.
Definition: serialbase.h:105
cRS232::cRS232
cRS232(int _port, unsigned long _baudrate, double _timeout, char const *_device_format_string="/dev/ttyS%d")
Definition: rs232-cygwin.cpp:107
cSerialBaseException
Derived exception class for low-level serial communication related exceptions.
Definition: serialbase.h:86
cRS232::baudrate
unsigned long baudrate
the baudrate in bit/s
Definition: rs232-cygwin.h:95
cRS232
Low-level communication class to access a serial port on Cygwin and Linux.
Definition: rs232-cygwin.h:84
cRS232::fd
int fd
the file descriptor of the RS232 port
Definition: rs232-cygwin.h:98
cRS232::Read
ssize_t Read(void *data, ssize_t size, long timeout_us, bool return_on_less_data)
Definition: rs232-cygwin.cpp:341
cRS232::port
int port
the RS232 portnumber to use
Definition: rs232-cygwin.h:89
cMsg
Class for short, fixed maximum length text messages.
Definition: sdhexception.h:77
cRS232::IsOpen
bool IsOpen(void)
Return true if port to RS232 is open.
Definition: rs232-cygwin.cpp:240
cRS232::Close
void Close(void)
Close the previously opened rs232 port.
Definition: rs232-cygwin.cpp:248
cRS232::BaudrateToBaudrateCode
tcflag_t BaudrateToBaudrateCode(unsigned long baudrate)
Translate a baudrate given as unsigned long into a baudrate code for struct termios.
Definition: rs232-cygwin.cpp:258
NAMESPACE_SDH_START
#define NAMESPACE_SDH_START
Definition: sdhlibrary_settings.h:79
cRS232Exception::cRS232Exception
cRS232Exception(cMsg const &_msg)
Definition: rs232-cygwin.h:74
sdhexception.h
Interface of the exception base class #SDH::cSDHLibraryException and #SDH::cMsg.
cRS232Exception
Derived exception class for low-level RS232 related exceptions.
Definition: rs232-cygwin.h:71
cRS232::status
int status
Definition: rs232-cygwin.h:103
sdhlibrary_settings.h
This file contains settings to make the SDHLibrary compile on differen systems:
cRS232::device_format_string
std::string device_format_string
the sprintf format string to generate the device name from the port, see Constructor
Definition: rs232-cygwin.h:92
cRS232::Open
void Open(void)
Definition: rs232-cygwin.cpp:121
cRS232::io_set_old
termios io_set_old
Definition: rs232-cygwin.h:105
cRS232::UseCRC16
virtual bool UseCRC16()
overloaded from cSerialBase::UseCRC16 since we want to use a CRC16 to protect binary RS232 communicat...
Definition: rs232-cygwin.h:163
cRS232::write
int write(char const *ptr, int len=0)
Write data to a previously opened port.
Definition: rs232-cygwin.cpp:321


sdhlibrary_cpp
Author(s): Dirk Osswald
autogenerated on Wed Mar 2 2022 01:00:58