UniSet
2.6.0
Титульная страница
Описания
Группы
Пространства имен
Классы
python
lib
pyUniSet
UModbus.h
1
/*
2
* Copyright (c) 2015 Pavel Vainerman.
3
*
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as
6
* published by the Free Software Foundation, version 2.1.
7
*
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
* Lesser General Lesser Public License for more details.
12
*
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15
*/
16
// -------------------------------------------------------------------------
17
#ifndef UModbus_H_
18
#define UModbus_H_
19
// --------------------------------------------------------------------------
20
#include "Configuration.h"
21
#include "UInterface.h"
22
#include "modbus/ModbusTCPMaster.h"
23
#include "modbus/ModbusTypes.h"
24
#include "extensions/VTypes.h"
25
#include "Debug.h"
26
#include "UTypes.h"
27
#include "UExceptions.h"
28
// --------------------------------------------------------------------------
29
class
UModbus
30
{
31
public
:
32
33
UModbus
();
34
~
UModbus
();
35
36
inline
std::string getUIType()
37
{
38
return
string(
"modbus"
);
39
}
40
41
inline
bool
isWriteFunction(
int
mbfunc )
42
{
43
return
uniset::ModbusRTU::isWriteFunction((uniset::ModbusRTU::SlaveFunctionCode)mbfunc);
44
}
45
46
// выставление паметров связи, без установления соединения (!)
47
void
prepare(
const
std::string& ip,
int
port )
throw
(
UException
);
48
49
void
connect(
const
std::string& ip,
int
port )
throw
(
UException
);
50
inline
int
conn_port()
51
{
52
return
port;
53
}
54
inline
std::string conn_ip()
55
{
56
return
ip;
57
}
58
inline
bool
isConnection()
59
{
60
return
(mb && mb->isConnection());
61
}
62
63
inline
void
setTimeout(
int
msec )
64
{
65
tout_msec = msec;
66
}
67
73
long
mbread
(
int
addr,
int
mbreg,
int
mbfunc,
74
const
std::string& vtype,
int
nbit = -1,
75
const
std::string& ip =
""
,
int
port = -1 )
throw
(
UException
);
76
77
long
getWord(
int
addr,
int
mbreg,
int
mbfunc = 0x4 )
throw
(
UException
);
78
long
getByte(
int
addr,
int
mbreg,
int
mbfunc = 0x4 )
throw
(
UException
);
79
bool
getBit(
int
addr,
int
mbreg,
int
mbfunc = 0x2 )
throw
(
UException
);
80
86
void
mbwrite
(
int
addr,
int
mbreg,
int
val,
int
mbfunc,
const
std::string& ip =
""
,
int
port = -1 )
throw
(
UException
);
87
88
protected
:
89
long
data2value( uniset::VTypes::VType vt, uniset::ModbusRTU::ModbusData* data );
90
91
private
:
92
// DebugStream dlog;
93
uniset::ModbusTCPMaster
* mb;
94
int
port;
95
string
ip;
96
int
tout_msec;
97
};
98
//---------------------------------------------------------------------------
99
#endif
100
//---------------------------------------------------------------------------
Документация по UniSet. Последние изменения: Вс 15 Янв 2017 18:59:12. Создано системой
1.8.1.2