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
56a7d293
Commit
56a7d293
authored
Nov 26, 2011
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(Modbus): Исправил ошибку (сдвиг не единицу) в обработке количества возвращаемых…
(Modbus): Исправил ошибку (сдвиг не единицу) в обработке количества возвращаемых байтов в функции 0x02
parent
6d54e50b
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
33 deletions
+41
-33
MBSlave.cc
Utilities/MBTester/MBSlave.cc
+14
-4
MBTCPServer.cc
Utilities/MBTester/MBTCPServer.cc
+16
-23
mbrtutester.cc
Utilities/MBTester/mbrtutester.cc
+2
-2
mbtcptester.cc
Utilities/MBTester/mbtcptester.cc
+2
-2
libuniset.spec
conf/libuniset.spec
+4
-1
MBSlave.cc
extensions/ModbusSlave/MBSlave.cc
+3
-1
No files found.
Utilities/MBTester/MBSlave.cc
View file @
56a7d293
...
@@ -134,16 +134,26 @@ ModbusRTU::mbErrCode MBSlave::readInputStatus( ReadInputStatusMessage& query,
...
@@ -134,16 +134,26 @@ ModbusRTU::mbErrCode MBSlave::readInputStatus( ReadInputStatusMessage& query,
d
.
b
[
3
]
=
1
;
d
.
b
[
3
]
=
1
;
d
.
b
[
7
]
=
1
;
d
.
b
[
7
]
=
1
;
if
(
replyVal
==
-
1
)
{
int
bnum
=
0
;
int
i
=
0
;
while
(
i
<
query
.
count
)
{
reply
.
addData
(
0
);
for
(
int
nbit
=
0
;
nbit
<
BitsPerByte
&&
i
<
query
.
count
;
nbit
++
,
i
++
)
reply
.
setBit
(
bnum
,
nbit
,
d
.
b
[
nbit
]);
bnum
++
;
}
}
else
{
int
bcnt
=
query
.
count
/
ModbusRTU
::
BitsPerByte
;
int
bcnt
=
query
.
count
/
ModbusRTU
::
BitsPerByte
;
if
(
(
query
.
count
%
ModbusRTU
::
BitsPerByte
)
>
0
)
if
(
(
query
.
count
%
ModbusRTU
::
BitsPerByte
)
>
0
)
bcnt
++
;
bcnt
++
;
for
(
int
i
=
0
;
i
<
bcnt
;
i
++
)
for
(
int
i
=
0
;
i
<
bcnt
;
i
++
)
{
if
(
replyVal
!=-
1
)
reply
.
addData
(
replyVal
);
reply
.
addData
(
replyVal
);
else
reply
.
addData
(
d
);
}
}
return
ModbusRTU
::
erNoError
;
return
ModbusRTU
::
erNoError
;
...
...
Utilities/MBTester/MBTCPServer.cc
View file @
56a7d293
...
@@ -148,33 +148,26 @@ ModbusRTU::mbErrCode MBTCPServer::readInputStatus( ReadInputStatusMessage& query
...
@@ -148,33 +148,26 @@ ModbusRTU::mbErrCode MBTCPServer::readInputStatus( ReadInputStatusMessage& query
d
.
b
[
3
]
=
1
;
d
.
b
[
3
]
=
1
;
d
.
b
[
7
]
=
1
;
d
.
b
[
7
]
=
1
;
if
(
replyVal
==
-
1
)
if
(
query
.
count
<=
1
)
{
{
if
(
replyVal
!=-
1
)
int
bnum
=
0
;
reply
.
addData
(
replyVal
);
int
i
=
0
;
else
while
(
i
<
query
.
count
)
reply
.
addData
(
d
);
return
ModbusRTU
::
erNoError
;
}
// Фомирование ответа:
int
num
=
0
;
// добавленное количество данных
ModbusData
reg
=
query
.
start
;
for
(
;
num
<
query
.
count
;
num
++
,
reg
++
)
{
{
if
(
replyVal
!=-
1
)
reply
.
addData
(
0
);
reply
.
addData
(
replyVal
);
for
(
int
nbit
=
0
;
nbit
<
BitsPerByte
&&
i
<
query
.
count
;
nbit
++
,
i
++
)
else
reply
.
setBit
(
bnum
,
nbit
,
d
.
b
[
nbit
]);
reply
.
addData
(
d
)
;
bnum
++
;
}
}
}
// Если мы в начале проверили, что запрос входит в разрешёный диапазон
else
// то теоретически этой ситуации возникнуть не может...
if
(
reply
.
bcnt
<
query
.
count
)
{
{
cerr
<<
"(readInputStatus): Получили меньше чем ожидали. "
int
bcnt
=
query
.
count
/
ModbusRTU
::
BitsPerByte
;
<<
" Запросили "
<<
query
.
count
<<
" получили "
<<
reply
.
bcnt
<<
endl
;
if
(
(
query
.
count
%
ModbusRTU
::
BitsPerByte
)
>
0
)
bcnt
++
;
for
(
int
i
=
0
;
i
<
bcnt
;
i
++
)
reply
.
addData
(
replyVal
);
}
}
return
ModbusRTU
::
erNoError
;
return
ModbusRTU
::
erNoError
;
...
...
Utilities/MBTester/mbrtutester.cc
View file @
56a7d293
...
@@ -379,7 +379,7 @@ int main( int argc, char **argv )
...
@@ -379,7 +379,7 @@ int main( int argc, char **argv )
{
{
ModbusRTU
::
DataBits
b
(
ret
.
data
[
i
]);
ModbusRTU
::
DataBits
b
(
ret
.
data
[
i
]);
cout
<<
i
<<
": ("
<<
ModbusRTU
::
dat2str
(
reg
+
i
)
<<
") = ("
cout
<<
i
<<
": ("
<<
ModbusRTU
::
dat2str
(
reg
+
8
*
i
)
<<
") = ("
<<
ModbusRTU
::
b2str
(
ret
.
data
[
i
])
<<
") "
<<
b
<<
endl
;
<<
ModbusRTU
::
b2str
(
ret
.
data
[
i
])
<<
") "
<<
b
<<
endl
;
}
}
}
}
...
@@ -403,7 +403,7 @@ int main( int argc, char **argv )
...
@@ -403,7 +403,7 @@ int main( int argc, char **argv )
{
{
ModbusRTU
::
DataBits
b
(
ret
.
data
[
i
]);
ModbusRTU
::
DataBits
b
(
ret
.
data
[
i
]);
cout
<<
i
<<
": ("
<<
ModbusRTU
::
dat2str
(
reg
+
i
)
<<
") = ("
cout
<<
i
<<
": ("
<<
ModbusRTU
::
dat2str
(
reg
+
8
*
i
)
<<
") = ("
<<
ModbusRTU
::
b2str
(
ret
.
data
[
i
])
<<
") "
<<
b
<<
endl
;
<<
ModbusRTU
::
b2str
(
ret
.
data
[
i
])
<<
") "
<<
b
<<
endl
;
}
}
}
}
...
...
Utilities/MBTester/mbtcptester.cc
View file @
56a7d293
...
@@ -274,7 +274,7 @@ int main( int argc, char **argv )
...
@@ -274,7 +274,7 @@ int main( int argc, char **argv )
{
{
ModbusRTU
::
DataBits
b
(
ret
.
data
[
i
]);
ModbusRTU
::
DataBits
b
(
ret
.
data
[
i
]);
cout
<<
i
<<
": ("
<<
ModbusRTU
::
dat2str
(
reg
+
i
)
<<
") = ("
cout
<<
i
<<
": ("
<<
ModbusRTU
::
dat2str
(
reg
+
8
*
i
)
<<
") = ("
<<
ModbusRTU
::
b2str
(
ret
.
data
[
i
])
<<
") "
<<
b
<<
endl
;
<<
ModbusRTU
::
b2str
(
ret
.
data
[
i
])
<<
") "
<<
b
<<
endl
;
}
}
}
}
...
@@ -298,7 +298,7 @@ int main( int argc, char **argv )
...
@@ -298,7 +298,7 @@ int main( int argc, char **argv )
{
{
ModbusRTU
::
DataBits
b
(
ret
.
data
[
i
]);
ModbusRTU
::
DataBits
b
(
ret
.
data
[
i
]);
cout
<<
i
<<
": ("
<<
ModbusRTU
::
dat2str
(
reg
+
i
)
<<
") = ("
cout
<<
i
<<
": ("
<<
ModbusRTU
::
dat2str
(
reg
+
8
*
i
)
<<
") = ("
<<
ModbusRTU
::
b2str
(
ret
.
data
[
i
])
<<
") "
<<
b
<<
endl
;
<<
ModbusRTU
::
b2str
(
ret
.
data
[
i
])
<<
") "
<<
b
<<
endl
;
}
}
}
}
...
...
conf/libuniset.spec
View file @
56a7d293
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
Name: libuniset
Name: libuniset
Version: 1.0
Version: 1.0
Release: alt5
5
Release: alt5
6
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++
...
@@ -212,6 +212,9 @@ rm -f %buildroot%_libdir/*.la
...
@@ -212,6 +212,9 @@ rm -f %buildroot%_libdir/*.la
%changelog
%changelog
* Sat Nov 26 2011 Pavel Vainerman <pv@altlinux.ru> 1.0-alt56
- (modbus): fixed bug (again) in ModbusSlave::readInputStatus(0x02)
* Sat Nov 26 2011 Pavel Vainerman <pv@altlinux.ru> 1.0-alt55
* Sat Nov 26 2011 Pavel Vainerman <pv@altlinux.ru> 1.0-alt55
- (modbus): fixed bug in ModbusSlave::readInputStatus(0x02)
- (modbus): fixed bug in ModbusSlave::readInputStatus(0x02)
...
...
extensions/ModbusSlave/MBSlave.cc
View file @
56a7d293
...
@@ -1339,11 +1339,13 @@ ModbusRTU::mbErrCode MBSlave::readInputStatus( ReadInputStatusMessage& query,
...
@@ -1339,11 +1339,13 @@ ModbusRTU::mbErrCode MBSlave::readInputStatus( ReadInputStatusMessage& query,
// Фомирование ответа:
// Фомирование ответа:
much_real_read
(
query
.
start
,
buf
,
query
.
count
);
much_real_read
(
query
.
start
,
buf
,
query
.
count
);
int
bnum
=
0
;
int
bnum
=
0
;
for
(
int
i
=
0
;
i
<
query
.
count
;
i
++
,
bnum
++
)
int
i
=
0
;
while
(
i
<
query
.
count
)
{
{
reply
.
addData
(
0
);
reply
.
addData
(
0
);
for
(
int
nbit
=
0
;
nbit
<
BitsPerByte
&&
i
<
query
.
count
;
nbit
++
,
i
++
)
for
(
int
nbit
=
0
;
nbit
<
BitsPerByte
&&
i
<
query
.
count
;
nbit
++
,
i
++
)
reply
.
setBit
(
bnum
,
nbit
,
buf
[
i
]);
reply
.
setBit
(
bnum
,
nbit
,
buf
[
i
]);
bnum
++
;
}
}
pingOK
=
true
;
pingOK
=
true
;
...
...
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