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
a4868787
Commit
a4868787
authored
Jul 10, 2010
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
добавил ключ для управления "постоянством" соединения
parent
6b0202c6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
4 deletions
+23
-4
mbtcptester.cc
Utilities/MBTester/mbtcptester.cc
+23
-4
No files found.
Utilities/MBTester/mbtcptester.cc
View file @
a4868787
...
@@ -23,6 +23,7 @@ static struct option longopts[] = {
...
@@ -23,6 +23,7 @@ static struct option longopts[] = {
{
"verbose"
,
no_argument
,
0
,
'v'
},
{
"verbose"
,
no_argument
,
0
,
'v'
},
{
"myaddr"
,
required_argument
,
0
,
'a'
},
{
"myaddr"
,
required_argument
,
0
,
'a'
},
{
"port"
,
required_argument
,
0
,
'p'
},
{
"port"
,
required_argument
,
0
,
'p'
},
{
"persistent-connection"
,
no_argument
,
0
,
'o'
},
{
NULL
,
0
,
0
,
0
}
{
NULL
,
0
,
0
,
0
}
};
};
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
...
@@ -41,6 +42,7 @@ static void print_help()
...
@@ -41,6 +42,7 @@ static void print_help()
printf
(
"[-a|--myaddr] addr - Modbus address for master. Default: 0x01.
\n
"
);
printf
(
"[-a|--myaddr] addr - Modbus address for master. Default: 0x01.
\n
"
);
printf
(
"[-p|--port] port - Modbus server port. Default: 502.
\n
"
);
printf
(
"[-p|--port] port - Modbus server port. Default: 502.
\n
"
);
printf
(
"[-t|--timeout] msec - Timeout. Default: 2000.
\n
"
);
printf
(
"[-t|--timeout] msec - Timeout. Default: 2000.
\n
"
);
printf
(
"[-o|--persistent-connection] - Use persistent-connection.
\n
"
);
printf
(
"[-v|--verbose] - Print all messages to stdout
\n
"
);
printf
(
"[-v|--verbose] - Print all messages to stdout
\n
"
);
}
}
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
...
@@ -64,6 +66,7 @@ int main( int argc, char **argv )
...
@@ -64,6 +66,7 @@ int main( int argc, char **argv )
int
optindex
=
0
;
int
optindex
=
0
;
int
opt
=
0
;
int
opt
=
0
;
int
verb
=
0
;
int
verb
=
0
;
bool
persist
=
false
;
string
iaddr
(
"127.0.0.1"
);
string
iaddr
(
"127.0.0.1"
);
int
port
=
502
;
int
port
=
502
;
ModbusRTU
::
ModbusData
reg
=
0
;
ModbusRTU
::
ModbusData
reg
=
0
;
...
@@ -76,7 +79,7 @@ int main( int argc, char **argv )
...
@@ -76,7 +79,7 @@ int main( int argc, char **argv )
try
try
{
{
while
(
(
opt
=
getopt_long
(
argc
,
argv
,
"hva:w:z:r:x:c:b:d:s:t:p:i:"
,
longopts
,
&
optindex
))
!=
-
1
)
while
(
(
opt
=
getopt_long
(
argc
,
argv
,
"hva:w:z:r:x:c:b:d:s:t:p:i:
o
"
,
longopts
,
&
optindex
))
!=
-
1
)
{
{
switch
(
opt
)
switch
(
opt
)
{
{
...
@@ -166,6 +169,10 @@ int main( int argc, char **argv )
...
@@ -166,6 +169,10 @@ int main( int argc, char **argv )
verb
=
1
;
verb
=
1
;
break
;
break
;
case
'o'
:
persist
=
true
;
break
;
case
'?'
:
case
'?'
:
default:
default:
printf
(
"? argumnet
\n
"
);
printf
(
"? argumnet
\n
"
);
...
@@ -176,7 +183,7 @@ int main( int argc, char **argv )
...
@@ -176,7 +183,7 @@ int main( int argc, char **argv )
if
(
verb
)
if
(
verb
)
{
{
cout
<<
"(init): ip="
<<
iaddr
<<
":"
<<
port
cout
<<
"(init): ip="
<<
iaddr
<<
":"
<<
port
<<
" myaddr="
<<
ModbusRTU
::
addr2str
(
myaddr
)
<<
ModbusRTU
::
addr2str
(
myaddr
)
<<
" timeout="
<<
tout
<<
" msec "
<<
" timeout="
<<
tout
<<
" msec "
<<
endl
;
<<
endl
;
...
@@ -190,13 +197,17 @@ int main( int argc, char **argv )
...
@@ -190,13 +197,17 @@ int main( int argc, char **argv )
ost
::
InetAddress
ia
(
iaddr
.
c_str
());
ost
::
InetAddress
ia
(
iaddr
.
c_str
());
mb
.
setTimeout
(
tout
);
mb
.
setTimeout
(
tout
);
mb
.
connect
(
ia
,
port
);
mb
.
connect
(
ia
,
port
);
mb
.
setForceDisconnect
(
!
persist
);
mb
.
setForceDisconnect
(
true
);
if
(
verb
)
if
(
verb
)
cout
<<
"connection: "
<<
(
mb
.
isConnection
()
?
"YES"
:
"NO"
)
<<
endl
;
cout
<<
"connection: "
<<
(
mb
.
isConnection
()
?
"YES"
:
"NO"
)
<<
endl
;
while
(
1
)
while
(
1
)
{
{
try
{
switch
(
cmd
)
switch
(
cmd
)
{
{
case
cmdRead01
:
case
cmdRead01
:
...
@@ -372,6 +383,14 @@ int main( int argc, char **argv )
...
@@ -372,6 +383,14 @@ int main( int argc, char **argv )
cerr
<<
"No command. Use -h for help."
<<
endl
;
cerr
<<
"No command. Use -h for help."
<<
endl
;
return
1
;
return
1
;
}
}
}
catch
(
ModbusRTU
::
mbException
&
ex
)
{
if
(
ex
.
err
!=
ModbusRTU
::
erTimeOut
)
throw
ex
;
cout
<<
"timeout..."
<<
endl
;
}
msleep
(
200
);
msleep
(
200
);
}
// end of while
}
// end of while
...
...
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