Commit 58c22b47 authored by Pavel Vaynerman's avatar Pavel Vaynerman

fixed minor bug in MBTCPMaster..

parent 37265acb
...@@ -191,6 +191,9 @@ int main( int argc, char **argv ) ...@@ -191,6 +191,9 @@ int main( int argc, char **argv )
mb.setTimeout(tout); mb.setTimeout(tout);
mb.connect(ia,port); mb.connect(ia,port);
if( verb )
cout << "connection: " << (mb.isConnection() ? "YES" : "NO") << endl;
while( 1) while( 1)
{ {
......
...@@ -47,15 +47,14 @@ int ModbusTCPMaster::nTransaction = 0; ...@@ -47,15 +47,14 @@ int ModbusTCPMaster::nTransaction = 0;
mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg, mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
ModbusMessage& reply, timeout_t timeout ) ModbusMessage& reply, timeout_t timeout )
{ {
// if( !isConnection() )
if( iaddr.empty() ) if( iaddr.empty() )
{ {
dlog[Debug::WARN] << "(query): unknown ip address for server..." << endl; dlog[Debug::WARN] << "(query): unknown ip address for server..." << endl;
return erHardwareError; return erHardwareError;
} }
reconnect(); if( !isConnection() )
reconnect();
if( !isConnection() ) if( !isConnection() )
{ {
...@@ -185,6 +184,8 @@ void ModbusTCPMaster::reconnect() ...@@ -185,6 +184,8 @@ void ModbusTCPMaster::reconnect()
delete tcp; delete tcp;
} }
if( dlog.debugging(Debug::INFO) )
dlog[Debug::INFO] << "(ModbusTCPMaster): reconnect " << iaddr << endl;
tcp = new ost::TCPStream(iaddr.c_str()); tcp = new ost::TCPStream(iaddr.c_str());
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment