Commit b0a52ad2 authored by Pavel Vainerman's avatar Pavel Vainerman

fized bug in MBTCPMaster

parent 705343d1
......@@ -21,7 +21,8 @@ mbregFromID(false),
activated(false),
noQueryOptimization(false),
allNotRespond(false),
prefix(prefix)
prefix(prefix),
no_extimer(false)
{
// cout << "$ $" << endl;
......@@ -119,7 +120,7 @@ prefix(prefix)
activateTimeout = conf->getArgPInt("--" + prefix + "-activate-timeout", 20000);
initMB(false);
// initMB(false);
printMap(rmap);
// abort();
......@@ -163,6 +164,9 @@ void MBTCPMaster::initMB( bool reopen )
mb->setTimeout(recv_timeout);
dlog[Debug::INFO] << myname << "(init): ipaddr=" << iaddr << " port=" << port << endl;
if( dlog.debugging(Debug::LEVEL9) )
mb->setLog(dlog);
}
catch( ModbusRTU::mbException& ex )
{
......@@ -197,7 +201,12 @@ void MBTCPMaster::waitSMReady()
void MBTCPMaster::timerInfo( TimerMessage *tm )
{
if( tm->id == tmExchange )
step();
{
if( no_extimer )
askTimer(tm->id,0);
else
step();
}
}
// -----------------------------------------------------------------------------
void MBTCPMaster::step()
......@@ -1515,6 +1524,9 @@ void MBTCPMaster::updateRSProperty( RSProperty* p, bool write_only )
if( !save && write_only )
return;
if( dlog.debugging(Debug::INFO) )
dlog[Debug::INFO] << "udpateP: sid=" << p->si.id << " mbval=" << r->mbval << endl;
try
{
if( p->vType == VTypes::vtUnknown )
......@@ -1715,4 +1727,34 @@ void MBTCPMaster::updateRSProperty( RSProperty* p, bool write_only )
}
}
// -----------------------------------------------------------------------------
void MBTCPMaster::execute()
{
no_extimer = true;
try
{
askTimer(tmExchange,0);
}
catch(...){}
initMB(false);
while(1)
{
try
{
step();
}
catch( Exception& ex )
{
dlog[Debug::CRIT] << myname << "(execute): " << ex << std::endl;
}
catch(...)
{
dlog[Debug::CRIT] << myname << "(execute): catch ..." << endl;
}
msleep(polltime);
}
}
// -----------------------------------------------------------------------------
......@@ -37,6 +37,8 @@ class MBTCPMaster:
/*! help- */
static void help_print( int argc, const char* const* argv );
void execute();
static const int NoSafetyState=-1;
enum Timer
......@@ -235,6 +237,8 @@ class MBTCPMaster:
Trigger trAllNotRespond;
PassiveTimer ptAllNotRespond;
std::string prefix;
bool no_extimer;
};
// -----------------------------------------------------------------------------
#endif // _MBTCPMaster_H_
......
......@@ -1546,7 +1546,7 @@ bool RTUExchange::initDeviceInfo( RTUDeviceMap& m, ModbusRTU::ModbusAddr a, UniX
// -----------------------------------------------------------------------------
void RTUExchange::printMap( RTUExchange::RTUDeviceMap& m )
{
cout << "devices: " << endl;
cout << "devices: num=" << m.size() << endl;
for( RTUExchange::RTUDeviceMap::iterator it=m.begin(); it!=m.end(); ++it )
{
cout << " " << *(it->second) << endl;
......
......@@ -17,7 +17,8 @@ SharedMemory::SharedMemory( ObjectId id, string datafile ):
activated(false),
workready(false),
dblogging(false),
msecPulsar(0)
msecPulsar(0),
iotypePulsar(UniversalIO::DigitalInput)
{
// cout << "$Id: SharedMemory.cc,v 1.4 2009/01/24 11:20:19 vpashka Exp $" << endl;
......@@ -100,6 +101,19 @@ SharedMemory::SharedMemory( ObjectId id, string datafile ):
siPulsar.node = conf->getLocalNode();
msecPulsar = conf->getArgPInt("--pulsar-msec",it.getProp("pulsar_msec"), 5000);
string t = conf->getArgParam("--pulsar-iotype",it.getProp("pulsar_iotype"));
if( !t.empty() )
{
iotypePulsar = UniSetTypes::getIOType(t);
if( iotypePulsar == UniversalIO::UnknownIOType )
{
ostringstream err;
err << myname << ": Unknown iotype '" << t << "' for pulsar. Must be 'DI' or 'DO'";
dlog[Debug::CRIT] << myname << "(init): " << err.str() << endl;
throw SystemError(err.str());
}
}
}
}
......@@ -184,7 +198,10 @@ void SharedMemory::timerInfo( TimerMessage *tm )
{
bool st = localGetState(ditPulsar,siPulsar);
st ^= true;
localSaveState(ditPulsar,siPulsar,st,getId());
if( iotypePulsar == UniversalIO::DigitalInput )
localSaveState(ditPulsar,siPulsar,st,getId());
else if( iotypePulsar == UniversalIO::DigitalOutput )
localSetState(ditPulsar,siPulsar,st,getId());
}
}
}
......
......@@ -189,6 +189,7 @@ class SharedMemory:
DIOStateList::iterator ditPulsar;
IOController_i::SensorInfo siPulsar;
UniversalIO::IOTypes iotypePulsar;
int msecPulsar;
private:
......
......@@ -4,7 +4,7 @@ export LD_LIBRARY_PATH="../../lib/.libs;../lib/.libs"
ulimit -Sc 10000000000
./uniset-start.sh -f ./uniset-smemory --smemory-id SharedMemory --pulsar-id TestMode_S \
./uniset-start.sh -f ./uniset-smemory --smemory-id SharedMemory --pulsar-id DO_C \
--confile test.xml --datfile test.xml \
--unideb-add-levels info,crit,warn,level9,system \
--dlog-add-levels info,crit,warn
......
......@@ -35,7 +35,7 @@ class ModbusTCPMaster:
private:
ost::TCPStream* tcp;
static int nTransaction;
int nTransaction;
std::queue<unsigned char> qrecv;
PassiveTimer ptTimeout;
std::string iaddr;
......
......@@ -14,6 +14,7 @@ using namespace UniSetTypes;
// -------------------------------------------------------------------------
ModbusTCPMaster::ModbusTCPMaster():
tcp(0),
nTransaction(0),
iaddr("")
{
setCRCNoCheckit(true);
......@@ -56,7 +57,8 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
}
reconnect();
if( !isConnection() )
reconnect();
assert(timeout);
ptTimeout.setTiming(timeout);
......@@ -67,7 +69,7 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
try
{
if( nTransaction >= numeric_limits<int>::max() )
if( nTransaction >= numeric_limits<ModbusRTU::ModbusData>::max() )
nTransaction = 0;
ModbusTCP::MBAPHeader mh;
......@@ -122,7 +124,7 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
}
if( ret < (int)sizeof(rmh) )
return erHardwareError;
return erTimeOut; // return erHardwareError;
rmh.swapdata();
......
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