UniSet  2.0.0
UModbus.h
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 //      UModbus( int argc, char** argv )throw(UException);
00017 //      UModbus( UTypes::Params* p )throw(UException);
00018       UModbus();
00019       ~UModbus();
00020 
00021       inline const char* getUIType(){ return "modbus"; } 
00022 
00023       inline bool isWriteFunction( int mbfunc ){ return ModbusRTU::isWriteFunction((ModbusRTU::SlaveFunctionCode)mbfunc); }
00024 
00025       // выставление паметров связи, без установления соединения (!)
00026       void prepare( const char* ip, int port )throw(UException);
00027       
00028       void connect( const char* ip, int port )throw(UException);
00029       inline int conn_port(){ return port; }
00030       inline std::string conn_ip(){ return ip; }
00031       inline bool isConnection(){ return (mb && mb->isConnection()); }
00032 
00033       inline void setTimeout( int msec ){ tout_msec = msec; }
00034 
00040       long mbread( int addr, int mbreg, int mbfunc,
00041                     const char* vtype, int nbit=-1,
00042                     const char* ip=0, int port=-1 )throw(UException);
00043 
00044       long getWord( int addr, int mbreg, int mbfunc=0x4 )throw(UException);
00045       long getByte( int addr, int mbreg, int mbfunc=0x4 )throw(UException);
00046       bool getBit( int addr, int mbreg, int mbfunc=0x2 )throw(UException);
00047 
00053       void mbwrite( int addr, int mbreg, int val, int mbfunc, const char* ip=0, int port=-1 )throw(UException);
00054 
00055     protected:
00056         long data2value( VTypes::VType vt, ModbusRTU::ModbusData* data );
00057     
00058     private:
00059         // DebugStream dlog;
00060         ModbusTCPMaster* mb;
00061         int port;
00062         string ip;
00063         int tout_msec;
00064 };
00065 //---------------------------------------------------------------------------
00066 #endif
00067 //---------------------------------------------------------------------------