00001 // ===================================================================== 00024 // ===================================================================== 00025 #ifndef CLDAQ__TRS232CMODULE_HH 00026 #define CLDAQ__TRS232CMODULE_HH 00027 00028 #include "Tglobals.h" 00029 #include "TModule.hh" 00030 00031 class TDataElement; 00032 00033 00053 class TRs232cModule 00054 : public TModule 00055 { 00056 00057 protected: 00058 Tint theFileDescriptor; 00059 Tstring theDeviceFile; 00060 struct termio theSerialPort; 00061 00062 public: 00063 TRs232cModule( const Tstring devfile = "/dev/ttyS0", Tint nchannel = 1 ); 00064 TRs232cModule( Tint nchannel, Tstring devfile = "/dev/ttyS0" ); 00065 TRs232cModule( const TRs232cModule& right ); 00066 00067 protected: 00068 virtual ~TRs232cModule(); 00069 00070 public: 00071 virtual const TRs232cModule& operator=( const TRs232cModule& right ); 00072 virtual Tbool operator==( const TRs232cModule& right ) const; 00073 virtual Tbool operator!=( const TRs232cModule& right ) const; 00074 00075 public: 00076 virtual Tint Clear(); 00077 virtual Tint Update(); 00078 virtual Tint Initialize(); 00079 virtual Tvoid FillData( TDataElement& element, Tint channel ); 00080 00081 public: 00082 Tvoid DoClearMethod( Tint channel ); 00083 Tvoid DoUpdateMethod( Tint channel ); 00084 Tvoid DoInitializeMethod( Tint channel ); 00085 Tstring DoReadMethod( Tint channel ); 00086 00087 protected: 00088 virtual Tvoid defineClearMethod( Tint channel ) = 0; 00089 virtual Tvoid defineUpdateMethod( Tint channel ) = 0; 00090 virtual Tvoid defineInitializeMethod( Tint channel ) = 0; 00091 virtual Tvoid defineReadMethod( Tint channel ) = 0; 00092 virtual Tbool modifyData( const Tstring& accept, Tdouble& databuf ) const; 00093 00094 public: 00095 Tint Open(); 00096 Tstring Read(); 00097 Tint Write( const Tstring& token ); 00098 Tint Close(); 00099 00100 public: 00101 Tbool IsOpen() const; 00102 Tint GetFileDescriptor() const; 00103 const Tstring& GetDeviceFile() const; 00104 Tvoid SetFileDescriptor( Tint fd ); 00105 Tvoid SetDeviceFile( const Tstring& devfile ); 00106 const struct termio& GetSerialPort() const; 00107 struct termio& GetSerialPort(); 00108 Tvoid SetSerialPort( const struct termio& serial ); 00109 00110 }; 00111 00112 inline Tbool TRs232cModule::IsOpen() const 00113 { 00114 if ( theFileDescriptor != -1 ) { 00115 return Ttrue; 00116 } else { 00117 return Tfalse; 00118 } 00119 } 00120 00121 inline Tint TRs232cModule::GetFileDescriptor() const 00122 { 00123 return theFileDescriptor; 00124 } 00125 00126 inline const Tstring& TRs232cModule::GetDeviceFile() const 00127 { 00128 return theDeviceFile; 00129 } 00130 00131 inline Tvoid TRs232cModule::SetFileDescriptor( Tint fd ) 00132 { 00133 theFileDescriptor = fd; 00134 return; 00135 } 00136 00137 inline Tvoid TRs232cModule::SetDeviceFile( const Tstring& devfile ) 00138 { 00139 theDeviceFile = devfile; 00140 return; 00141 } 00142 00143 inline const struct termio& TRs232cModule::GetSerialPort() const 00144 { 00145 return theSerialPort; 00146 } 00147 00148 inline struct termio& TRs232cModule::GetSerialPort() 00149 { 00150 return theSerialPort; 00151 } 00152 00153 inline Tvoid TRs232cModule::SetSerialPort( const struct termio& serial ) 00154 { 00155 theSerialPort = serial; 00156 return; 00157 } 00158 00159 inline Tvoid TRs232cModule::DoClearMethod( Tint channel ) 00160 { 00161 defineClearMethod( channel ); 00162 return; 00163 } 00164 00165 inline Tvoid TRs232cModule::DoUpdateMethod( Tint channel ) 00166 { 00167 defineUpdateMethod( channel ); 00168 return; 00169 } 00170 00171 inline Tvoid TRs232cModule::DoInitializeMethod( Tint channel ) 00172 { 00173 defineInitializeMethod( channel ); 00174 return; 00175 } 00176 00177 inline Tstring TRs232cModule::DoReadMethod( Tint channel ) 00178 { 00179 defineReadMethod( channel ); 00180 return Read(); 00181 } 00182 00183 inline Tbool TRs232cModule::modifyData( const Tstring& accept, Tdouble& databuf ) const 00184 { 00185 return Tfalse; 00186 } 00187 00188 #endif