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
2c15e774
Commit
2c15e774
authored
Jul 09, 2010
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Сделал новый режим для ModbusSlave: "отвечать на любой адрес"
parent
575753cb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
3 deletions
+18
-3
MBTCPServer.h
Utilities/MBTester/MBTCPServer.h
+2
-0
mbtcpserver.cc
Utilities/MBTester/mbtcpserver.cc
+10
-2
ModbusServer.h
include/modbus/ModbusServer.h
+4
-0
ModbusServer.cc
src/Communications/Modbus/ModbusServer.cc
+2
-1
No files found.
Utilities/MBTester/MBTCPServer.h
View file @
2c15e774
...
...
@@ -20,6 +20,8 @@ class MBTCPServer
verbose
=
state
;
}
inline
void
setAnyAddressMode
(
bool
set
){
if
(
sslot
)
sslot
->
setAnyAddressMode
(
set
);
}
void
execute
();
/*!< основной цикл работы */
...
...
Utilities/MBTester/mbtcpserver.cc
View file @
2c15e774
...
...
@@ -16,6 +16,7 @@ static struct option longopts[] = {
{
"verbose"
,
no_argument
,
0
,
'v'
},
{
"myaddr"
,
required_argument
,
0
,
'a'
},
{
"port"
,
required_argument
,
0
,
'p'
},
{
"any-address"
,
no_argument
,
0
,
'b'
},
{
NULL
,
0
,
0
,
0
}
};
// --------------------------------------------------------------------------
...
...
@@ -27,6 +28,7 @@ static void print_help()
printf
(
"[-i|--iaddr] ip - Server listen ip. Default 127.0.0.1
\n
"
);
printf
(
"[-a|--myaddr] addr - Modbus address for master. Default: 0x01.
\n
"
);
printf
(
"[-p|--port] port - Server port. Default: 502.
\n
"
);
printf
(
"[-b|--any-address] - Respond for any RTU address. Ignore [--myaddr|-a]
\n
"
);
printf
(
"[-v|--verbose] - Print all messages to stdout
\n
"
);
}
// --------------------------------------------------------------------------
...
...
@@ -36,6 +38,7 @@ int main( int argc, char **argv )
int
opt
=
0
;
int
verb
=
0
;
int
port
=
502
;
int
anyaddr
=
0
;
string
iaddr
(
"127.0.0.1"
);
ModbusRTU
::
ModbusAddr
myaddr
=
0x01
;
int
tout
=
2000
;
...
...
@@ -45,7 +48,7 @@ int main( int argc, char **argv )
try
{
while
(
(
opt
=
getopt_long
(
argc
,
argv
,
"ht:va:p:i:"
,
longopts
,
&
optindex
))
!=
-
1
)
while
(
(
opt
=
getopt_long
(
argc
,
argv
,
"ht:va:p:i:
b
"
,
longopts
,
&
optindex
))
!=
-
1
)
{
switch
(
opt
)
{
...
...
@@ -72,6 +75,10 @@ int main( int argc, char **argv )
case
'v'
:
verb
=
1
;
break
;
case
'b'
:
anyaddr
=
1
;
break
;
case
'?'
:
default:
...
...
@@ -83,7 +90,7 @@ int main( int argc, char **argv )
if
(
verb
)
{
cout
<<
"(init): iaddr: "
<<
iaddr
<<
":"
<<
port
<<
" myaddr="
<<
ModbusRTU
::
addr2str
(
myaddr
)
<<
" myaddr="
<<
(
anyaddr
?
"'any'"
:
ModbusRTU
::
addr2str
(
myaddr
)
)
<<
" timeout="
<<
tout
<<
" msec "
<<
endl
;
...
...
@@ -93,6 +100,7 @@ int main( int argc, char **argv )
MBTCPServer
mbs
(
myaddr
,
iaddr
,
port
,
verb
);
mbs
.
setLog
(
dlog
);
mbs
.
setVerbose
(
verb
);
mbs
.
setAnyAddressMode
(
anyaddr
);
mbs
.
execute
();
}
catch
(
ModbusRTU
::
mbException
&
ex
)
...
...
include/modbus/ModbusServer.h
View file @
2c15e774
...
...
@@ -49,6 +49,9 @@ class ModbusServer
inline
void
setBroadcastMode
(
bool
set
){
onBroadcast
=
set
;
}
inline
bool
getBroadcastMode
(){
return
onBroadcast
;
}
inline
void
setAnyAddressMode
(
bool
set
){
anyAddr
=
set
;
}
inline
bool
getAnyAddressMode
(){
return
anyAddr
;
}
/*! Вспомогательная функция реализующая обработку запроса на установку времени.
Основана на использовании gettimeofday и settimeofday.
...
...
@@ -202,6 +205,7 @@ class ModbusServer
timeout_t
replyTimeout_ms
;
/*!< таймаут на формирование ответа */
timeout_t
aftersend_msec
;
/*!< пауза после посылки ответа */
bool
onBroadcast
;
/*!< включен режим работы с broadcst-сообщениями */
bool
anyAddr
;
/*!< режим обработки запросов на любой адрес устройства */
bool
crcNoCheckit
;
void
printProcessingTime
();
...
...
src/Communications/Modbus/ModbusServer.cc
View file @
2c15e774
...
...
@@ -18,6 +18,7 @@ ModbusServer::ModbusServer():
replyTimeout_ms
(
2000
),
aftersend_msec
(
0
),
onBroadcast
(
false
),
anyAddr
(
false
),
crcNoCheckit
(
false
)
{
tmProcessing
.
setTiming
(
replyTimeout_ms
);
...
...
@@ -470,7 +471,7 @@ mbErrCode ModbusServer::recv( ModbusRTU::ModbusAddr addr, ModbusMessage& rbuf, t
while
(
!
tmAbort
.
checkTime
()
)
{
bcnt
=
getNextData
((
unsigned
char
*
)(
&
rbuf
),
sizeof
(
ModbusAddr
));
if
(
bcnt
>
0
&&
(
rbuf
.
addr
==
addr
||
(
onBroadcast
&&
rbuf
.
addr
==
BroadcastAddr
)
)
)
if
(
bcnt
>
0
&&
(
rbuf
.
addr
==
addr
||
anyAddr
||
(
onBroadcast
&&
rbuf
.
addr
==
BroadcastAddr
)
)
)
{
begin
=
true
;
break
;
...
...
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