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

add new property: rtuVType mbtype="rtu"

parent f612b836
......@@ -70,8 +70,10 @@
<RTUExchange name="RTUExchange">
<RespondList>
<!--
<item addr="0x01" respondSensor="RespondRTU_S" timeout="5000"/>
<item addr="0x02" respondSensor="NoRespondRTU2_S" timeout="5000" invert="1"/>
-->
</RespondList>
</RTUExchange>
......@@ -98,9 +100,9 @@
<!-- ************************ ********************** -->
<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="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="Input4_S" textname=" 4" node="" iotype="DI" priority="Medium" mbtype="rtu" mbaddr="0x02" mbfunc="0x04" mbreg="0x02" rs="1" />
<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">
<depends>
......@@ -109,8 +111,11 @@
</item>
<item name="DO_C" textname="Digital output" node="" iotype="DO" priority="Medium"/>
<item name="DO1_C" textname="Digital output" node="" iotype="DO" priority="Medium"/>
<item name="AO_AS" textname="Analog output" node="" iotype="AO" priority="Medium"/>
<item name="AI_AS" textname="Analog input" node="" iotype="AI" default="378" priority="Medium">
<item name="AO_AS" textname="Analog output" node="" iotype="AO" priority="Medium"
mbtype="rtu" mbaddr="0x01" mbfunc="0x06" mbreg="0x02" rs="2" default="10" />
/>
<item name="AI_AS" textname="Analog input" node="" iotype="AI" default="378" priority="Medium"
mbtype="rtu" mbaddr="0x01" mbfunc="0x04" mbreg="0x01" rs="1" rtuVType="F2" precision="45">
<consumers>
<consumer name="TestProc" type="objects" cfilter="test1"/>
<consumer name="PLCProcessor" type="objects"/>
......
bin_PROGRAMS = @PACKAGE@-rtuexchange mtrconv rtustate
bin_PROGRAMS = @PACKAGE@-rtuexchange mtrconv rtustate vtconv
lib_LTLIBRARIES = libUniSetRTU.la
libUniSetRTU_la_LIBADD = $(top_builddir)/lib/libUniSet.la \
......@@ -19,6 +19,10 @@ mtrconv_SOURCES = mtrconv.cc
mtrconv_LDADD = $(top_builddir)/extentions/lib/libUniSetExtentions.la $(top_builddir)/lib/libUniSet.la
mtrconv_CXXFLAGS = -I$(top_builddir)/extentions/include
vtconv_SOURCES = vtconv.cc
vtconv_LDADD = $(top_builddir)/extentions/lib/libUniSetExtentions.la $(top_builddir)/lib/libUniSet.la
vtconv_CXXFLAGS = -I$(top_builddir)/extentions/include
rtustate_LDADD = libUniSetRTU.la $(top_builddir)/extentions/lib/libUniSetExtentions.la $(top_builddir)/lib/libUniSet.la
rtustate__CXXFLAGS = -I$(top_builddir)/extentions/include
rtustate_SOURCES = rtustate.cc
......
......@@ -399,12 +399,17 @@ void RTUExchange::poll()
if( it->devtype == dtRTU )
val = pollRTU(it);
else if( it->devtype == dtMTR )
{
val = pollMTR(it);
IOBase::processingAsAI( ib, val, shm, force );
}
else if( it->devtype == dtRTU188 )
{
val = pollRTU188(it);
IOBase::processingAsAI( ib, val, shm, force );
}
else
continue;
IOBase::processingAsAI( ib, val, shm, force );
}
else if( it->stype == UniversalIO::DigitalInput )
{
......@@ -433,7 +438,9 @@ void RTUExchange::poll()
switch(it->mbfunc)
{
case fnWriteOutputSingleRegister:
{
WriteSingleOutputRetMessage ret = mb->write06( it->mbaddr,it->mbreg,d);
}
break;
case fnWriteOutputRegisters:
......@@ -495,6 +502,9 @@ long RTUExchange::pollRTU( RSMap::iterator& p )
<< " mbaddr=" << ModbusRTU::addr2str(p->mbaddr)
<< " mbreg=" << ModbusRTU::dat2str(p->mbreg)
<< " mbfunc=" << p->mbfunc
<< " rnum=" << p->rnum
<< " vtype=" << p->vType
<< " rnum=" << p->rnum
<< endl;
}
......@@ -502,14 +512,33 @@ long RTUExchange::pollRTU( RSMap::iterator& p )
{
case ModbusRTU::fnReadInputRegisters:
{
ModbusRTU::ReadInputRetMessage ret = mb->read04(p->mbaddr,p->mbreg,1);
return ret.data[0];
ModbusRTU::ReadInputRetMessage ret = mb->read04(p->mbaddr,p->mbreg,p->rnum);
if( p->vType == VTypes::vtUnknown )
{
IOBase::processingAsAI( &(*p), ret.data[0], shm, force );
return ret.data[0];
}
if( p->vType == VTypes::vtF2 )
{
VTypes::F2 f(ret.data, sizeof(ret.data));
cerr << "****** float v=" << (float)f << endl;
IOBase::processingFasAI( &(*p), f, shm, force );
return 0;
}
if( p->vType == VTypes::vtF4 )
{
VTypes::F4 f(ret.data, sizeof(ret.data));
IOBase::processingFasAI( &(*p), f, shm, force );
return 0;
}
}
break;
case ModbusRTU::fnReadOutputRegisters:
{
ModbusRTU::ReadOutputRetMessage ret = mb->read03(p->mbaddr, p->mbreg, 1);
ModbusRTU::ReadOutputRetMessage ret = mb->read03(p->mbaddr, p->mbreg, p->rnum);
return ret.data[0];
}
break;
......@@ -1054,6 +1083,28 @@ bool RTUExchange::initRTUitem( UniXML_iterator& it, RSProperty& p )
p.nbit = UniSetTypes::uni_atoi(nb.c_str());
}
string vt(it.getProp("rtuVType"));
if( vt.empty() )
{
p.rnum = VTypes::wsize(VTypes::vtUnknown);
p.vType = VTypes::vtUnknown;
}
else
{
VTypes::VType v(VTypes::str2type(vt));
if( v == VTypes::vtUnknown )
{
dlog[Debug::CRIT] << myname << "(readRTUItem): Unknown rtuVType=" << vt << " for "
<< it.getProp("name")
<< endl;
return false;
}
p.vType = v;
p.rnum = VTypes::wsize(v);
}
return true;
}
// ------------------------------------------------------------------------------------------
......@@ -1208,7 +1259,7 @@ std::ostream& operator<<( std::ostream& os, const RTUExchange::DeviceType& dt )
break;
default:
os << "Unknown device type";
os << "Unknown device type (" << (int)dt << ")";
break;
}
......
......@@ -19,6 +19,7 @@
#include "MTR.h"
#include "RTUStorage.h"
#include "IOBase.h"
#include "VTypes.h"
// -----------------------------------------------------------------------------
class RTUExchange:
public UniSetObject_LT
......@@ -51,7 +52,6 @@ class RTUExchange:
friend std::ostream& operator<<( std::ostream& os, const DeviceType& dt );
struct RSProperty:
public IOBase
{
......@@ -60,8 +60,11 @@ class RTUExchange:
ModbusRTU::ModbusData mbreg; /*!< */
ModbusRTU::SlaveFunctionCode mbfunc; /*!< / */
// only for RTU
short nbit; /*!< bit number (for func=[0x01,0x02]) */
short nbit; /*!< bit number (for func=[0x01,0x02]) */
VTypes::VType vType; /*!< type of value */
short rnum; /*!< count of registers */
// only for MTR
MTR::MTRType mtrType; /*!< ( MTR) */
......@@ -74,7 +77,9 @@ class RTUExchange:
RSProperty():
devtype(dtUnknown),
mbaddr(0),mbreg(0),mbfunc(ModbusRTU::fnUnknown),
nbit(-1),rtu(0),rtuJack(RTUStorage::nUnknown),rtuChan(0)
nbit(-1),vType(VTypes::vtUnknown),
rnum(VTypes::wsize(VTypes::vtUnknown)),
rtu(0),rtuJack(RTUStorage::nUnknown),rtuChan(0)
{}
friend std::ostream& operator<<( std::ostream& os, RSProperty& p );
......
// --------------------------------------------------------------------------
//! \version $Id: mtrconv.cc,v 1.2 2009/01/22 02:11:23 vpashka Exp $
// --------------------------------------------------------------------------
#include <iostream>
#include <iomanip>
#include "UniSetTypes.h"
#include "VTypes.h"
// --------------------------------------------------------------------------
using namespace std;
using namespace VTypes;
// --------------------------------------------------------------------------
static void print_help()
{
printf("Usage: vtconv TYPE[F2|F4] hex1 hex2 [hex3 hex4]\n");
}
// --------------------------------------------------------------------------
int main( int argc, char **argv )
{
VTypes::F2 f2;
f2.raw.val = 2.345;
cout << "Example(F2): float=" << f2.raw.val
<< " regs:"
<< " v[0]=" << f2.raw.v[0]
<< " v[1]=" << f2.raw.v[1]
<< endl;
VTypes::F4 f4;
f4.raw.val = 2.345123123;
cout << "Example(F4): float=" << f4.raw.val
<< " regs:"
<< " v[0]=" << f4.raw.v[0]
<< " v[1]=" << f4.raw.v[1]
<< " v[2]=" << f4.raw.v[2]
<< " v[3]=" << f4.raw.v[3]
<< endl;
cout << "-------------" << endl << endl;
// return 0;
unsigned short v[4];
memset(v,0,sizeof(v));
char* type="";
if( argc<3 )
{
print_help();
return 1;
}
type = argv[1];
v[0] = UniSetTypes::uni_atoi(argv[2]);
if( argc>3 )
v[1] = UniSetTypes::uni_atoi(argv[3]);
if( argc>4 )
v[2] = UniSetTypes::uni_atoi(argv[4]);
if( argc>5 )
v[3] = UniSetTypes::uni_atoi(argv[5]);
if( !strcmp(type,"F2") )
{
VTypes::F2 f(v,sizeof(v));
cout << "(F2): v[0]=" << v[0]
<< " v[1]=" << v[1]
<< " --> (float) " << (float)f << endl;
}
else if( !strcmp(type,"F4") )
{
VTypes::F4 f(v,sizeof(v));
cout << "(F4): v[0]=" << v[0]
<< " v[1]=" << v[1]
<< " v[2]=" << v[2]
<< " v[3]=" << v[3]
<< " --> (float) " << (float)f << endl;
}
else
{
cout << " Unknown type: " << type << endl;
}
return 0;
}
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
//! \version $Id: RTUTypes.h,v 1.1 2008/12/14 21:57:50 vpashka Exp $
// --------------------------------------------------------------------------
#ifndef _RTUTypes_H_
#define _RTUTypes_H_
// -----------------------------------------------------------------------------
#include <string>
#include <cmath>
#include <cstring>
#include <ostream>
#include "modbus/ModbusTypes.h"
// -----------------------------------------------------------------------------
namespace VTypes
{
enum VType
{
vtUnknown,
vtF2,
vtF4
};
std::ostream& operator<<( std::ostream& os, const VType& vt );
// -------------------------------------------------------------------------
std::string type2str( VType t ); /*!< */
VType str2type( const std::string s ); /*!< */
int wsize( VType t ); /*!< */
// -------------------------------------------------------------------------
class F2
{
public:
// ------------------------------------------
static const int f2Size=2;
/*! */
typedef union
{
unsigned short v[f2Size];
float val; //
} F2mem;
// ------------------------------------------
// ...
F2(){ memset(raw.v,0,sizeof(raw.v)); }
F2( const ModbusRTU::ModbusData* data, int size )
{
for( int i=0; i<wsize() && i<size; i++ )
raw.v[i] = data[i];
}
~F2(){}
// ------------------------------------------
/*! */
static int wsize(){ return f2Size; }
/*! */
static VType type(){ return vtF2; }
// ------------------------------------------
operator float(){ return raw.val; }
operator long(){ return lroundf(raw.val); }
F2mem raw;
};
// --------------------------------------------------------------------------
class F4
{
public:
// ------------------------------------------
static const int f4Size=4;
/*! */
typedef union
{
unsigned short v[f4Size];
float val; //
} F4mem;
// ------------------------------------------
// ...
F4(){ memset(raw.v,0,sizeof(raw.v)); }
F4( const ModbusRTU::ModbusData* data, int size )
{
for( int i=0; i<wsize() && i<size; i++ )
raw.v[i] = data[i];
}
~F4(){}
// ------------------------------------------
/*! */
static int wsize(){ return f4Size; }
/*! */
static VType type(){ return vtF4; }
// ------------------------------------------
operator float(){ return raw.val; }
operator long(){ return lroundf(raw.val); }
F4mem raw;
};
// --------------------------------------------------------------------------
} // end of namespace VTypes
// --------------------------------------------------------------------------
#endif // _RTUTypes_H_
// -----------------------------------------------------------------------------
// --------------------------------------------------------------------------
//! \version $Id: VType.cc,v 1.1 2008/12/14 21:57:50 vpashka Exp $
// --------------------------------------------------------------------------
#include <cmath>
#include "VTypes.h"
// --------------------------------------------------------------------------
using namespace std;
// --------------------------------------------------------------------------
namespace VTypes
{
std::ostream& operator<<( std::ostream& os, const VType& vt )
{
return os << type2str(vt);
}
VType str2type( const std::string s )
{
if( s == "F2" )
return vtF2;
if( s == "F4" )
return vtF4;
return vtUnknown;
}
// -------------------------------------------------------------------------
string type2str( VType t )
{
if( t == vtF2 )
return "F2";
if( t == vtF4 )
return "F4";
return "vtUnknown";
}
// -------------------------------------------------------------------------
int wsize( VType t )
{
if( t == vtF2 )
return F2::wsize();
if( t == vtF4 )
return F4::wsize();
return 0;
}
// -----------------------------------------------------------------------------
} // end of namespace VTypes
// -----------------------------------------------------------------------------
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