00001 // ===================================================================== 00002 // $Id: TRs232cModule.hh,v 1.2 2003/07/30 16:19:11 goiwai Exp $ 00003 // $Name: CLDAQ-1-08-00 $ 00004 // 00005 // $Log: TRs232cModule.hh,v $ 00006 // Revision 1.2 2003/07/30 16:19:11 goiwai 00007 // ファイルにコミットログをつけることにしました. 00008 // 00009 // ===================================================================== 00010 #ifndef __TRS232CMODULE_HH 00011 #define __TRS232CMODULE_HH 00012 00013 #include "Tglobals.h" 00014 #include "TModule.hh" 00015 00016 class TDataElement; 00017 00018 class TRs232cModule 00019 : public TModule 00020 { 00021 00022 protected: 00023 Tint theFileDescriptor; 00024 Tstring theDeviceFile; 00025 struct termio theSerialPort; 00026 00027 public: 00028 TRs232cModule( const Tstring devfile = "/dev/ttyS0", Tint nchannel = 1 ); 00029 TRs232cModule( Tint nchannel, Tstring devfile = "/dev/ttyS0" ); 00030 TRs232cModule( const TRs232cModule& right ); 00031 00032 protected: 00033 virtual ~TRs232cModule(); 00034 00035 public: 00036 virtual const TRs232cModule& operator=( const TRs232cModule& right ); 00037 virtual Tbool operator==( const TRs232cModule& right ) const; 00038 virtual Tbool operator!=( const TRs232cModule& right ) const; 00039 00040 public: 00041 virtual Tint Clear(); 00042 virtual Tint Update(); 00043 virtual Tint Initialize(); 00044 virtual Tvoid FillData( TDataElement& element, Tint channel ); 00045 00046 public: 00047 Tvoid DoClearMethod( Tint channel ); 00048 Tvoid DoUpdateMethod( Tint channel ); 00049 Tvoid DoInitializeMethod( Tint channel ); 00050 Tstring DoReadMethod( Tint channel ); 00051 00052 protected: 00053 virtual Tvoid defineClearMethod( Tint channel ) = 0; 00054 virtual Tvoid defineUpdateMethod( Tint channel ) = 0; 00055 virtual Tvoid defineInitializeMethod( Tint channel ) = 0; 00056 virtual Tvoid defineReadMethod( Tint channel ) = 0; 00057 virtual Tbool modifyData( const Tstring& accept, Tdouble& databuf ) const; 00058 00059 public: 00060 Tint Open(); 00061 Tstring Read(); 00062 Tint Write( const Tstring& token ); 00063 Tint Close(); 00064 00065 public: 00066 Tbool IsOpen() const; 00067 Tint GetFileDescriptor() const; 00068 const Tstring& GetDeviceFile() const; 00069 Tvoid SetFileDescriptor( Tint fd ); 00070 Tvoid SetDeviceFile( const Tstring& devfile ); 00071 const struct termio& GetSerialPort() const; 00072 struct termio& GetSerialPort(); 00073 Tvoid SetSerialPort( const struct termio& serial ); 00074 00075 }; 00076 00077 inline Tbool TRs232cModule::IsOpen() const 00078 { 00079 if ( theFileDescriptor != -1 ) { 00080 return( Ttrue ); 00081 } else { 00082 return( Tfalse ); 00083 } 00084 } 00085 00086 inline Tint TRs232cModule::GetFileDescriptor() const 00087 { 00088 return( theFileDescriptor ); 00089 } 00090 00091 inline const Tstring& TRs232cModule::GetDeviceFile() const 00092 { 00093 return( theDeviceFile ); 00094 } 00095 00096 inline Tvoid TRs232cModule::SetFileDescriptor( Tint fd ) 00097 { 00098 theFileDescriptor = fd; 00099 return; 00100 } 00101 00102 inline Tvoid TRs232cModule::SetDeviceFile( const Tstring& devfile ) 00103 { 00104 theDeviceFile = devfile; 00105 return; 00106 } 00107 00108 inline const struct termio& TRs232cModule::GetSerialPort() const 00109 { 00110 return( theSerialPort ); 00111 } 00112 00113 inline struct termio& TRs232cModule::GetSerialPort() 00114 { 00115 return( theSerialPort ); 00116 } 00117 00118 inline Tvoid TRs232cModule::SetSerialPort( const struct termio& serial ) 00119 { 00120 theSerialPort = serial; 00121 return; 00122 } 00123 00124 inline Tvoid TRs232cModule::DoClearMethod( Tint channel ) 00125 { 00126 defineClearMethod( channel ); 00127 return; 00128 } 00129 00130 inline Tvoid TRs232cModule::DoUpdateMethod( Tint channel ) 00131 { 00132 defineUpdateMethod( channel ); 00133 return; 00134 } 00135 00136 inline Tvoid TRs232cModule::DoInitializeMethod( Tint channel ) 00137 { 00138 defineInitializeMethod( channel ); 00139 return; 00140 } 00141 00142 inline Tstring TRs232cModule::DoReadMethod( Tint channel ) 00143 { 00144 defineReadMethod( channel ); 00145 return( Read() ); 00146 } 00147 00148 inline Tbool TRs232cModule::modifyData( const Tstring& accept, Tdouble& databuf ) const 00149 { 00150 return( Tfalse ); 00151 } 00152 00153 #endif