Commit 1aa7a6a5 authored by Pavel Vainerman's avatar Pavel Vainerman

fixed bug in MBTCPMaster and minor fixed in debug logs

parent 9e44a19f
......@@ -84,7 +84,7 @@
<RSExchange name="RSExchange" speed="38400">
<DeviceList>
<item addr="0x02" speed="9600" respondSensor="RTU_Not_Respond_FS" timeout="2000" invert="0"/>
<item addr="0x02" speed="9600" respondSensor="RespondRTU_S" timeout="5000" invert="0"/>
</DeviceList>
</RSExchange>
......@@ -103,7 +103,7 @@
textname -
-->
<nodes port="2809">
<item name="LocalhostNode" alias="" textname=" " ip="127.0.0.1" infserver="InfoServer" dbserver="DBServer"/>
<item name="LocalhostNode" alias="" textname=" " ip="127.0.0.1" infserver="InfoServer" dbserver=""/>
<item name="Node2" alias="" textname=" " ip="127.0.0.1" infserver="InfoServer" dbserver=""/>
</nodes>
......@@ -111,7 +111,8 @@
<sensors name="Sensors">
<item name="Input1_S" textname=" 1" node="" iotype="DI" priority="Medium" default="1" />
<item name="Input2_S" textname=" 2" node="" iotype="DI" priority="Medium" mbtype="rtu" mbaddr="0x01" mbfunc="0x04" mbreg="0x02" rs="2" />
<item name="Input3_S" textname=" 3" node="" iotype="DI" priority="Medium" mbtcp="1" mbaddr="0x02" mbfunc="0x04" mbreg="0x02"/>
<item name="Input3_S" textname=" 3" node="" iotype="DI" priority="Medium"
mbtcp="1" tcp_mbtype="rtu" tcp_mbaddr="0x02" tcp_mbfunc="0x04" tcp_mbreg="0x02"/>
<item name="Input4_S" textname=" 4" node="" iotype="DI" priority="Medium" mbtype="rtu" mbaddr="0x02" mbfunc="0x04" mbreg="0x02" rs="2" />
<item name="Input5_S" textname=" 5" node="" iotype="DI" priority="Medium" udp="2"/>
<item name="Input6_S" textname=" 6" node="" iotype="DI" priority="Medium" udp="2">
......
......@@ -192,7 +192,7 @@ void MBTCPMaster::waitSMReady()
if( !shm->waitSMready(ready_timeout, 50) )
{
ostringstream err;
err << myname << "(waitSMReady): SharedMemory " << ready_timeout << " ";
err << myname << "(waitSMReady): failed waiting SharedMemory " << ready_timeout << " msec";
dlog[Debug::CRIT] << err.str() << endl;
throw SystemError(err.str());
}
......@@ -254,6 +254,7 @@ void MBTCPMaster::poll()
for( MBTCPMaster::RTUDeviceMap::iterator it=rmap.begin(); it!=rmap.end(); ++it )
it->second->resp_real = false;
}
cerr << "*********** mb=NULL " << endl;
updateSM();
return;
}
......@@ -393,7 +394,7 @@ bool MBTCPMaster::pollRTU( RTUDevice* dev, RegMap::iterator& it )
return false;
}
cerr << "**** mbreg=" << ModbusRTU::dat2str(p->mbreg) << " val=" << ModbusRTU::dat2str(p->mbval) << endl;
// cerr << "**** mbreg=" << ModbusRTU::dat2str(p->mbreg) << " val=" << ModbusRTU::dat2str(p->mbval) << endl;
ModbusRTU::WriteSingleOutputRetMessage ret = mb->write06(dev->mbaddr,p->mbreg+p->offset,p->mbval);
}
break;
......@@ -417,7 +418,7 @@ bool MBTCPMaster::pollRTU( RTUDevice* dev, RegMap::iterator& it )
return false;
}
cerr << "****(coil) mbreg=" << ModbusRTU::dat2str(p->mbreg) << " val=" << ModbusRTU::dat2str(p->mbval) << endl;
// cerr << "****(coil) mbreg=" << ModbusRTU::dat2str(p->mbreg) << " val=" << ModbusRTU::dat2str(p->mbval) << endl;
ModbusRTU::ForceSingleCoilRetMessage ret = mb->write05(dev->mbaddr,p->mbreg+p->offset,p->mbval);
}
break;
......@@ -478,13 +479,15 @@ void MBTCPMaster::updateSM()
for( MBTCPMaster::RTUDeviceMap::iterator it1=rmap.begin(); it1!=rmap.end(); ++it1 )
{
RTUDevice* d(it1->second);
/*
cout << "check respond addr=" << ModbusRTU::addr2str(d->mbaddr)
if( dlog.debugging(Debug::LEVEL4) )
{
dlog[Debug::LEVEL4] << "check respond addr=" << ModbusRTU::addr2str(d->mbaddr)
<< " respond=" << d->resp_id
<< " real=" << d->resp_real
<< " state=" << d->resp_state
<< endl;
*/
}
if( d->resp_real )
allNotRespond = false;
......
......@@ -56,7 +56,7 @@ int main( int argc, const char** argv )
MBTCPMaster* mb = MBTCPMaster::init_mbmaster(argc,argv,shmID);
if( !mb )
{
dlog[Debug::CRIT] << "(mbmaster): init ۣ..." << endl;
dlog[Debug::CRIT] << "(mbmaster): init MBTCPMaster failed." << endl;
return 1;
}
......
#!/bin/sh
uniset-start.sh -f ./uniset-mbtcpmaster --mbtcp-name MBTCPExchange1 \
--dlog-add-levels info,crit,warn \
--mbtcp-filter-field CAN2sender \
--mbtcp-filter-value SYSTSNode \
uniset-start.sh -f ./uniset-mbtcpmaster \
--confile test.xml \
--mbtcp-name MBMaster1 \
--smemory-id SharedMemory \
--dlog-add-levels info,crit,warn,level4 \
--mbtcp-filter-field mbtcp \
--mbtcp-filter-value 1 \
--mbtcp-gateway-iaddr 127.0.0.1 \
--mbtcp-gateway-port 2048
--mbtcp-gateway-port 1024 \
--mbtcp-recv-timeout 5000
#--mbtcp-filter-field mbtcp --mbtcp-filter-value 1
......@@ -17,8 +17,8 @@ SharedMemory::SharedMemory( ObjectId id, string datafile ):
activated(false),
workready(false),
dblogging(false),
msecPulsar(0),
iotypePulsar(UniversalIO::DigitalInput)
iotypePulsar(UniversalIO::DigitalInput),
msecPulsar(0)
{
// cout << "$Id: SharedMemory.cc,v 1.4 2009/01/24 11:20:19 vpashka Exp $" << endl;
......@@ -168,6 +168,25 @@ void SharedMemory::processingMessage( UniSetTypes::VoidMessage *msg )
{
dlog[Debug::CRIT] << myname << "(processingMessage): " << ex << endl;
}
catch(CORBA::SystemException& ex)
{
dlog[Debug::WARN] << myname << "(processingMessage): CORBA::SystemException: " << ex.NP_minorString() << endl;
}
catch(CORBA::Exception& ex)
{
dlog[Debug::WARN] << myname << "(processingMessage): CORBA::Exception: " << ex._name() << endl;
}
catch( omniORB::fatalException& fe )
{
dlog[Debug::CRIT] << myname << "(processingMessage): Caught omniORB::fatalException:" << endl;
dlog[Debug::CRIT] << myname << "(processingMessage): file: " << fe.file()
<< " line: " << fe.line()
<< " mesg: " << fe.errmsg() << endl;
}
catch(...)
{
dlog[Debug::CRIT] << myname << "(processingMessage): catch..." << endl;
}
}
// ------------------------------------------------------------------------------------------
......@@ -281,6 +300,7 @@ bool SharedMemory::activateObject()
{
PassiveTimer pt(UniSetTimer::WaitUpTime);
bool res = true;
// Startup
// ģ
// . sysCommand()
......@@ -311,6 +331,7 @@ bool SharedMemory::activateObject()
activated = true;
}
cerr << "************************** activate: " << pt.getCurrent() << " msec " << endl;
return res;
}
......
......@@ -93,23 +93,35 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
mbPrintMessage( dlog, (ModbusByte*)(&mh), sizeof(mh));
dlog(Debug::INFO) << endl;
}
for( int i=0; i<2; i++ )
{
(*tcp) << mh;
mh.swapdata();
// send PDU
mbErrCode res = send(msg);
if( res!=erNoError )
return res;
if( !tcp->isPending(ost::Socket::pendingOutput,timeout) )
{
if( tcp->isPending(ost::Socket::pendingOutput,timeout) )
break;
if( dlog.debugging(Debug::INFO) )
dlog[Debug::INFO] << "(ModbusTCPMaster): no write pending.. reconnnect.." << endl;
dlog[Debug::INFO] << "(ModbusTCPMaster::query): no write pending.. reconnnect.." << endl;
reconnect();
if( !isConnection() )
{
dlog[Debug::WARN] << "(ModbusTCPMaster::query): not connected to server..." << endl;
return erTimeOut;
}
if( dlog.debugging(Debug::INFO) )
dlog[Debug::INFO] << "(ModbusTCPMaster::query): no write pending.. reconnnect OK" << endl;
}
mh.swapdata();
if( timeout != UniSetTimer::WaitUpTime )
{
timeout = ptTimeout.getLeft(timeout);
......@@ -159,6 +171,8 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
// return recv_pdu(msg.func,reply,timeout);
}
if( dlog.debugging(Debug::INFO) )
dlog[Debug::INFO] << "(query): input pending timeout " << endl;
return erTimeOut;
}
catch( ModbusRTU::mbException& ex )
......
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