00001
00027
00028
00029 #ifndef RS232_VCC_h
00030 #define RS232_VCC_h
00031
00032 #include "sdhlibrary_settings.h"
00033
00034 #if SDH_USE_VCC
00035 # pragma warning(disable : 4996)
00036 # pragma warning(disable : 4290)
00037 # pragma once
00038 #endif
00039
00040
00041
00042
00043
00044 #include <windows.h>
00045
00046
00047
00048
00049
00050 #include "sdhexception.h"
00051 #include "serialbase.h"
00052 #include "sdhlibrary_settings.h"
00053
00054
00055
00056 #define SDH_RS232_VCC_ASYNC 0
00057
00058 NAMESPACE_SDH_START
00059
00060
00061 class cRS232Exception: public cSerialBaseException
00062 {
00063 public:
00064 cRS232Exception( cMsg const & _msg )
00065 : cSerialBaseException( "cRS232Exception", _msg )
00066 {}
00067 };
00068
00072 class cRS232 : public cSerialBase
00073 {
00074 private:
00075 #ifndef RS_232_TEST
00076 HANDLE _hCOM;
00077 #endif
00078 #if SDH_RS232_VCC_ASYNC
00079 OVERLAPPED o;
00080 #endif
00081 COMMTIMEOUTS comm_timeouts;
00082 long read_timeout_us;
00083
00084 protected:
00086 int port;
00087
00089 unsigned long baudrate;
00090
00091
00092 public:
00101 cRS232( int _port, unsigned long _baudrate, double _timeout, char const* _device_format_string = "" );
00102 ~cRS232(void);
00103
00104 void Open( void )
00105 throw (cRS232Exception*);
00106 void Close( void )
00107 throw (cRS232Exception*);
00108
00109 virtual void SetTimeout( double _timeout )
00110 throw (cSerialBaseException*);
00111
00112 #ifndef RS_232_TEST
00113 bool IsOpen()
00114 throw()
00115 { return _hCOM != NULL; }
00116 #else
00117 bool IsOpen() { return true; }
00118 #endif
00119 int write( char const *ptr, int len=0 )
00120 throw (cRS232Exception*);
00121
00130 ssize_t Read( void *data, ssize_t size, long timeout_us, bool return_on_less_data )
00131 throw (cRS232Exception*);
00132
00133 char* readline(char* line, int size, char* eol, bool return_on_less_data)
00134 throw (cRS232Exception*);
00135 };
00136
00137 NAMESPACE_SDH_END
00138
00139 #endif