Commit a2756ef7 authored by Pavel Vainerman's avatar Pavel Vainerman

testing

parent 2cebcea4
......@@ -93,7 +93,7 @@
<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="0x31" mbfunc="0x04" mbreg="0x02" rs="1" />
<item name="Input3_S" textname=" 3" node="" iotype="DI" priority="Medium" udp="1"/>
<item name="Input3_S" textname=" 3" node="" iotype="DI" priority="Medium" mbtcp="1" mbaddr="0x31" mbfunc="0x04" mbreg="0x02"/>
<item name="Input4_S" textname=" 4" node="" iotype="DI" priority="Medium" udp="1"/>
<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">
......
......@@ -43,10 +43,11 @@ class MBMaster:
ModbusRTU::ModbusAddr mbaddr; /*!< */
ModbusRTU::ModbusData mbreg; /*!< */
ModbusRTU::SlaveFunctionCode mbfunc; /*!< / */
short nbit; /*!< bit number (for func=[0x01,0x02]) */
MBProperty():
mbaddr(0),mbreg(0),
mbfunc(ModbusRTU::fnUnknown)
mbfunc(ModbusRTU::fnUnknown),nbit(0)
{}
friend std::ostream& operator<<( std::ostream& os, MBProperty& p );
......@@ -80,7 +81,8 @@ class MBMaster:
void askSensors( UniversalIO::UIOCommand cmd );
void initOutput();
void waitSMReady();
long callItem( MBMap::iterator& p );
long readReg( MBMap::iterator& p );
bool writeReg( MBMap::iterator& p, long val );
virtual bool activateObject();
......@@ -100,6 +102,7 @@ class MBMaster:
bool initPause;
UniSetTypes::uniset_mutex mutex_start;
bool mbregFromID;
bool force; /*!< , SM, */
bool force_out; /*!< , */
int polltime; /*!< , [] */
......@@ -113,6 +116,7 @@ class MBMaster:
Trigger trTimeout;
PassiveTimer ptTimeout;
bool activated;
int activateTimeout;
std::string prefix;
......
#!/bin/sh
uniset-start.sh -f ./uniset-mbtcpmaster --mbtcp-name MBMaster1 --confile test.xml \
--dlog-add-levels info,crit,warn --mbtcp-reg-from-id 1 \
--mbtcp-iaddr 127.0.0.1 --mbtcp-port 30000
--dlog-add-levels info,crit,warn \
--mbtcp-iaddr 127.0.0.1 --mbtcp-port 2048 \
--mbtcp-filter-field mbtcp --mbtcp-filter-value 1
#--mbtcp-reg-from-id 1
\ No newline at end of file
......@@ -13,7 +13,6 @@
#include "PassiveTimer.h"
#include "Trigger.h"
#include "Mutex.h"
#include "Calibration.h"
#include "SMInterface.h"
#include "SharedMemory.h"
#include "IOBase.h"
......@@ -23,12 +22,13 @@ class MBSlave:
public UniSetObject_LT
{
public:
MBSlave( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmID, SharedMemory* ic=0 );
MBSlave( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmID, SharedMemory* ic=0, std::string prefix="mbs" );
virtual ~MBSlave();
/*! */
static MBSlave* init_mbslave( int argc, char* argv[],
UniSetTypes::ObjectId shmID, SharedMemory* ic=0 );
UniSetTypes::ObjectId shmID, SharedMemory* ic=0,
std::string prefix="mbs" );
/*! help- */
static void help_print( int argc, char* argv[] );
......@@ -172,12 +172,12 @@ class MBSlave:
bool pingOK;
int wait_msec;
bool force; /*!< , SM, */
bool force_out; /*!< , */
bool mbregFromID;
typedef std::map<int,std::string> FileList;
FileList flist;
std::string prefix;
};
// -----------------------------------------------------------------------------
#endif // _MBSlave_H_
......
#!/bin/sh
uniset-start.sh -f ./uniset-mbslave --mbs-name MBSlave1 --confile test.xml --dlog-add-levels info,crit,warn \
--mbs-type TCP --mbs-inet-addr 127.0.0.2 --mbs-inet-port 2048 --mbs-reg-from-id 1
\ No newline at end of file
--mbs-type TCP --mbs-inet-addr 127.0.0.1 --mbs-inet-port 2048 \
--mbs-filter-field rs --mbs-filter-value 1
# --mbs-force 1
#--mbs-reg-from-id 1 \
\ No newline at end of file
......@@ -252,18 +252,20 @@ bool IOBase::initItem( IOBase* b, UniXML_iterator& it, SMInterface* shm,
{
string sname( it.getProp("name") );
ObjectId sid = UniSetTypes::uni_atoi(it.getProp("id").c_str());
if( sid <=0 )
ObjectId sid = DefaultObjectId;
if( it.getProp("id").empty() )
sid = conf->getSensorID(sname);
else
{
if( dlog )
dlog[Debug::CRIT] << myname << "(readItem): ID : "
<< sname << endl;
return false;
sid = UniSetTypes::uni_atoi(it.getProp("id").c_str());
if( sid <=0 )
sid = DefaultObjectId;
}
if( sid == DefaultObjectId )
{
dlog[Debug::CRIT] << myname << "(readItem): (-1) ID : "
if( dlog )
dlog[Debug::CRIT] << myname << "(readItem): (-1) ID : "
<< sname << endl;
return false;
}
......
......@@ -439,16 +439,16 @@ void SMInterface::initAIterator( IOController::AIOStateList::iterator& it )
{
if( ic )
it = ic->aioEnd();
else
cerr << "(SMInterface::initAIterator): ic=NULL" << endl;
// else
// cerr << "(SMInterface::initAIterator): ic=NULL" << endl;
}
// --------------------------------------------------------------------------
void SMInterface::initDIterator( IOController::DIOStateList::iterator& it )
{
if( ic )
it = ic->dioEnd();
else
cerr << "(SMInterface::initDIterator): ic=NULL" << endl;
// else
// cerr << "(SMInterface::initDIterator): ic=NULL" << endl;
}
// --------------------------------------------------------------------------
bool SMInterface::waitSMready( int ready_timeout, int pmsec )
......
......@@ -24,6 +24,8 @@ class ModbusTCPMaster:
bool isConnection();
protected:
void reconnect();
virtual int getNextData( unsigned char* buf, int len );
virtual void setChannelTimeout( int msec );
......@@ -35,6 +37,8 @@ class ModbusTCPMaster:
ost::TCPStream* tcp;
static int nTransaction;
std::queue<unsigned char> qrecv;
PassiveTimer ptTimeout;
std::string iaddr;
};
// -------------------------------------------------------------------------
#endif // ModbusTCPMaster_H_
......
......@@ -13,7 +13,8 @@ using namespace ModbusRTU;
using namespace UniSetTypes;
// -------------------------------------------------------------------------
ModbusTCPMaster::ModbusTCPMaster():
tcp(0)
tcp(0),
iaddr("")
{
setCRCNoCheckit(true);
}
......@@ -46,13 +47,16 @@ int ModbusTCPMaster::nTransaction = 0;
mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
ModbusMessage& reply, int timeout )
{
if( !isConnection() )
// if( !isConnection() )
if( iaddr.empty() )
{
dlog[Debug::WARN] << "(query): not connection to server..." << endl;
return erHardwareError;
}
PassiveTimer ptTimeout;
reconnect();
if( timeout<=0 || timeout == UniSetTimer::WaitUpTime )
{
......@@ -66,6 +70,9 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
try
{
if( nTransaction >= numeric_limits<int>::max() )
nTransaction = 0;
ModbusTCP::MBAPHeader mh;
mh.tID = ++nTransaction;
mh.pID = 0;
......@@ -89,7 +96,7 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
mbErrCode res = send(msg);
if( res!=erNoError )
return res;
if( !tcp->isPending(ost::Socket::pendingOutput,timeout) )
return erTimeOut;
......@@ -159,6 +166,17 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
return erHardwareError;
}
// -------------------------------------------------------------------------
void ModbusTCPMaster::reconnect()
{
if( tcp )
{
tcp->disconnect();
delete tcp;
}
tcp = new ost::TCPStream(iaddr.c_str());
}
// -------------------------------------------------------------------------
void ModbusTCPMaster::connect( ost::InetAddress addr, int port )
{
if( !tcp )
......@@ -169,7 +187,8 @@ void ModbusTCPMaster::connect( ost::InetAddress addr, int port )
if( dlog.debugging(Debug::INFO) )
dlog[Debug::INFO] << "(ModbusTCPMaster): connect to " << s.str() << endl;
tcp = new ost::TCPStream(s.str().c_str());
iaddr = s.str();
tcp = new ost::TCPStream(iaddr.c_str());
}
}
// -------------------------------------------------------------------------
......
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