Commit 70841899 authored by Pavel Vainerman's avatar Pavel Vainerman Committed by Pavel Vainerman

(Modbus) перевёл на использование UTCPStream (для исключения

блокирования соединения)
parent 79f27de3
......@@ -8,12 +8,12 @@
--mbtcp-set-prop-prefix \
--mbtcp-filter-field rs \
--mbtcp-filter-value 5 \
--mbtcp-gateway-iaddr 127.0.0.1 \
--mbtcp-gateway-iaddr server \
--mbtcp-gateway-port 2048 \
--mbtcp-recv-timeout 3000 \
--mbtcp-timeout 2000 \
--mbtcp-force-disconnect 1 \
--mbtcp-polltime 100 \
--mbtcp-polltime 1000 \
--mbtcp-force-out 1 \
$*
......
../../Utilities/scripts/uniset2-functions.sh
\ No newline at end of file
../../Utilities/scripts/uniset2-functions.sh
\ No newline at end of file
......@@ -6,6 +6,7 @@
#include <cc++/socket.h>
#include "ModbusTypes.h"
#include "ModbusClient.h"
#include "UTCPStream.h"
// -------------------------------------------------------------------------
/*! Modbus TCP master interface */
class ModbusTCPMaster:
......@@ -42,11 +43,13 @@ class ModbusTCPMaster:
ModbusRTU::ModbusMessage& reply, timeout_t timeout ) override;
private:
ost::TCPStream* tcp;
//ost::TCPStream* tcp;
UTCPStream* tcp;
ModbusRTU::ModbusData nTransaction;
std::queue<unsigned char> qrecv;
PassiveTimer ptTimeout;
std::string iaddr;
int port;
bool force_disconnect;
};
// -------------------------------------------------------------------------
......
......@@ -280,10 +280,8 @@ bool ModbusTCPMaster::checkConnection( const std::string& ip, int port, int time
s << ip << ":" << port;
// Проверяем просто попыткой создать соединение..
// ost::Thread::setException(ost::Thread::throwException);
// TCPStream (const char *name, Family family=IPV4, unsigned mss=536, bool throwflag=false, timeout_t timer=0)
ost::TCPStream t(s.str().c_str(),ost::Socket::IPV4,536,true,timeout_msec);
UTCPStream t;
t.create(ip,port,true,timeout_msec);
t.disconnect();
return true;
}
......@@ -301,18 +299,16 @@ void ModbusTCPMaster::reconnect()
if( tcp )
{
// cerr << "tcp diconnect..." << endl;
tcp->disconnect();
delete tcp;
tcp = 0;
}
// ost::Thread::setException(ost::Thread::throwException);
try
{
// TCPStream (const char *name, Family family=IPV4, unsigned mss=536, bool throwflag=false, timeout_t timer=0)
tcp = new ost::TCPStream(iaddr.c_str(),ost::Socket::IPV4,536,true,500);
tcp = new UTCPStream();
tcp->create(iaddr,port,true,500);
tcp->setTimeout(replyTimeOut_ms);
}
catch( std::exception& e )
......@@ -335,13 +331,13 @@ void ModbusTCPMaster::reconnect()
}
}
// -------------------------------------------------------------------------
void ModbusTCPMaster::connect( const std::string& addr, int port )
void ModbusTCPMaster::connect( const std::string& addr, int _port )
{
ost::InetAddress ia(addr.c_str());
connect(ia,port);
connect(ia,_port);
}
// -------------------------------------------------------------------------
void ModbusTCPMaster::connect( ost::InetAddress addr, int port )
void ModbusTCPMaster::connect( ost::InetAddress addr, int _port )
{
if( tcp )
{
......@@ -352,18 +348,21 @@ void ModbusTCPMaster::connect( ost::InetAddress addr, int port )
// if( !tcp )
// {
ostringstream s;
s << addr << ":" << port;
s << addr;
iaddr = s.str();
port = _port;
if( dlog.is_info() )
dlog.info() << "(ModbusTCPMaster): connect to " << s.str() << endl;
iaddr = s.str();
dlog.info() << "(ModbusTCPMaster): connect to " << iaddr << ":" << port << endl;
ost::Thread::setException(ost::Thread::throwException);
try
{
tcp = new ost::TCPStream(iaddr.c_str(),ost::Socket::IPV4,536,true,500);
ostringstream aa;
tcp = new UTCPStream();
tcp->create(iaddr,port,true,500);
tcp->setTimeout(replyTimeOut_ms);
}
catch( std::exception& e )
......
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