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