|
UniSet
2.2.1
|
00001 #ifndef UModbus_H_ 00002 #define UModbus_H_ 00003 // -------------------------------------------------------------------------- 00004 #include "Configuration.h" 00005 #include "UInterface.h" 00006 #include "modbus/ModbusTCPMaster.h" 00007 #include "modbus/ModbusTypes.h" 00008 #include "extensions/VTypes.h" 00009 #include "Debug.h" 00010 #include "UTypes.h" 00011 #include "UExceptions.h" 00012 // -------------------------------------------------------------------------- 00013 class UModbus 00014 { 00015 public: 00016 00017 UModbus(); 00018 ~UModbus(); 00019 00020 inline std::string getUIType() 00021 { 00022 return string("modbus"); 00023 } 00024 00025 inline bool isWriteFunction( int mbfunc ) 00026 { 00027 return ModbusRTU::isWriteFunction((ModbusRTU::SlaveFunctionCode)mbfunc); 00028 } 00029 00030 // выставление паметров связи, без установления соединения (!) 00031 void prepare( const std::string& ip, int port )throw(UException); 00032 00033 void connect( const std::string& ip, int port )throw(UException); 00034 inline int conn_port() 00035 { 00036 return port; 00037 } 00038 inline std::string conn_ip() 00039 { 00040 return ip; 00041 } 00042 inline bool isConnection() 00043 { 00044 return (mb && mb->isConnection()); 00045 } 00046 00047 inline void setTimeout( int msec ) 00048 { 00049 tout_msec = msec; 00050 } 00051 00057 long mbread( int addr, int mbreg, int mbfunc, 00058 const std::string& vtype, int nbit = -1, 00059 const std::string& ip = "", int port = -1 )throw(UException); 00060 00061 long getWord( int addr, int mbreg, int mbfunc = 0x4 )throw(UException); 00062 long getByte( int addr, int mbreg, int mbfunc = 0x4 )throw(UException); 00063 bool getBit( int addr, int mbreg, int mbfunc = 0x2 )throw(UException); 00064 00070 void mbwrite( int addr, int mbreg, int val, int mbfunc, const std::string& ip = "", int port = -1 )throw(UException); 00071 00072 protected: 00073 long data2value( VTypes::VType vt, ModbusRTU::ModbusData* data ); 00074 00075 private: 00076 // DebugStream dlog; 00077 ModbusTCPMaster* mb; 00078 int port; 00079 string ip; 00080 int tout_msec; 00081 }; 00082 //--------------------------------------------------------------------------- 00083 #endif 00084 //---------------------------------------------------------------------------
1.7.6.1