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 //======================================================================
std::string tcp_adr
Definition: tcpserial.h:93
static long const TIMEOUT_RETURN_IMMEDITELY_US
Definition: tcpserial.h:115
virtual bool IsOpen(void)=0
Return true if communication channel is open.
long timeout_us
cached timeout in us for read()
Definition: tcpserial.h:109
static double const TIMEOUT_WAIT_FOR_EVER_S
Definition: tcpserial.h:112
virtual void SetTimeout(double _timeout)
set the timeout for next readline() calls (negative value means: no timeout, wait for ever) ...
Definition: serialbase.h:151
int tErrorCode
type of the error code, DWORD on windows and int on Linux/cygwin
Definition: serialbase.h:233
Interface of the exception base class #SDH::cSDHLibraryException and #SDH::cMsg.
virtual tErrorCode GetErrorNumber()
Definition: tcpserial.h:167
static long const TIMEOUT_WAIT_FOR_EVER_US
Definition: tcpserial.h:114
Derived exception class for low-level CAN ESD related exceptions.
Definition: tcpserial.h:75
Low-level communication class to access a serial port.
Definition: serialbase.h:105
#define NAMESPACE_SDH_START
int tcp_port
the TCP port to use
Definition: tcpserial.h:96
Low-level communication class to access a CAN port.
Definition: tcpserial.h:88
UInt16 size
Definition: dsa.h:269
virtual int write(char const *ptr, int len=0)=0
Write data to a previously opened port.
int fd
the file descriptor of the socket
Definition: tcpserial.h:102
#define NAMESPACE_SDH_END
This file contains settings to make the SDHLibrary compile on differen systems:
virtual void Open(void)=0
Open rs232 port port.
This file contains some basic definitions (defines, macros, datatypes)
Interface of class #SDH::cSerialBase, a virtal base class to access serial communication channels lik...
static double const TIMEOUT_RETURN_IMMEDITELY_S
Definition: tcpserial.h:113
Derived exception class for low-level serial communication related exceptions.
Definition: serialbase.h:86
virtual void Close(void)=0
Close the previously opened communication channel.
Class for short, fixed maximum length text messages.
Definition: sdhexception.h:77
virtual ssize_t Read(void *data, ssize_t size, long timeout_us, bool return_on_less_data)=0
cTCPSerialException(cMsg const &_msg)
Definition: tcpserial.h:78


sdhlibrary_cpp
Author(s): Dirk Osswald
autogenerated on Mon Feb 28 2022 23:41:51