rs232-vcc.h
Go to the documentation of this file.
1 //======================================================================
27 //======================================================================
28 
29 #ifndef RS232_VCC_h
30 #define RS232_VCC_h
31 
32 #include "sdhlibrary_settings.h"
33 
34 #if SDH_USE_VCC
35 # pragma warning(disable : 4996)
36 # pragma warning(disable : 4290)
37 # pragma once
38 #endif
39 
40 //----------------------------------------------------------------------
41 // System Includes - include with <>
42 //----------------------------------------------------------------------
43 
44 #include <windows.h>
45 
46 //----------------------------------------------------------------------
47 // Project Includes - include with ""
48 //----------------------------------------------------------------------
49 
50 #include "sdhexception.h"
51 #include "serialbase.h"
52 #include "sdhlibrary_settings.h"
53 
54 
55 //#define RS_232_TEST
56 #define SDH_RS232_VCC_ASYNC 0
57 
59 
60 class VCC_EXPORT cRS232Exception: public cSerialBaseException
61 {
62 public:
63  cRS232Exception( cMsg const & _msg )
64  : cSerialBaseException( "cRS232Exception", _msg )
65  {}
66 };
67 
71 class VCC_EXPORT cRS232 : public cSerialBase
72 {
73 private:
74 #ifndef RS_232_TEST
75  HANDLE _hCOM;
76 #endif
77 #if SDH_RS232_VCC_ASYNC
78  OVERLAPPED o;
79 #endif
80  COMMTIMEOUTS comm_timeouts;
81  long read_timeout_us; // for caching the read timeout in ms
82 
83 protected:
85  int port;
86 
88  unsigned long baudrate;
89 
90 
91 public:
100  cRS232( int _port, unsigned long _baudrate, double _timeout, char const* _device_format_string = "" );
101  ~cRS232(void);
102 
103  void Open( void );
104  void Close( void );
105 
106  virtual void SetTimeout( double _timeout );
107 
108 #ifndef RS_232_TEST
109  bool IsOpen()
110  throw()
111  { return _hCOM != NULL; }
112 #else
113  bool IsOpen() { return true; }
114 #endif
115  int write( char const *ptr, int len=0 );
116 
125  ssize_t Read( void *data, ssize_t size, long timeout_us, bool return_on_less_data );
126 
127  char* readline(char* line, int size, char* eol, bool return_on_less_data);
128 
130  virtual bool UseCRC16()
131  {
132  return true;
133  }
134 };
135 
137 
138 #endif
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
cRS232::IsOpen
bool IsOpen()
Return true if communication channel is open.
Definition: rs232-vcc.h:109
cRS232::read_timeout_us
long read_timeout_us
Definition: rs232-vcc.h:81
cSerialBase::IsOpen
virtual bool IsOpen(void)=0
Return true if communication channel is open.
NULL
#define NULL
Definition: getopt1.c:56
cSerialBaseException
Derived exception class for low-level serial communication related exceptions.
Definition: serialbase.h:86
cRS232
Low-level communication class to access a serial port on Cygwin and Linux.
Definition: rs232-cygwin.h:84
cRS232::_hCOM
HANDLE _hCOM
Definition: rs232-vcc.h:75
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
NAMESPACE_SDH_START
#define NAMESPACE_SDH_START
Definition: sdhlibrary_settings.h:79
cSerialBase::Open
virtual void Open(void)=0
Open rs232 port port.
cRS232Exception::cRS232Exception
cRS232Exception(cMsg const &_msg)
Definition: rs232-vcc.h:63
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
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:
cRS232::comm_timeouts
COMMTIMEOUTS comm_timeouts
Definition: rs232-vcc.h:80
cSerialBase::readline
virtual char * readline(char *line, int size, char const *eol="\n", bool return_on_less_data=false)
Read a line from the device.
Definition: serialbase.cpp:76
cRS232::UseCRC16
virtual bool UseCRC16()
overloaded from cSerialBase::UseCRC16 since we want to use a CRC16 to protect binary RS232 communicat...
Definition: rs232-vcc.h:130


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