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
84d4006e
Commit
84d4006e
authored
Apr 20, 2017
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(mbtcptest, mtr-read): Добавил параметр --ignore-errors (-g)
для игнорирования ошибок обмена
parent
644292cd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
6 deletions
+48
-6
mbtcptester.cc
Utilities/MBTester/mbtcptester.cc
+24
-3
mtr-read.cc
extensions/ModbusMaster/mtr-read.cc
+24
-3
No files found.
Utilities/MBTester/mbtcptester.cc
View file @
84d4006e
...
@@ -31,6 +31,7 @@ static struct option longopts[] =
...
@@ -31,6 +31,7 @@ static struct option longopts[] =
{
"num-cycles"
,
required_argument
,
0
,
'l'
},
{
"num-cycles"
,
required_argument
,
0
,
'l'
},
{
"sleep-msec"
,
required_argument
,
0
,
's'
},
{
"sleep-msec"
,
required_argument
,
0
,
's'
},
{
"check"
,
no_argument
,
0
,
'n'
},
{
"check"
,
no_argument
,
0
,
'n'
},
{
"ignore-errors"
,
no_argument
,
0
,
'g'
},
{
NULL
,
0
,
0
,
0
}
{
NULL
,
0
,
0
,
0
}
};
};
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
...
@@ -62,6 +63,7 @@ static void print_help()
...
@@ -62,6 +63,7 @@ static void print_help()
printf
(
"[-v|--verbose] - Print all messages to stdout
\n
"
);
printf
(
"[-v|--verbose] - Print all messages to stdout
\n
"
);
printf
(
"[-s|--sleep-msec] - send pause. Default: 200 msec
\n
"
);
printf
(
"[-s|--sleep-msec] - send pause. Default: 200 msec
\n
"
);
printf
(
"[-n|--check] - Check connection for (-i)ip (-p)port
\n
"
);
printf
(
"[-n|--check] - Check connection for (-i)ip (-p)port
\n
"
);
printf
(
"[-g|--ignore-errors] - Ignore errors
\n
"
);
}
}
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
enum
Command
enum
Command
...
@@ -95,6 +97,7 @@ int main( int argc, char** argv )
...
@@ -95,6 +97,7 @@ int main( int argc, char** argv )
ModbusRTU
::
ModbusData
reg
=
0
;
ModbusRTU
::
ModbusData
reg
=
0
;
int
val
=
0
;
int
val
=
0
;
int
sleep_msec
=
500
;
int
sleep_msec
=
500
;
bool
ignoreErrors
=
false
;
union
DValue
union
DValue
{
{
...
@@ -124,7 +127,7 @@ int main( int argc, char** argv )
...
@@ -124,7 +127,7 @@ int main( int argc, char** argv )
{
{
while
(
1
)
while
(
1
)
{
{
opt
=
getopt_long
(
argc
,
argv
,
"hvna:w:z:r:x:c:b:d:s:t:p:i:ol:d:e:u:"
,
longopts
,
&
optindex
);
opt
=
getopt_long
(
argc
,
argv
,
"hv
g
na:w:z:r:x:c:b:d:s:t:p:i:ol:d:e:u:"
,
longopts
,
&
optindex
);
if
(
opt
==
-
1
)
if
(
opt
==
-
1
)
break
;
break
;
...
@@ -172,6 +175,10 @@ int main( int argc, char** argv )
...
@@ -172,6 +175,10 @@ int main( int argc, char** argv )
cmd
=
cmdCheck
;
cmd
=
cmdCheck
;
break
;
break
;
case
'g'
:
ignoreErrors
=
true
;
break
;
case
'e'
:
case
'e'
:
{
{
if
(
cmd
==
cmdNOP
)
if
(
cmd
==
cmdNOP
)
...
@@ -685,10 +692,24 @@ int main( int argc, char** argv )
...
@@ -685,10 +692,24 @@ int main( int argc, char** argv )
}
}
catch
(
ModbusRTU
::
mbException
&
ex
)
catch
(
ModbusRTU
::
mbException
&
ex
)
{
{
if
(
ex
.
err
!=
ModbusRTU
::
erTimeOut
)
if
(
ex
.
err
==
ModbusRTU
::
erTimeOut
)
{
cout
<<
"timeout..."
<<
endl
;
}
else
{
if
(
!
ignoreErrors
)
throw
;
cerr
<<
ex
<<
endl
;
}
}
catch
(
std
::
exception
&
ex
)
{
if
(
!
ignoreErrors
)
throw
;
throw
;
c
out
<<
"timeout..."
<<
endl
;
c
err
<<
ex
.
what
()
<<
endl
;
}
}
if
(
ncycles
>
0
)
if
(
ncycles
>
0
)
...
...
extensions/ModbusMaster/mtr-read.cc
View file @
84d4006e
...
@@ -43,6 +43,7 @@ static struct option longopts[] =
...
@@ -43,6 +43,7 @@ static struct option longopts[] =
{
"timeout"
,
required_argument
,
0
,
't'
},
{
"timeout"
,
required_argument
,
0
,
't'
},
{
"iaddr"
,
required_argument
,
0
,
'i'
},
{
"iaddr"
,
required_argument
,
0
,
'i'
},
{
"port"
,
required_argument
,
0
,
'p'
},
{
"port"
,
required_argument
,
0
,
'p'
},
{
"ignore-errors"
,
no_argument
,
0
,
'g'
},
{
NULL
,
0
,
0
,
0
}
{
NULL
,
0
,
0
,
0
}
};
};
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
...
@@ -55,6 +56,7 @@ static void print_help()
...
@@ -55,6 +56,7 @@ static void print_help()
printf
(
"[-n|--read-serial] slaveaddr - read serial number from MTR
\n
"
);
printf
(
"[-n|--read-serial] slaveaddr - read serial number from MTR
\n
"
);
printf
(
"[-t|--timeout] msec - Timeout. Default: 2000.
\n
"
);
printf
(
"[-t|--timeout] msec - Timeout. Default: 2000.
\n
"
);
printf
(
"[-l|--num-cycles] num - Number of cycles of exchange. Default: -1 infinitely.
\n
"
);
printf
(
"[-l|--num-cycles] num - Number of cycles of exchange. Default: -1 infinitely.
\n
"
);
printf
(
"[-g|--ignore-errors] - Ignore errors
\n
"
);
printf
(
"[-v|--verbose] - Print all messages to stdout
\n
"
);
printf
(
"[-v|--verbose] - Print all messages to stdout
\n
"
);
printf
(
"
\n
RTU prameters:
\n
"
);
printf
(
"
\n
RTU prameters:
\n
"
);
printf
(
"[-y|--use485F] - use RS485 Fastwel.
\n
"
);
printf
(
"[-y|--use485F] - use RS485 Fastwel.
\n
"
);
...
@@ -98,12 +100,13 @@ int main( int argc, char** argv )
...
@@ -98,12 +100,13 @@ int main( int argc, char** argv )
MTR
::
MTRType
mtrtype
=
MTR
::
mtUnknown
;
MTR
::
MTRType
mtrtype
=
MTR
::
mtUnknown
;
string
iaddr
(
"127.0.0.1"
);
string
iaddr
(
"127.0.0.1"
);
int
port
=
502
;
int
port
=
502
;
bool
ignoreErrors
=
false
;
try
try
{
{
while
(
1
)
while
(
1
)
{
{
opt
=
getopt_long
(
argc
,
argv
,
"hvyq:r:d:s:t:x:m:n:i:p:"
,
longopts
,
&
optindex
);
opt
=
getopt_long
(
argc
,
argv
,
"hvy
g
q:r:d:s:t:x:m:n:i:p:"
,
longopts
,
&
optindex
);
if
(
opt
==
-
1
)
if
(
opt
==
-
1
)
break
;
break
;
...
@@ -155,6 +158,10 @@ int main( int argc, char** argv )
...
@@ -155,6 +158,10 @@ int main( int argc, char** argv )
}
}
break
;
break
;
case
'g'
:
ignoreErrors
=
true
;
break
;
case
'n'
:
case
'n'
:
{
{
cmd
=
cmdSerial
;
cmd
=
cmdSerial
;
...
@@ -293,10 +300,24 @@ int main( int argc, char** argv )
...
@@ -293,10 +300,24 @@ int main( int argc, char** argv )
}
}
catch
(
ModbusRTU
::
mbException
&
ex
)
catch
(
ModbusRTU
::
mbException
&
ex
)
{
{
if
(
ex
.
err
!=
ModbusRTU
::
erTimeOut
)
if
(
ex
.
err
==
ModbusRTU
::
erTimeOut
)
{
cout
<<
"timeout..."
<<
endl
;
}
else
{
if
(
!
ignoreErrors
)
throw
;
cerr
<<
ex
<<
endl
;
}
}
catch
(
std
::
exception
&
ex
)
{
if
(
!
ignoreErrors
)
throw
;
throw
;
c
out
<<
"timeout..."
<<
endl
;
c
err
<<
ex
.
what
()
<<
endl
;
}
}
if
(
ncycles
>
0
)
if
(
ncycles
>
0
)
...
...
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