Commit ef7fdabc authored by Pavel Vainerman's avatar Pavel Vainerman

fixed bug in MBTCPMaster

parent 641998d3
......@@ -3,7 +3,7 @@
Name: libuniset
Version: 0.97
Release: eter48
Release: eter50
Summary: UniSet - library for building distributed industrial control systems
License: GPL
Group: Development/C++
......@@ -182,6 +182,9 @@ rm -f %buildroot%_libdir/*.la
%exclude %_pkgconfigdir/libUniSet.pc
%changelog
* Tue Jan 26 2010 Pavel Vainerman <pv@altlinux.ru> 0.97-eter49
- fixed bug in ModbusTCPMaster
* Mon Dec 28 2009 Alexander Morozov <amorozov@etersoft.ru> 0.97-eter48
- added new filters
- fixed some bugs
......
......@@ -833,7 +833,7 @@ ModbusRTU::mbErrCode MBSlave::readOutputRegisters( ModbusRTU::ReadOutputMessage&
if( reply.count < query.count )
{
dlog[Debug::WARN] << myname
<< "(readInputRegisters): query.count=" << query.count
<< "(readInputRegisters): query.count=" << (int)query.count
<< " > reply.count=" << reply.count << endl;
}
......@@ -1143,8 +1143,8 @@ mbErrCode MBSlave::readInputRegisters( ReadInputMessage& query,
if( reply.count < query.count )
{
dlog[Debug::WARN] << myname
<< "(readInputRegisters): query.count=" << query.count
<< " > reply.count=" << reply.count << endl;
<< "(readInputRegisters): query.count=" << (int)query.count
<< " > reply.count=" << (int)reply.count << endl;
}
pingOK = true;
......
......@@ -160,10 +160,13 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
if( ret < (int)sizeof(rmh) )
{
if( dlog.debugging(Debug::INFO) )
dlog[Debug::INFO] << "(ModbusTCPMaster::query): ret=" << (int)ret
<< " < rmh=" << (int)sizeof(rmh) << endl;
disconnect();
return erTimeOut; // return erHardwareError;
}
rmh.swapdata();
if( rmh.tID != mh.tID )
......@@ -176,11 +179,20 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
cleanInputStream();
return erBadReplyNodeAddress;
}
//
return recv(addr,msg.func,reply,timeout);
// msg.addr = rmh.uID;
// return recv_pdu(msg.func,reply,timeout);
// return recv(addr,msg.func,reply,timeout);
mbErrCode res = recv(addr,msg.func,reply,timeout);
if( force_disconnect )
{
if( dlog.debugging(Debug::INFO) )
dlog[Debug::INFO] << "(query): force disconnect.." << endl;
disconnect();
}
return res;
}
if( dlog.debugging(Debug::INFO) )
......
......@@ -88,6 +88,7 @@ mbErrCode ModbusTCPServer::receive( ModbusRTU::ModbusAddr addr, timeout_t timeou
}
usleep(10000);
tcp.disconnect();
return res;
}
......@@ -104,7 +105,10 @@ mbErrCode ModbusTCPServer::receive( ModbusRTU::ModbusAddr addr, timeout_t timeou
while( res == erBadReplyNodeAddress );
if( res!=erNoError )
{
tcp.disconnect();
return res;
}
// processing message...
res = processing(buf);
......@@ -169,7 +173,13 @@ mbErrCode ModbusTCPServer::tcp_processing( ost::TCPStream& tcp, ModbusTCP::MBAPH
len = ModbusTCPCore::readNextData(&tcp,qrecv,mhead.len);
if( len<mhead.len )
{
if( dlog.debugging(Debug::INFO) )
dlog[Debug::INFO] << "(ModbusTCPServer::tcp_processing): len(" << (int)len
<< ") < mhead.len(" << (int)mhead.len << ")" << endl;
return erInvalidFormat;
}
return erNoError;
}
......
......@@ -653,7 +653,8 @@ std::ostream& ModbusRTU::operator<<(std::ostream& os, ReadInputStatusMessage& m
// return mbPrintMessage(os,(ModbusByte*)(&m),sizeof(m));
return os << "addr=" << addr2str(m.addr)
<< " start=" << dat2str(m.start)
<< " count=" << dat2str(m.count);
<< " count=" << dat2str(m.count)
<< "(" << (int)m.count << ")";
}
std::ostream& ModbusRTU::operator<<(std::ostream& os, ReadInputStatusMessage* m )
{
......@@ -854,7 +855,9 @@ std::ostream& ModbusRTU::operator<<(std::ostream& os, ReadOutputMessage& m )
// return mbPrintMessage(os,(ModbusByte*)(&m),sizeof(m));
return os << "addr=" << addr2str(m.addr)
<< " start=" << dat2str(m.start)
<< " count=" << dat2str(m.count);
<< " count=" << dat2str(m.count)
<< "(" << (int)m.count << ")";
}
std::ostream& ModbusRTU::operator<<(std::ostream& os, ReadOutputMessage* m )
{
......@@ -1070,7 +1073,8 @@ std::ostream& ModbusRTU::operator<<(std::ostream& os, ReadInputMessage& m )
// return mbPrintMessage(os,(ModbusByte*)(&m),sizeof(m));
return os << "addr=" << addr2str(m.addr)
<< " start=" << dat2str(m.start)
<< " count=" << dat2str(m.count);
<< " count=" << dat2str(m.count)
<< "(" << (int)m.count << ")";
}
std::ostream& ModbusRTU::operator<<(std::ostream& os, ReadInputMessage* m )
{
......
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