Commit a4db3837 authored by Pavel Vainerman's avatar Pavel Vainerman

ModbusTCP: Исправил ошибку предыдущего коммита

parent 5dbcb71b
...@@ -69,45 +69,49 @@ mbErrCode ModbusTCPServer::receive( ModbusRTU::ModbusAddr addr, timeout_t timeou ...@@ -69,45 +69,49 @@ mbErrCode ModbusTCPServer::receive( ModbusRTU::ModbusAddr addr, timeout_t timeou
} }
} }
// Если получили пакет по TCP if( !qrecv.empty() )
// то вроде задержек с остальной частью быть не должно
// а если пакет, не нам, то обработка пройдёт быстро..
// (поэтому ставим условный timeout)
// не != 0, т.к. в recv стоит assert(timeout)
timeout = 1;
do
{ {
// buf.addr = curQueryHeader.uID; // check addr
// res = recv_pdu(buf,mec); unsigned char _addr = qrecv.front();
res = recv( addr, buf, timeout ); if( _addr != addr )
if( res!=erNoError && res!=erBadReplyNodeAddress )
{ {
if( res < erInternalErrorCode ) tmProcessing.setTiming(replyTimeout_ms);
{ ErrorRetMessage em( buf.addr, buf.func, erBadReplyNodeAddress );
ErrorRetMessage em( buf.addr, buf.func, res ); buf = em.transport_msg();
buf = em.transport_msg(); send(buf);
send(buf); printProcessingTime();
printProcessingTime(); usleep(1000);
}
usleep(10000);
tcp.disconnect(); tcp.disconnect();
return res; return res;
} }
}
res = recv( addr, buf, timeout );
if( res!=erNoError ) // && res!=erBadReplyNodeAddress )
{
if( res < erInternalErrorCode )
{
ErrorRetMessage em( buf.addr, buf.func, res );
buf = em.transport_msg();
send(buf);
printProcessingTime();
}
usleep(1000);
tcp.disconnect();
return res;
}
if( timeout != UniSetTimer::WaitUpTime ) if( timeout != UniSetTimer::WaitUpTime )
{
timeout = ptTimeout.getLeft(timeout);
if( timeout == 0 )
{ {
timeout = ptTimeout.getLeft(timeout); tcp.disconnect();
if( timeout == 0 ) return erTimeOut;
{
tcp.disconnect();
return erTimeOut;
}
} }
} }
while( res == erBadReplyNodeAddress );
if( res!=erNoError ) if( res!=erNoError )
{ {
......
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