tcpserial.h
Go to the documentation of this file.
1 //======================================================================
28 //======================================================================
29 
30 #ifndef TCP_SERIAL_H_
31 #define TCP_SERIAL_H_
32 
33 //----------------------------------------------------------------------
34 // System Includes - include with <>
35 //----------------------------------------------------------------------
36 
37 #if SDH_USE_VCC
38 # include <sys/timeb.h>
39 # include <time.h>
40 # include <winsock.h>
41 #else
42 # include <sys/time.h>
43 #endif
44 #include <string>
45 
46 //----------------------------------------------------------------------
47 // Project Includes - include with ""
48 //----------------------------------------------------------------------
49 
50 #include "sdhexception.h"
51 #include "serialbase.h"
52 #include "basisdef.h"
53 
54 #include "sdhlibrary_settings.h"
55 
56 //----------------------------------------------------------------------
57 // Defines, enums, unions, structs,
58 //----------------------------------------------------------------------
59 
61 
62 //----------------------------------------------------------------------
63 // Global variables
64 //----------------------------------------------------------------------
65 
66 
67 //----------------------------------------------------------------------
68 // Function and class member declarations
69 //----------------------------------------------------------------------
70 
71 
75 class VCC_EXPORT cTCPSerialException: public cSerialBaseException
76 {
77 public:
78  cTCPSerialException( cMsg const & _msg )
79  : cSerialBaseException( "cTCPSerialException", _msg )
80  {}
81 };
82 //======================================================================
83 
84 
88 class VCC_EXPORT cTCPSerial : public cSerialBase
89 {
90 
91 protected:
92 
93  std::string tcp_adr;
94 
96  int tcp_port;
97 
99 #if SDH_USE_VCC
100  SOCKET fd;
101 #else
102  int fd;
103  static const int INVALID_SOCKET = -1;
104 #endif
105 private:
107  struct timeval timeout_timeval;
110 
111 public:
112  static double const TIMEOUT_WAIT_FOR_EVER_S;
113  static double const TIMEOUT_RETURN_IMMEDITELY_S;
114  static long const TIMEOUT_WAIT_FOR_EVER_US;
115  static long const TIMEOUT_RETURN_IMMEDITELY_US;
116 
126  cTCPSerial( char const* _tcp_adr, int _tcp_port, double _timeout );
127 
131  void Open( void );
132 
134  bool IsOpen( void )
135  throw();
136 
138  void Close( void );
139 
141 
149  int write( char const *ptr, int len=0 );
150 
159  ssize_t Read( void *data, ssize_t size, long timeout_us, bool return_on_less_data );
160 
162  void SetTimeout( double _timeout );
163 
168  {
169 #if SDH_USE_VCC
170  return WSAGetLastError();
171 #else
172  return errno;
173 #endif
174  }
175 };
176 //======================================================================
177 
179 
180 #endif
181 
182 
183 //======================================================================
184 /*
185  Here are some settings for the emacs/xemacs editor (and can be safely ignored):
186  (e.g. to explicitely set C++ mode for *.h header files)
187 
188  Local Variables:
189  mode:C++
190  mode:ELSE
191  End:
192 */
193 //======================================================================
cTCPSerial::tcp_port
int tcp_port
the TCP port to use
Definition: tcpserial.h:96
serialbase.h
Interface of class #SDH::cSerialBase, a virtal base class to access serial communication channels lik...
cSerialBase::Close
virtual void Close(void)=0
Close the previously opened communication channel.
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
cTCPSerial::fd
int fd
the file descriptor of the socket
Definition: tcpserial.h:102
cSerialBase::IsOpen
virtual bool IsOpen(void)=0
Return true if communication channel is open.
cSerialBaseException
Derived exception class for low-level serial communication related exceptions.
Definition: serialbase.h:86
cTCPSerial::TIMEOUT_RETURN_IMMEDITELY_US
static const long TIMEOUT_RETURN_IMMEDITELY_US
Definition: tcpserial.h:115
cSerialBase::tErrorCode
int tErrorCode
type of the error code, DWORD on windows and int on Linux/cygwin
Definition: serialbase.h:233
cTCPSerial
Low-level communication class to access a CAN port.
Definition: tcpserial.h:88
cTCPSerial::TIMEOUT_WAIT_FOR_EVER_S
static const double TIMEOUT_WAIT_FOR_EVER_S
Definition: tcpserial.h:112
cSerialBase::SetTimeout
virtual void SetTimeout(double _timeout)
set the timeout for next readline() calls (negative value means: no timeout, wait for ever)
Definition: serialbase.h:151
cMsg
Class for short, fixed maximum length text messages.
Definition: sdhexception.h:77
cTCPSerial::tcp_adr
std::string tcp_adr
Definition: tcpserial.h:93
NAMESPACE_SDH_START
#define NAMESPACE_SDH_START
Definition: sdhlibrary_settings.h:79
cSerialBase::Open
virtual void Open(void)=0
Open rs232 port port.
cTCPSerial::TIMEOUT_WAIT_FOR_EVER_US
static const long TIMEOUT_WAIT_FOR_EVER_US
Definition: tcpserial.h:114
sdhexception.h
Interface of the exception base class #SDH::cSDHLibraryException and #SDH::cMsg.
basisdef.h
This file contains some basic definitions (defines, macros, datatypes)
cSerialBase::Read
virtual ssize_t Read(void *data, ssize_t size, long timeout_us, bool return_on_less_data)=0
cSerialBase::write
virtual int write(char const *ptr, int len=0)=0
Write data to a previously opened port.
sdhlibrary_settings.h
This file contains settings to make the SDHLibrary compile on differen systems:
cTCPSerial::timeout_us
long timeout_us
cached timeout in us for read()
Definition: tcpserial.h:109
cTCPSerial::GetErrorNumber
virtual tErrorCode GetErrorNumber()
Definition: tcpserial.h:167
cTCPSerialException::cTCPSerialException
cTCPSerialException(cMsg const &_msg)
Definition: tcpserial.h:78
cTCPSerialException
Derived exception class for low-level CAN ESD related exceptions.
Definition: tcpserial.h:75
cTCPSerial::TIMEOUT_RETURN_IMMEDITELY_S
static const double TIMEOUT_RETURN_IMMEDITELY_S
Definition: tcpserial.h:113


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