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
HANDLE _hCOM
Definition: rs232-vcc.h:75
long read_timeout_us
Definition: rs232-vcc.h:81
virtual bool UseCRC16()
overloaded from cSerialBase::UseCRC16 since we want to use a CRC16 to protect binary RS232 communicat...
Definition: rs232-vcc.h:130
#define NULL
Definition: getopt1.c:56
virtual bool IsOpen(void)=0
Return true if communication channel is open.
bool IsOpen()
Return true if communication channel is open.
Definition: rs232-vcc.h:109
virtual void SetTimeout(double _timeout)
set the timeout for next readline() calls (negative value means: no timeout, wait for ever) ...
Definition: serialbase.h:151
Interface of the exception base class #SDH::cSDHLibraryException and #SDH::cMsg.
Low-level communication class to access a serial port.
Definition: serialbase.h:105
#define NAMESPACE_SDH_START
cRS232Exception(cMsg const &_msg)
Definition: rs232-vcc.h:63
COMMTIMEOUTS comm_timeouts
Definition: rs232-vcc.h:80
UInt16 size
Definition: dsa.h:269
virtual int write(char const *ptr, int len=0)=0
Write data to a previously opened port.
#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.
Interface of class #SDH::cSerialBase, a virtal base class to access serial communication channels lik...
Derived exception class for low-level serial communication related exceptions.
Definition: serialbase.h:86
Derived exception class for low-level RS232 related exceptions.
Definition: rs232-cygwin.h:71
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
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


sdhlibrary_cpp
Author(s): Dirk Osswald
autogenerated on Sun Aug 18 2019 03:42:20