Commit ee470b31 authored by Pavel Vaynerman's avatar Pavel Vaynerman

fixed bug in MTR

parent a1850448
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
Name: libuniset Name: libuniset
Version: 0.96 Version: 0.96
Release: eter50 Release: eter52
Summary: UniSet - library for building distributed industrial control systems Summary: UniSet - library for building distributed industrial control systems
License: GPL License: GPL
Group: Development/C++ Group: Development/C++
...@@ -175,6 +175,9 @@ rm -f %buildroot%_libdir/*.la ...@@ -175,6 +175,9 @@ rm -f %buildroot%_libdir/*.la
%exclude %_pkgconfigdir/libUniSet.pc %exclude %_pkgconfigdir/libUniSet.pc
%changelog %changelog
* Fri Aug 21 2009 Pavel Vainerman <pv@etersoft.ru> 0.96-eter51
- minor fixes in RTUExchange
* Wed Aug 19 2009 Pavel Vainerman <pv@etersoft.ru> 0.96-eter50 * Wed Aug 19 2009 Pavel Vainerman <pv@etersoft.ru> 0.96-eter50
- fixed bug in IOControl (blink mechanic) - fixed bug in IOControl (blink mechanic)
......
...@@ -36,18 +36,18 @@ namespace MTR ...@@ -36,18 +36,18 @@ namespace MTR
int wsize( MTRType t ); /*!< */ int wsize( MTRType t ); /*!< */
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// //
const ModbusRTU::ModbusData regModelNumber = 30001; const ModbusRTU::ModbusData regModelNumber = 0x01;
const ModbusRTU::ModbusData regSerialNumber = 30009; const ModbusRTU::ModbusData regSerialNumber = 0x09;
std::string getModelNumber( ModbusRTUMaster* mb, ModbusRTU::ModbusAddr addr ); std::string getModelNumber( ModbusRTUMaster* mb, ModbusRTU::ModbusAddr addr );
std::string getSerialNumber( ModbusRTUMaster* mb, ModbusRTU::ModbusAddr addr ); std::string getSerialNumber( ModbusRTUMaster* mb, ModbusRTU::ModbusAddr addr );
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// // ( - read03, - write06)
const ModbusRTU::ModbusData regAddress = 40055; const ModbusRTU::ModbusData regAddress = 55;
const ModbusRTU::ModbusData regBaudRate = 40056; const ModbusRTU::ModbusData regBaudRate = 56;
const ModbusRTU::ModbusData regStopBit = 40057; /* 0 - Stop bit, 1 - Stop bits */ const ModbusRTU::ModbusData regStopBit = 57; /* 0 - Stop bit, 1 - Stop bits */
const ModbusRTU::ModbusData regParity = 40058; const ModbusRTU::ModbusData regParity = 58;
const ModbusRTU::ModbusData regDataBits = 40059; const ModbusRTU::ModbusData regDataBits = 59;
enum mtrBaudRate enum mtrBaudRate
{ {
...@@ -497,7 +497,11 @@ namespace MTR ...@@ -497,7 +497,11 @@ namespace MTR
T_Str16( const ModbusRTU::ReadInputRetMessage& ret ) T_Str16( const ModbusRTU::ReadInputRetMessage& ret )
{ {
char c[16]; char c[16];
memcpy(c,&ret.data,sizeof(c)); ModbusRTU::ModbusData data[8];
for( int i=0; i<8; i++ )
data[i] = ModbusRTU::SWAPSHORT(ret.data[i]);
memcpy(c,&data,sizeof(c));
sval = std::string(c); sval = std::string(c);
} }
...@@ -511,6 +515,7 @@ namespace MTR ...@@ -511,6 +515,7 @@ namespace MTR
std::string sval; std::string sval;
}; };
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
class T_Str8 class T_Str8
{ {
public: public:
...@@ -520,7 +525,10 @@ namespace MTR ...@@ -520,7 +525,10 @@ namespace MTR
T_Str8( const ModbusRTU::ReadInputRetMessage& ret ) T_Str8( const ModbusRTU::ReadInputRetMessage& ret )
{ {
char c[8]; char c[8];
memcpy(c,&ret.data,sizeof(c)); ModbusRTU::ModbusData data[4];
for( int i=0; i<4; i++ )
data[i] = ModbusRTU::SWAPSHORT(ret.data[i]);
memcpy(c,&data,sizeof(c));
sval = std::string(c); sval = std::string(c);
} }
......
...@@ -59,6 +59,8 @@ namespace ModbusRTU ...@@ -59,6 +59,8 @@ namespace ModbusRTU
const unsigned char MBErrMask = 0x80; const unsigned char MBErrMask = 0x80;
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
static unsigned short SWAPSHORT(unsigned short x) { return ((((x)>>8)&0xff)|(((x)<<8)&0xff00)); }
// ---------------------------------------------------------------------
/*! ޣ */ /*! ޣ */
ModbusCRC checkCRC( ModbusByte* start, int len ); ModbusCRC checkCRC( ModbusByte* start, int len );
const int szCRC = sizeof(ModbusCRC); /*!< */ const int szCRC = sizeof(ModbusCRC); /*!< */
......
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
using namespace ModbusRTU; using namespace ModbusRTU;
using namespace std; using namespace std;
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
#define SWAPSHORT(x) ((((x)>>8)&0xff)|(((x)<<8)&0xff00))
// -------------------------------------------------------------------------
#define USE_CRC_TAB 1 // ޣ #define USE_CRC_TAB 1 // ޣ
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// Lav: , . // Lav: , .
......
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