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
c2ece263
Commit
c2ece263
authored
Dec 03, 2011
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(Utilities): реализовал в mbrtuslave-echo возможность указывать
несколько слов данных (3) для использования в качестве ответа.
parent
f3c0af54
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
13 deletions
+66
-13
MBSlave.cc
Utilities/MBTester/MBSlave.cc
+27
-4
MBSlave.h
Utilities/MBTester/MBSlave.h
+10
-0
mbrtuslave.cc
Utilities/MBTester/mbrtuslave.cc
+28
-8
mbrtutester.cc
Utilities/MBTester/mbrtutester.cc
+1
-1
No files found.
Utilities/MBTester/MBSlave.cc
View file @
c2ece263
...
@@ -16,7 +16,9 @@ MBSlave::MBSlave( ModbusRTU::ModbusAddr addr, const std::string dev, const std::
...
@@ -16,7 +16,9 @@ MBSlave::MBSlave( ModbusRTU::ModbusAddr addr, const std::string dev, const std::
// prev(ModbusRTU::erNoError),
// prev(ModbusRTU::erNoError),
// askCount(0),
// askCount(0),
verbose
(
false
),
verbose
(
false
),
replyVal
(
-
1
)
replyVal
(
-
1
),
replyVal2
(
-
1
),
replyVal3
(
-
1
)
{
{
// int replyTimeout = uni_atoi( conf->getArgParam("--reply-timeout",it.getProp("reply_timeout")).c_str() );
// int replyTimeout = uni_atoi( conf->getArgParam("--reply-timeout",it.getProp("reply_timeout")).c_str() );
// if( replyTimeout <= 0 )
// if( replyTimeout <= 0 )
...
@@ -153,7 +155,14 @@ ModbusRTU::mbErrCode MBSlave::readInputStatus( ReadInputStatusMessage& query,
...
@@ -153,7 +155,14 @@ ModbusRTU::mbErrCode MBSlave::readInputStatus( ReadInputStatusMessage& query,
bcnt
++
;
bcnt
++
;
for
(
int
i
=
0
;
i
<
bcnt
;
i
++
)
for
(
int
i
=
0
;
i
<
bcnt
;
i
++
)
reply
.
addData
(
replyVal
);
{
if
(
i
==
1
)
reply
.
addData
(
replyVal2
);
else
if
(
i
==
2
)
reply
.
addData
(
replyVal3
);
else
reply
.
addData
(
replyVal
);
}
}
}
return
ModbusRTU
::
erNoError
;
return
ModbusRTU
::
erNoError
;
...
@@ -180,7 +189,14 @@ mbErrCode MBSlave::readInputRegisters( ReadInputMessage& query,
...
@@ -180,7 +189,14 @@ mbErrCode MBSlave::readInputRegisters( ReadInputMessage& query,
for
(
;
num
<
query
.
count
;
num
++
,
reg
++
)
for
(
;
num
<
query
.
count
;
num
++
,
reg
++
)
{
{
if
(
replyVal
!=
-
1
)
if
(
replyVal
!=
-
1
)
reply
.
addData
(
replyVal
);
{
if
(
num
==
1
&&
replyVal2
!=
-
1
)
reply
.
addData
(
replyVal2
);
else
if
(
num
==
2
&&
replyVal3
!=
-
1
)
reply
.
addData
(
replyVal3
);
else
reply
.
addData
(
replyVal
);
}
else
else
reply
.
addData
(
reg
);
reply
.
addData
(
reg
);
}
}
...
@@ -217,7 +233,14 @@ ModbusRTU::mbErrCode MBSlave::readOutputRegisters(
...
@@ -217,7 +233,14 @@ ModbusRTU::mbErrCode MBSlave::readOutputRegisters(
for
(
;
num
<
query
.
count
;
num
++
,
reg
++
)
for
(
;
num
<
query
.
count
;
num
++
,
reg
++
)
{
{
if
(
replyVal
!=
-
1
)
if
(
replyVal
!=
-
1
)
reply
.
addData
(
replyVal
);
{
if
(
num
==
1
&&
replyVal2
!=
-
1
)
reply
.
addData
(
replyVal2
);
else
if
(
num
==
2
&&
replyVal3
!=
-
1
)
reply
.
addData
(
replyVal3
);
else
reply
.
addData
(
replyVal
);
}
else
else
reply
.
addData
(
reg
);
reply
.
addData
(
reg
);
}
}
...
...
Utilities/MBTester/MBSlave.h
View file @
c2ece263
...
@@ -23,6 +23,14 @@ class MBSlave
...
@@ -23,6 +23,14 @@ class MBSlave
{
{
replyVal
=
val
;
replyVal
=
val
;
}
}
inline
void
setReply2
(
long
val
)
{
replyVal2
=
val
;
}
inline
void
setReply3
(
long
val
)
{
replyVal3
=
val
;
}
void
execute
();
/*!< основной цикл работы */
void
execute
();
/*!< основной цикл работы */
...
@@ -103,6 +111,8 @@ class MBSlave
...
@@ -103,6 +111,8 @@ class MBSlave
FileList flist;
FileList flist;
#endif
#endif
long
replyVal
;
long
replyVal
;
long
replyVal2
;
long
replyVal3
;
private
:
private
:
};
};
...
...
Utilities/MBTester/mbrtuslave.cc
View file @
c2ece263
...
@@ -22,16 +22,18 @@ static struct option longopts[] = {
...
@@ -22,16 +22,18 @@ static struct option longopts[] = {
static
void
print_help
()
static
void
print_help
()
{
{
printf
(
"-h|--help - this message
\n
"
);
printf
(
"-h|--help - this message
\n
"
);
printf
(
"[-t|--timeout] msec - Timeout. Default: 2000.
\n
"
);
printf
(
"[-t|--timeout] msec
- Timeout. Default: 2000.
\n
"
);
printf
(
"[-v|--verbose] - Print all messages to stdout
\n
"
);
printf
(
"[-v|--verbose]
- Print all messages to stdout
\n
"
);
printf
(
"[-d|--device] dev - use device dev. Default: /dev/ttyS0
\n
"
);
printf
(
"[-d|--device] dev
- use device dev. Default: /dev/ttyS0
\n
"
);
printf
(
"[-a|--myaddr] addr - Modbus address for master. Default: 0x01.
\n
"
);
printf
(
"[-a|--myaddr] addr
- Modbus address for master. Default: 0x01.
\n
"
);
printf
(
"[-s|--speed] speed - 9600,14400,19200,38400,57600,115200. Default: 38400.
\n
"
);
printf
(
"[-s|--speed] speed
- 9600,14400,19200,38400,57600,115200. Default: 38400.
\n
"
);
printf
(
"[-y|--use485F] - use RS485 Fastwel.
\n
"
);
printf
(
"[-y|--use485F]
- use RS485 Fastwel.
\n
"
);
printf
(
"[-v|--verbose] - Print all messages to stdout
\n
"
);
printf
(
"[-v|--verbose]
- Print all messages to stdout
\n
"
);
printf
(
"[-c|--const-reply] val
- Reply val for all queries
\n
"
);
printf
(
"[-c|--const-reply] val
1 [val2 val3] - Reply val for all queries
\n
"
);
}
}
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
static
char
*
checkArg
(
int
ind
,
int
argc
,
char
*
argv
[]
);
// --------------------------------------------------------------------------
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
int
optindex
=
0
;
int
optindex
=
0
;
...
@@ -44,6 +46,8 @@ int main( int argc, char **argv )
...
@@ -44,6 +46,8 @@ int main( int argc, char **argv )
DebugStream
dlog
;
DebugStream
dlog
;
int
use485
=
0
;
int
use485
=
0
;
int
replyVal
=-
1
;
int
replyVal
=-
1
;
int
replyVal2
=-
1
;
int
replyVal3
=-
1
;
try
try
{
{
...
@@ -81,6 +85,10 @@ int main( int argc, char **argv )
...
@@ -81,6 +85,10 @@ int main( int argc, char **argv )
case
'c'
:
case
'c'
:
replyVal
=
uni_atoi
(
optarg
);
replyVal
=
uni_atoi
(
optarg
);
if
(
checkArg
(
optind
,
argc
,
argv
)
)
replyVal2
=
uni_atoi
(
argv
[
optind
]);
if
(
checkArg
(
optind
+
1
,
argc
,
argv
)
)
replyVal3
=
uni_atoi
(
argv
[
optind
+
1
]);
break
;
break
;
case
'?'
:
case
'?'
:
...
@@ -105,6 +113,10 @@ int main( int argc, char **argv )
...
@@ -105,6 +113,10 @@ int main( int argc, char **argv )
mbs
.
setVerbose
(
verb
);
mbs
.
setVerbose
(
verb
);
if
(
replyVal
!=-
1
)
if
(
replyVal
!=-
1
)
mbs
.
setReply
(
replyVal
);
mbs
.
setReply
(
replyVal
);
if
(
replyVal2
!=-
1
)
mbs
.
setReply2
(
replyVal2
);
if
(
replyVal3
!=-
1
)
mbs
.
setReply3
(
replyVal3
);
mbs
.
execute
();
mbs
.
execute
();
}
}
catch
(
ModbusRTU
::
mbException
&
ex
)
catch
(
ModbusRTU
::
mbException
&
ex
)
...
@@ -127,3 +139,11 @@ int main( int argc, char **argv )
...
@@ -127,3 +139,11 @@ int main( int argc, char **argv )
return
0
;
return
0
;
}
}
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
char
*
checkArg
(
int
i
,
int
argc
,
char
*
argv
[]
)
{
if
(
i
<
argc
&&
(
argv
[
i
])[
0
]
!=
'-'
)
return
argv
[
i
];
return
0
;
}
// --------------------------------------------------------------------------
Utilities/MBTester/mbrtutester.cc
View file @
c2ece263
...
@@ -148,7 +148,7 @@ int main( int argc, char **argv )
...
@@ -148,7 +148,7 @@ int main( int argc, char **argv )
reg
=
ModbusRTU
::
str2mbData
(
argv
[
optind
]);
reg
=
ModbusRTU
::
str2mbData
(
argv
[
optind
]);
if
(
checkArg
(
optind
+
1
,
argc
,
argv
)
)
if
(
checkArg
(
optind
+
1
,
argc
,
argv
)
)
dat
=
uni_atoi
(
argv
[
optind
+
1
]);
count
=
ModbusRTU
::
str2mbData
(
argv
[
optind
+
1
]);
break
;
break
;
case
'o'
:
case
'o'
:
...
...
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