Commit 84d4006e authored by Pavel Vainerman's avatar Pavel Vainerman

(mbtcptest, mtr-read): Добавил параметр --ignore-errors (-g)

для игнорирования ошибок обмена
parent 644292cd
...@@ -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, "hvgna: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; throw;
cout << "timeout..." << endl; cerr << ex << endl;
}
}
catch( std::exception& ex )
{
if( !ignoreErrors )
throw;
cerr << ex.what() << endl;
} }
if( ncycles > 0 ) if( ncycles > 0 )
......
...@@ -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("\nRTU prameters:\n"); printf("\nRTU 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, "hvygq: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; throw;
cout << "timeout..." << endl; cerr << ex << endl;
}
}
catch( std::exception& ex )
{
if( !ignoreErrors )
throw;
cerr << ex.what() << endl;
} }
if( ncycles > 0 ) if( ncycles > 0 )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment