Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00044
00045
00046 #ifndef RS232_VCC_h
00047 #define RS232_VCC_h
00048
00049 #include "sdhlibrary_settings.h"
00050
00051 #if SDH_USE_VCC
00052 # pragma warning(disable : 4996)
00053 # pragma warning(disable : 4290)
00054 # pragma once
00055 #endif
00056
00057
00058
00059
00060
00061 #include <windows.h>
00062
00063
00064
00065
00066
00067 #include "sdhexception.h"
00068 #include "serialbase.h"
00069 #include "sdhlibrary_settings.h"
00070
00071
00072
00073 #define SDH_RS232_VCC_ASYNC 0
00074
00075 NAMESPACE_SDH_START
00076
00077 class VCC_EXPORT cRS232Exception: public cSerialBaseException
00078 {
00079 public:
00080 cRS232Exception(cMsg const & _msg)
00081 : cSerialBaseException("cRS232Exception", _msg)
00082 {}
00083 };
00084
00088 class VCC_EXPORT cRS232 : public cSerialBase
00089 {
00090 private:
00091 #ifndef RS_232_TEST
00092 HANDLE _hCOM;
00093 #endif
00094 #if SDH_RS232_VCC_ASYNC
00095 OVERLAPPED o;
00096 #endif
00097 COMMTIMEOUTS comm_timeouts;
00098 long read_timeout_us;
00099
00100 protected:
00102 int port;
00103
00105 unsigned long baudrate;
00106
00107
00108 public:
00117 cRS232(int _port, unsigned long _baudrate, double _timeout, char const* _device_format_string = "");
00118 ~cRS232(void);
00119
00120 void Open(void)
00121 throw (cRS232Exception*);
00122 void Close(void)
00123 throw (cRS232Exception*);
00124
00125 virtual void SetTimeout(double _timeout)
00126 throw (cSerialBaseException*);
00127
00128 #ifndef RS_232_TEST
00129 bool IsOpen()
00130 throw()
00131 {
00132 return _hCOM != NULL;
00133 }
00134 #else
00135 bool IsOpen()
00136 {
00137 return true;
00138 }
00139 #endif
00140 int write(char const *ptr, int len = 0)
00141 throw (cRS232Exception*);
00142
00151 ssize_t Read(void *data, ssize_t size, long timeout_us, bool return_on_less_data)
00152 throw (cRS232Exception*);
00153
00154 char* readline(char* line, int size, char* eol, bool return_on_less_data)
00155 throw (cRS232Exception*);
00156
00158 virtual bool UseCRC16()
00159 {
00160 return true;
00161 }
00162 };
00163
00164 NAMESPACE_SDH_END
00165
00166 #endif