Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
173e6cfc
Commit
173e6cfc
authored
May 18, 2015
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(ModbusSlave): исправление ошибки в функции обработки запроса 0x3
parent
c6477633
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
6 deletions
+31
-6
test.xml
conf/test.xml
+1
-1
MBSlave.cc
extensions/ModbusSlave/MBSlave.cc
+15
-4
test_mbslave.cc
extensions/ModbusSlave/tests/test_mbslave.cc
+15
-1
No files found.
conf/test.xml
View file @
173e6cfc
...
...
@@ -246,7 +246,7 @@
<item
id=
"58"
iotype=
"AO"
name=
"Lamp58_C"
textname=
"Lamp 58"
rrd=
"1"
rrd1_ds=
"GAUGE:20:U:U"
/>
<item
id=
"62"
iotype=
"AI"
name=
"LogLevel_S"
textname=
"LogLevel control"
/>
<item
id=
"63"
iotype=
"AI"
name=
"SVU_AskCount_AS"
textname=
"svu asl count"
/>
<item
id=
"64"
iotype=
"AI"
name=
"AI64_AS"
textname=
"AI64"
mbaddr=
"0x01"
mbfunc=
"0x03"
mbreg=
"64"
mbtype=
"rtu"
rs=
"5"
/>
<item
id=
"64"
iotype=
"AI"
name=
"AI64_AS"
textname=
"AI64"
mbaddr=
"0x01"
mbfunc=
"0x03"
mbreg=
"64"
mbtype=
"rtu"
rs=
"5"
tcp=
"6"
/>
<item
id=
"66"
iotype=
"DI"
name=
"DI66_AS"
textname=
"DI66"
mbaddr=
"0x01"
mbfunc=
"0x01"
mbreg=
"66"
mbtype=
"rtu"
rs=
"5"
/>
<item
id=
"65"
iotype=
"DI"
name=
"D65_S"
textname=
"D65"
threshold_aid=
"AI64_AS"
lowlimit=
"3"
hilimit=
"5"
threshold_invert=
"1"
rs=
"5"
/>
</sensors>
...
...
extensions/ModbusSlave/MBSlave.cc
View file @
173e6cfc
...
...
@@ -85,7 +85,10 @@ MBSlave::MBSlave( UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmId, cons
mbregFromID
=
conf
->
getArgInt
(
"--"
+
prefix
+
"-reg-from-id"
,
it
.
getProp
(
"reg_from_id"
));
checkMBFunc
=
conf
->
getArgInt
(
"--"
+
prefix
+
"-check-mbfunc"
,
it
.
getProp
(
"check_mbfunc"
));
dinfo
<<
myname
<<
"(init): mbregFromID="
<<
mbregFromID
<<
endl
;
dinfo
<<
myname
<<
"(init): mbregFromID="
<<
mbregFromID
<<
" checkMBFunc="
<<
checkMBFunc
<<
" default_mbfunc="
<<
default_mbfunc
<<
endl
;
respond_id
=
conf
->
getSensorID
(
conf
->
getArgParam
(
"--"
+
prefix
+
"-respond-id"
,
it
.
getProp
(
"respond_id"
)));
respond_invert
=
conf
->
getArgInt
(
"--"
+
prefix
+
"-respond-invert"
,
it
.
getProp
(
"respond_invert"
));
...
...
@@ -899,6 +902,9 @@ bool MBSlave::initItem( UniXML::iterator& it )
int
mbfunc
=
IOBase
::
initIntProp
(
it
,
"mbfunc"
,
prop_prefix
,
false
,
default_mbfunc
);
if
(
!
checkMBFunc
)
mbfunc
=
default_mbfunc
;
p
.
regID
=
ModbusRTU
::
genRegID
(
p
.
mbreg
,
mbfunc
);
p
.
amode
=
MBSlave
::
amRW
;
...
...
@@ -1215,7 +1221,7 @@ ModbusRTU::mbErrCode MBSlave::readOutputRegisters( ModbusRTU::ReadOutputMessage&
if
(
query
.
count
<=
1
)
{
ModbusRTU
::
ModbusData
d
=
0
;
ModbusRTU
::
mbErrCode
ret
=
real_read
(
query
.
start
,
d
);
ModbusRTU
::
mbErrCode
ret
=
real_read
(
query
.
start
,
d
,
query
.
func
);
if
(
ret
==
ModbusRTU
::
erNoError
)
reply
.
addData
(
d
);
...
...
@@ -1633,10 +1639,15 @@ ModbusRTU::mbErrCode MBSlave::much_real_read( const ModbusRTU::ModbusData reg, M
// -------------------------------------------------------------------------
ModbusRTU
::
mbErrCode
MBSlave
::
real_read
(
const
ModbusRTU
::
ModbusData
reg
,
ModbusRTU
::
ModbusData
&
val
,
const
int
fn
)
{
ModbusRTU
::
RegID
regID
=
checkMBFunc
?
genRegID
(
reg
,
fn
)
:
genRegID
(
reg
,
default_mbfunc
);
dinfo
<<
myname
<<
"(real_read): read mbID="
<<
ModbusRTU
::
dat2str
(
reg
)
<<
"("
<<
(
int
)
reg
<<
")"
<<
" fn="
<<
fn
<<
endl
;
<<
ModbusRTU
::
dat2str
(
reg
)
<<
"("
<<
(
int
)
reg
<<
")"
<<
" fn="
<<
fn
<<
" regID="
<<
regID
<<
" default_mbfunc="
<<
default_mbfunc
<<
" checkMBFunc="
<<
checkMBFunc
<<
endl
;
ModbusRTU
::
RegID
regID
=
checkMBFunc
?
genRegID
(
reg
,
fn
)
:
genRegID
(
reg
,
default_mbfunc
);
auto
it
=
iomap
.
find
(
regID
);
return
real_read_it
(
it
,
val
);
...
...
extensions/ModbusSlave/tests/test_mbslave.cc
View file @
173e6cfc
...
...
@@ -1049,7 +1049,7 @@ TEST_CASE("read03(04) 10 registers", "[modbus][mbslave][mbtcpslave][readmore]")
ModbusRTU
::
ModbusData
tREG
=
130
;
int
num
=
10
;
SECTION
(
"Test: read03"
)
SECTION
(
"Test: read03
num=10
"
)
{
ModbusRTU
::
ReadOutputRetMessage
ret
=
mb
->
read03
(
slaveaddr
,
tREG
,
num
);
for
(
int
i
=
0
;
i
<
num
;
i
++
)
...
...
@@ -1057,6 +1057,13 @@ TEST_CASE("read03(04) 10 registers", "[modbus][mbslave][mbtcpslave][readmore]")
REQUIRE
(
ret
.
data
[
i
]
==
(
i
+
1
)
);
}
}
SECTION
(
"Test: read03 num=1"
)
{
ModbusRTU
::
ReadOutputRetMessage
ret
=
mb
->
read03
(
slaveaddr
,
tREG
,
1
);
REQUIRE
(
ret
.
data
[
0
]
==
1
);
}
SECTION
(
"Test: read04"
)
{
ModbusRTU
::
ReadInputRetMessage
ret
=
mb
->
read04
(
slaveaddr
,
tREG
,
num
);
...
...
@@ -1065,6 +1072,13 @@ TEST_CASE("read03(04) 10 registers", "[modbus][mbslave][mbtcpslave][readmore]")
REQUIRE
(
ret
.
data
[
i
]
==
(
i
+
1
)
);
}
}
SECTION
(
"Test: read04 num=1"
)
{
ModbusRTU
::
ReadInputRetMessage
ret
=
mb
->
read04
(
slaveaddr
,
tREG
,
1
);
REQUIRE
(
ret
.
data
[
0
]
==
1
);
}
}
// -------------------------------------------------------------
/*! \todo Доделать тесты на считывание с разными prop_prefix.. */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment