Commit b91eda75 authored by Pavel Vainerman's avatar Pavel Vainerman

Merge remote-tracking branch 'eter/master'

Conflicts: Utilities/codegen/ctl-cpp-cc-alone-ask.xsl Utilities/codegen/ctl-cpp-cc-alone.xsl Utilities/codegen/ctl-cpp-cc-ask.xsl
parents 02444c9f 3e5a3923
......@@ -194,6 +194,9 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::setValue( UniSetTypes::ObjectId _si
</xsl:if>
</xsl:if>
</xsl:for-each>
ui.setValue(_sid, _val);
}
// -----------------------------------------------------------------------------
void <xsl:value-of select="$CLASSNAME"/>_SK::askState( UniSetTypes::ObjectId _sid, UniversalIO::UIOCommand _cmd, UniSetTypes::ObjectId _node )
......
......@@ -173,6 +173,8 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::setValue( UniSetTypes::ObjectId _si
</xsl:if>
</xsl:if>
</xsl:for-each>
ui.setValue( _sid, _val );
}
// -----------------------------------------------------------------------------
......@@ -192,11 +194,6 @@ long <xsl:value-of select="$CLASSNAME"/>_SK::getValue( UniSetTypes::ObjectId _si
</xsl:if>
</xsl:for-each>
// unideb[Debug::CRIT] &lt;&lt; myname &lt;&lt; "(getState): Обращение к неизвестному ДИСКРЕТНОМУ датчику sid="
// &lt;&lt; _sid &lt;&lt; endl;
//
// return 0;
return ui.getValue(_sid);
}
// -----------------------------------------------------------------------------
......
......@@ -120,6 +120,8 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::setValue( UniSetTypes::ObjectId _si
}
</xsl:if>
</xsl:for-each>
ui.setValue( _sid, _val );
}
// -----------------------------------------------------------------------------
void <xsl:value-of select="$CLASSNAME"/>_SK::updateOutputs( bool _force )
......@@ -218,8 +220,6 @@ long <xsl:value-of select="$CLASSNAME"/>_SK::getValue( UniSetTypes::ObjectId _si
unideb[Debug::CRIT] &lt;&lt; myname &lt;&lt; "(getState): " &lt;&lt; ex &lt;&lt; endl;
throw;
}
return 0;
}
// -----------------------------------------------------------------------------
......
......@@ -124,6 +124,8 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::setValue( UniSetTypes::ObjectId sid
}
</xsl:if>
</xsl:for-each>
ui.setValue( sid, val );
}
// -----------------------------------------------------------------------------
void <xsl:value-of select="$CLASSNAME"/>_SK::updateOutputs( bool force )
......
......@@ -8,7 +8,7 @@
Name: libuniset
Version: 1.7
Release: alt4
Release: alt10
Summary: UniSet - library for building distributed industrial control systems
......@@ -335,6 +335,25 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
%exclude %_pkgconfigdir/libUniSet.pc
%changelog
* Tue Apr 01 2014 Pavel Vainerman <pv@altlinux.ru> 1.7-alt10
- add new vtype: F2r, I2r, U2r (reverse data order)
* Wed Mar 19 2014 Pavel Vainerman <pv@altlinux.ru> 1.7-alt9
- add thresholds processing for ModbusMaster (TCP and RTU)
- minor fixes
* Fri Mar 07 2014 Pavel Vainerman <pv@altlinux.ru> 1.7-alt8
- fixed bug in ComPort class (getTimeout. eterbug #9890)
* Wed Feb 12 2014 Pavel Vainerman <pv@altlinux.ru> 1.7-alt7
- revert last changes ("ModbusMaster: add thread for check connection")
* Wed Feb 12 2014 Pavel Vainerman <pv@altlinux.ru> 1.7-alt6
- ModbusMaster: add thread for check connection
* Mon Feb 10 2014 Pavel Vainerman <pv@altlinux.ru> 1.7-alt5
- ModbusMaster: minor fixes
* Thu Feb 06 2014 Pavel Vainerman <pv@altlinux.ru> 1.7-alt4
- ModbusExchange: fixed bug: deadlock for pollMutex..
......
......@@ -25,6 +25,7 @@
#include <sys/time.h>
#include <sstream>
#include <iomanip>
#include <cmath>
#include "ORepHelpers.h"
#include "DBServer_MySQL.h"
......@@ -281,7 +282,9 @@ void DBServer_MySQL::parse( UniSetTypes::SensorMessage *si )
struct timezone tz;
gettimeofday(&si->tm,&tz);
}
float val = (float)si->value / (float)pow10(si->ci.precision);
// см. DBTABLE AnalogSensors, DigitalSensors
ostringstream data;
data << "INSERT INTO " << tblName(si->type)
......@@ -289,10 +292,10 @@ void DBServer_MySQL::parse( UniSetTypes::SensorMessage *si )
// Поля таблицы
<< ui.dateToString(si->sm_tv_sec,"-") << "','" // date
<< ui.timeToString(si->sm_tv_sec,":") << "','" // time
<< si->sm_tv_usec << "'," // time_usec
<< si->id << "," // sensor_id
<< si->value << "," // value
<< si->node << ")"; // node
<< si->sm_tv_usec << "','" // time_usec
<< si->id << "','" // sensor_id
<< val << "','" // value
<< si->node << "')"; // node
if( unideb.debugging(DBLEVEL) )
unideb[DBLEVEL] << myname << "(insert_main_history): " << data.str() << endl;
......
......@@ -25,6 +25,7 @@
#include <sys/time.h>
#include <sstream>
#include <iomanip>
#include <cmath>
#include "ORepHelpers.h"
#include "DBServer_SQLite.h"
......@@ -258,7 +259,9 @@ void DBServer_SQLite::parse( UniSetTypes::SensorMessage *si )
struct timezone tz;
gettimeofday(&si->tm,&tz);
}
float val = (float)si->value / (float)pow10(si->ci.precision);
// см. DBTABLE AnalogSensors, DigitalSensors
ostringstream data;
data << "INSERT INTO " << tblName(si->type)
......@@ -266,10 +269,10 @@ void DBServer_SQLite::parse( UniSetTypes::SensorMessage *si )
// Поля таблицы
<< ui.dateToString(si->sm_tv_sec,"-") << "','" // date
<< ui.timeToString(si->sm_tv_sec,":") << "','" // time
<< si->sm_tv_usec << "'," // time_usec
<< si->id << "," // sensor_id
<< si->value << "," // value
<< si->node << ")"; // node
<< si->sm_tv_usec << "','" // time_usec
<< si->id << "','" // sensor_id
<< si->value << "','" // value
<< si->node << "')"; // node
if( unideb.debugging(DBLEVEL) )
unideb[DBLEVEL] << myname << "(insert_main_history): " << data.str() << endl;
......
......@@ -325,6 +325,11 @@ class MBExchange:
PassiveTimer ptReopen; /*!< таймер для переоткрытия соединения */
Trigger trReopen;
// т.к. пороговые датчики не связаны напрямую с обменом, создаём для них отдельный список
// и отдельно его проверяем потом
typedef std::list<IOBase> ThresholdList;
ThresholdList thrlist;
private:
MBExchange();
......
......@@ -301,17 +301,14 @@ void RTUExchange::poll()
updateSM();
// check thresholds
for( MBExchange::RTUDeviceMap::iterator it1=rmap.begin(); it1!=rmap.end(); ++it1 )
for( ThresholdList::iterator t=thrlist.begin(); t!=thrlist.end(); ++t )
{
RTUDevice* d(it1->second);
for( RTUExchange::RegMap::iterator it=d->regmap.begin(); it!=d->regmap.end(); ++it )
{
RegInfo* r(it->second);
for( PList::iterator i=r->slst.begin(); i!=r->slst.end(); ++i )
IOBase::processingThreshold( &(*i),shm,force);
}
if( !checkProcActive() )
return;
IOBase::processingThreshold(&(*t),shm,force);
}
if( trReopen.hi(allNotRespond) )
ptReopen.reset();
......
......@@ -4,11 +4,11 @@
--confile test.xml \
--mbtcp-name MBMaster1 \
--smemory-id SharedMemory \
--dlog-add-levels info,crit,warn,level4,level3 \
--dlog-add-levels info,crit,warn,level4,level3,level9 \
--mbtcp-set-prop-prefix \
--mbtcp-filter-field rs \
--mbtcp-filter-value 5 \
--mbtcp-gateway-iaddr 127.0.0.1 \
--mbtcp-gateway-iaddr 192.168.1.42 \
--mbtcp-gateway-port 2048 \
--mbtcp-recv-timeout 5000 \
--mbtcp-force-disconnect 1 \
......
......@@ -9,11 +9,11 @@ using namespace VTypes;
// --------------------------------------------------------------------------
static void print_help()
{
printf("Usage: vtconv TYPE[F2|F4|I2|U2] hex1 hex2 [hex3 hex4]\n");
printf("Usage: vtconv TYPE[F2|F2r|F4|I2|U2|I2r|U2r] hex1 hex2 [hex3 hex4]\n");
}
// --------------------------------------------------------------------------
int main( int argc, const char **argv )
{
{
/*
VTypes::F2 f2;
f2.raw.val = 2.345;
......@@ -89,6 +89,13 @@ int main( int argc, const char **argv )
<< " v[1]=" << v[1]
<< " --> (float) " << (float)f << endl;
}
else if( !strcmp(type,"F2r") )
{
VTypes::F2r f(v,sizeof(v));
cout << "(F2r): v[0]=" << v[0]
<< " v[1]=" << v[1]
<< " --> (float) " << (float)f << endl;
}
else if( !strcmp(type,"F4") )
{
VTypes::F4 f(v,sizeof(v));
......@@ -105,6 +112,13 @@ int main( int argc, const char **argv )
<< " v[1]=" << v[1]
<< " --> (int) " << (int)i << endl;
}
else if( !strcmp(type,"I2r") )
{
VTypes::I2r i(v,sizeof(v));
cout << "(I2r): v[0]=" << v[0]
<< " v[1]=" << v[1]
<< " --> (int) " << (int)i << endl;
}
else if( !strcmp(type,"U2") )
{
VTypes::U2 i(v,sizeof(v));
......@@ -112,6 +126,13 @@ int main( int argc, const char **argv )
<< " v[1]=" << v[1]
<< " --> (unsigned int) " << (unsigned int)i << endl;
}
else if( !strcmp(type,"U2r") )
{
VTypes::U2r i(v,sizeof(v));
cout << "(U2r): v[0]=" << v[0]
<< " v[1]=" << v[1]
<< " --> (unsigned int) " << (unsigned int)i << endl;
}
else
{
cout << " Unknown type: " << type << endl;
......
......@@ -77,8 +77,8 @@ prefix(prefix)
if( speed.empty() )
speed = "38400";
bool use485F = conf->getArgInt("--rs-use485F",it.getProp("use485F"));
bool transmitCtl = conf->getArgInt("--rs-transmit-ctl",it.getProp("transmitCtl"));
bool use485F = conf->getArgInt("--" + prefix +"-use485F",it.getProp("use485F"));
bool transmitCtl = conf->getArgInt("--" + prefix + "-transmit-ctl",it.getProp("transmitCtl"));
ModbusRTUSlaveSlot* rs = new ModbusRTUSlaveSlot(dev,use485F,transmitCtl);
rs->setSpeed(speed);
......@@ -1287,7 +1287,7 @@ ModbusRTU::mbErrCode MBSlave::real_read_it( IOMap::iterator& it, ModbusRTU::Modb
{
val = IOBase::processingAsAO(p,shm,force);
}
if( p->vtype == VTypes::vtF2 )
else if( p->vtype == VTypes::vtF2 )
{
float f = IOBase::processingFasAO(p,shm,force);
VTypes::F2 f2(f);
......@@ -1297,6 +1297,16 @@ ModbusRTU::mbErrCode MBSlave::real_read_it( IOMap::iterator& it, ModbusRTU::Modb
// if( p->wnum >=0 && p->wnum < f4.wsize()
val = f2.raw.v[p->wnum];
}
else if( p->vtype == VTypes::vtF2r )
{
float f = IOBase::processingFasAO(p,shm,force);
VTypes::F2r f2(f);
// оптимизируем и проверку не делаем
// считая, что при "загрузке" всё было правильно
// инициализировано
// if( p->wnum >=0 && p->wnum < f4.wsize()
val = f2.raw.v[p->wnum];
}
else if( p->vtype == VTypes::vtF4 )
{
float f = IOBase::processingFasAO(p,shm,force);
......@@ -1317,6 +1327,16 @@ ModbusRTU::mbErrCode MBSlave::real_read_it( IOMap::iterator& it, ModbusRTU::Modb
// if( p->wnum >=0 && p->wnum < i2.wsize()
val = i2.raw.v[p->wnum];
}
else if( p->vtype == VTypes::vtI2r )
{
long v = IOBase::processingAsAO(p,shm,force);
VTypes::I2r i2(v);
// оптимизируем и проверку не делаем
// считая, что при "загрузке" всё было правильно
// инициализировано
// if( p->wnum >=0 && p->wnum < i2.wsize()
val = i2.raw.v[p->wnum];
}
else if( p->vtype == VTypes::vtU2 )
{
unsigned long v = IOBase::processingAsAO(p,shm,force);
......@@ -1327,6 +1347,16 @@ ModbusRTU::mbErrCode MBSlave::real_read_it( IOMap::iterator& it, ModbusRTU::Modb
// if( p->wnum >=0 && p->wnum < u2.wsize()
val = u2.raw.v[p->wnum];
}
else if( p->vtype == VTypes::vtU2r )
{
unsigned long v = IOBase::processingAsAO(p,shm,force);
VTypes::U2r u2(v);
// оптимизируем и проверку не делаем
// считая, что при "загрузке" всё было правильно
// инициализировано
// if( p->wnum >=0 && p->wnum < u2.wsize()
val = u2.raw.v[p->wnum];
}
else
val = IOBase::processingAsAO(p,shm,force);
}
......
......@@ -32,6 +32,7 @@ void SharedMemory::help_print( int argc, const char* const* argv )
cout << "--pulsar-id - датчик 'мигания'" << endl;
cout << "--pulsar-msec - период 'мигания'. По умолчанию: 5000." << endl;
cout << "--pulsar-iotype - [DI|DO]тип датчика для 'мигания'. По умолчанию DI." << endl;
cout << "--db-logging [1,0] - Включение логирования в DBServer. По умолчанию 0 (выключено)" << endl;
}
// -----------------------------------------------------------------------------
SharedMemory::SharedMemory( ObjectId id, string datafile, std::string confname ):
......
......@@ -44,19 +44,19 @@ int main(int argc, const char **argv)
}
catch( SystemError& err )
{
unideb[Debug::CRIT] << "(smemory): " << err << endl;
dlog[Debug::CRIT] << "(smemory): " << err << endl;
}
catch( Exception& ex )
{
unideb[Debug::CRIT] << "(smemory): " << ex << endl;
dlog[Debug::CRIT] << "(smemory): " << ex << endl;
}
catch( std::exception& e )
{
unideb[Debug::CRIT] << "(smemory): " << e.what() << endl;
dlog[Debug::CRIT] << "(smemory): " << e.what() << endl;
}
catch(...)
{
unideb[Debug::CRIT] << "(smemory): catch(...)" << endl;
dlog[Debug::CRIT] << "(smemory): catch(...)" << endl;
}
return 1;
......
......@@ -58,15 +58,15 @@ int main(int argc, const char **argv)
}
catch(SystemError& err)
{
unideb[Debug::CRIT] << "(uninetwork): " << err << endl;
dlog[Debug::CRIT] << "(uninetwork): " << err << endl;
}
catch(Exception& ex)
{
unideb[Debug::CRIT] << "(uninetwork): " << ex << endl;
dlog[Debug::CRIT] << "(uninetwork): " << ex << endl;
}
catch(...)
{
unideb[Debug::CRIT] << "(uninetwork): catch(...)" << endl;
dlog[Debug::CRIT] << "(uninetwork): catch(...)" << endl;
}
while( waitpid(-1, 0, 0) > 0 );
......
......@@ -101,7 +101,7 @@ static const int NoSafety = -1;
хранится идентификатор аналогового датчика
с которым он связан */
IONotifyController_i::ThresholdInfo ti;
IOController::AIOStateList::iterator t_ait; /*! итератор на датчик по которому формируется порог */
IOController::AIOStateList::iterator ait;
IOController::DIOStateList::iterator dit;
......
......@@ -16,12 +16,15 @@ namespace VTypes
{
vtUnknown,
vtF2, /*!< двойное слово float(4 байта). В виде строки задаётся как \b "F2". */
vtF2r, /*!< двойное слово float(4 байта). С перевёрнутой (reverse) последовательностью слов. \b "F2r". */
vtF4, /*!< 8-х байтовое слово (double). В виде строки задаётся как \b "F4". */
vtByte, /*!< байт. В виде строки задаётся как \b "byte". */
vtUnsigned, /*!< беззнаковое целое (2 байта). В виде строки задаётся как \b "unsigned". */
vtSigned, /*!< знаковое целое (2 байта). В виде строки задаётся как \b "signed". */
vtI2, /*!< целое (4 байта). В виде строки задаётся как \b "I2".*/
vtU2 /*!< беззнаковое целое (4 байта). В виде строки задаётся как \b "U2".*/
vtI2r, /*!< целое (4 байта). С перевёрнутой (reverse) последовательностью слов. В виде строки задаётся как \b "I2r".*/
vtU2, /*!< беззнаковое целое (4 байта). В виде строки задаётся как \b "U2".*/
vtU2r /*!< беззнаковое целое (4 байта). С перевёрнутой (reverse) последовательностью слов. В виде строки задаётся как \b "U2r".*/
};
std::ostream& operator<<( std::ostream& os, const VType& vt );
......@@ -67,6 +70,24 @@ namespace VTypes
F2mem raw;
};
// --------------------------------------------------------------------------
class F2r:
public F2
{
public:
// ------------------------------------------
// конструкторы на разные случаи...
F2r(){}
F2r( float f ):F2(f){}
F2r( const ModbusRTU::ModbusData* data, int size ):F2(data,size)
{
std::swap(raw.v[0],raw.v[1]);
}
~F2r(){}
};
// --------------------------------------------------------------------------
class F4
{
public:
......@@ -239,6 +260,21 @@ namespace VTypes
I2mem raw;
};
// --------------------------------------------------------------------------
class I2r:
public I2
{
public:
I2r(){}
I2r( int v ):I2(v){}
I2r( const ModbusRTU::ModbusData* data, int size ):I2(data,size)
{
std::swap(raw.v[0],raw.v[1]);
}
~I2r(){}
};
// --------------------------------------------------------------------------
class U2
{
public:
......@@ -274,6 +310,21 @@ namespace VTypes
U2mem raw;
};
// --------------------------------------------------------------------------
class U2r:
public U2
{
public:
U2r(){}
U2r( int v ):U2(v){}
U2r( const ModbusRTU::ModbusData* data, int size ):U2(data,size)
{
std::swap(raw.v[0],raw.v[1]);
}
~U2r(){}
};
// --------------------------------------------------------------------------
} // end of namespace VTypes
// --------------------------------------------------------------------------
......
......@@ -431,12 +431,26 @@ bool send_param( ModbusRTUMaster* mb, DataMap& dmap, ModbusRTU::ModbusAddr addr,
// if( !ok )
// return false;
}
ModbusRTU::WriteSingleOutputRetMessage ret = mb->write06(addr,regUpdateConfiguration,1);
if( verb )
cout << "(mtr-setup): save parameters " << endl;
return true;
try
{
ModbusRTU::ModbusData dat = 1;
ModbusRTU::WriteSingleOutputRetMessage ret = mb->write06( addr, regUpdateConfiguration, dat);
if( ret.start == regUpdateConfiguration && ret.data == dat )
{
if( verb )
cout << "(mtr-setup): save parameters " << endl;
return true;
}
}
catch( ModbusRTU::mbException& ex )
{
}
if( verb )
cout << "(mtr-setup): not save parameters " << endl;
return false;
}
// ------------------------------------------------------------------------------------------
MTR::MTRError update_configuration( ModbusRTUMaster* mb, ModbusRTU::ModbusAddr slaveaddr,
......
......@@ -18,6 +18,8 @@ VType str2type( const std::string& s )
return vtByte;
if( s == "F2" || s == "f2" )
return vtF2;
if( s == "F2r" || s == "f2r" )
return vtF2r;
if( s == "F4" || s == "f4" )
return vtF4;
if( s == "Unsigned" || s == "unsigned" )
......@@ -26,8 +28,12 @@ VType str2type( const std::string& s )
return vtSigned;
if( s == "I2" || s == "i2" )
return vtI2;
if( s == "I2r" || s == "i2r" )
return vtI2r;
if( s == "U2" || s == "u2" )
return vtU2;
if( s == "U2r" || s == "u2r" )
return vtU2r;
return vtUnknown;
}
......@@ -38,6 +44,8 @@ string type2str( VType t )
return "Byte";
if( t == vtF2 )
return "F2";
if( t == vtF2r )
return "F2r";
if( t == vtF4 )
return "F4";
if( t == vtUnsigned )
......@@ -46,8 +54,12 @@ string type2str( VType t )
return "Signed";
if( t == vtI2 )
return "I2";
if( t == vtI2r )
return "I2r";
if( t == vtU2 )
return "U2";
if( t == vtU2r )
return "U2r";
return "vtUnknown";
}
......@@ -56,7 +68,7 @@ int wsize( VType t )
{
if( t == vtByte )
return Byte::wsize();
if( t == vtF2 )
if( t == vtF2 || t == vtF2r )
return F2::wsize();
if( t == vtF4 )
return F4::wsize();
......@@ -64,9 +76,9 @@ int wsize( VType t )
return Unsigned::wsize();
if( t == vtSigned )
return Signed::wsize();
if( t == vtI2 )
if( t == vtI2 || t == vtI2r )
return I2::wsize();
if( t == vtU2 )
if( t == vtU2 || t == vtU2r )
return U2::wsize();
return 1;
......
......@@ -82,9 +82,9 @@ public:
void setCharacterSize(CharacterSize);
void setStopBits(StopBits sBit);
virtual void setTimeout(int timeout);
void setWaiting(bool waiting);
inline int getTimeout(){ return uTimeout*1000; } // msec
virtual void setTimeout( int msec );
inline int getTimeout(){ return uTimeout/1000; } // msec
void setWaiting( bool waiting );
virtual unsigned char receiveByte();
virtual void sendByte(unsigned char x);
......
......@@ -257,9 +257,9 @@ void ComPort::sendByte(unsigned char x)
}
// --------------------------------------------------------------------------------
// Lav: убрать, переделать в receiveBlock
void ComPort::setTimeout(int timeout)
void ComPort::setTimeout( int msec )
{
uTimeout=timeout;
uTimeout = msec * 1000;
}
// --------------------------------------------------------------------------------
// Lav: ситуация, когда отправлено меньше запрошенного, не типична и должна
......
......@@ -73,10 +73,10 @@ ComPort485F::ComPort485F( string dev, int gpio_num, bool tmit_ctrl ):
}
}
// --------------------------------------------------------------------------------
void ComPort485F::setTimeout(int timeout)
void ComPort485F::setTimeout( int msec )
{
tout_msec = timeout / 1000;
ComPort::setTimeout(timeout);
tout_msec = msec;
ComPort::setTimeout(msec);
}
// --------------------------------------------------------------------------------
unsigned char ComPort485F::m_receiveByte( bool wait )
......
......@@ -35,7 +35,7 @@ ModbusRTUMaster::ModbusRTUMaster( const string dev, bool use485, bool tr_ctl ):
port->setCharacterSize(ComPort::CSize8);
port->setStopBits(ComPort::OneBit);
port->setWaiting(true);
port->setTimeout(replyTimeOut_ms*1000);
port->setTimeout(replyTimeOut_ms);
// port->setBlocking(false);
}
// -------------------------------------------------------------------------
......@@ -51,7 +51,7 @@ ModbusRTUMaster::ModbusRTUMaster( ComPort* com ):
port->setCharacterSize(ComPort::CSize8);
port->setStopBits(ComPort::OneBit);
port->setWaiting(true);
port->setTimeout(replyTimeOut_ms*1000);
port->setTimeout(replyTimeOut_ms);
// port->setBlocking(false);
}
// -------------------------------------------------------------------------
......@@ -116,7 +116,7 @@ int ModbusRTUMaster::getNextData( unsigned char* buf, int len )
void ModbusRTUMaster::setChannelTimeout( timeout_t msec )
{
if( port )
port->setTimeout(msec*1000);
port->setTimeout(msec);
}
// --------------------------------------------------------------------------------
mbErrCode ModbusRTUMaster::sendData( unsigned char* buf, int len )
......
......@@ -35,7 +35,7 @@ ModbusRTUSlave::ModbusRTUSlave( const string dev, bool use485, bool tr_ctl ):
port->setCharacterSize(ComPort::CSize8);
port->setStopBits(ComPort::OneBit);
port->setWaiting(true);
port->setTimeout(recvTimeOut_ms*1000);
port->setTimeout(recvTimeOut_ms);
// port->setBlocking(false);
}
......@@ -49,7 +49,7 @@ ModbusRTUSlave::ModbusRTUSlave( ComPort* com ):
port->setCharacterSize(ComPort::CSize8);
port->setStopBits(ComPort::OneBit);
port->setWaiting(true);
port->setTimeout(recvTimeOut_ms*1000);
port->setTimeout(recvTimeOut_ms);
// port->setBlocking(false);
}
......@@ -129,9 +129,9 @@ int ModbusRTUSlave::getNextData( unsigned char* buf, int len )
void ModbusRTUSlave::setChannelTimeout( timeout_t msec )
{
if( msec == UniSetTimer::WaitUpTime )
port->setTimeout(15*60*1000*1000); // используем просто большое время (15 минут). Переведя его в наносекунды.
port->setTimeout(15*60*1000); // используем просто большое время (15 минут).
else
port->setTimeout(msec*1000);
port->setTimeout(msec);
}
// --------------------------------------------------------------------------------
mbErrCode ModbusRTUSlave::sendData( unsigned char* buf, int len )
......
......@@ -173,8 +173,9 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
if( dlog.debugging(Debug::INFO) )
dlog[Debug::INFO] << "(ModbusTCPMaster::query): ret=" << (int)ret
<< " < rmh=" << (int)sizeof(rmh)
<< " err: " << tcp->getErrorNumber()
<< " errnum: " << tcp->getErrorNumber()
<< " perr: " << tcp->getPeer(&port)
<< " err: " << string(tcp->getErrorString())
<< endl;
disconnect();
......@@ -313,6 +314,7 @@ void ModbusTCPMaster::reconnect()
// 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->setTimeout(replyTimeOut_ms);
tcp->setKeepAlive(true);
}
catch( std::exception& e )
{
......@@ -364,6 +366,7 @@ void ModbusTCPMaster::connect( ost::InetAddress addr, int port )
{
tcp = new ost::TCPStream(iaddr.c_str(),ost::Socket::IPV4,536,true,500);
tcp->setTimeout(replyTimeOut_ms);
tcp->setKeepAlive(true);
}
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