You need to sign in or sign up before continuing.
Commit b605e8f7 authored by Pavel Vainerman's avatar Pavel Vainerman

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

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