Commit 37265acb authored by Pavel Vaynerman's avatar Pavel Vaynerman

check connection before send

parent 23b4833c
......@@ -51,13 +51,18 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
// if( !isConnection() )
if( iaddr.empty() )
{
dlog[Debug::WARN] << "(query): not connection to server..." << endl;
dlog[Debug::WARN] << "(query): unknown ip address for server..." << endl;
return erHardwareError;
}
reconnect();
if( !isConnection() )
{
dlog[Debug::WARN] << "(query): not connected to server..." << endl;
return erTimeOut;
}
assert(timeout);
ptTimeout.setTiming(timeout);
......@@ -112,6 +117,15 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
if( tcp->isPending(ost::Socket::pendingInput,timeout) )
{
/*
unsigned char rbuf[100];
memset(rbuf,0,sizeof(rbuf));
int ret = getNextData(rbuf,sizeof(rbuf));
cerr << "ret=" << ret << " recv: ";
for( int i=0; i<sizeof(rbuf); i++ )
cerr << hex << " 0x" << (int)rbuf[i];
cerr << endl;
*/
ModbusTCP::MBAPHeader rmh;
int ret = getNextData((unsigned char*)(&rmh),sizeof(rmh));
if( dlog.debugging(Debug::INFO) )
......
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