Commit 4e700a91 authored by Pavel Vainerman's avatar Pavel Vainerman

(mbrtutest): added 'polltime' option

eterbug #13154
parent 277625c0
...@@ -34,6 +34,7 @@ static struct option longopts[] = ...@@ -34,6 +34,7 @@ static struct option longopts[] =
{ "speed", required_argument, 0, 's' }, { "speed", required_argument, 0, 's' },
{ "use485F", no_argument, 0, 'y' }, { "use485F", no_argument, 0, 'y' },
{ "num-cycles", required_argument, 0, 'l' }, { "num-cycles", required_argument, 0, 'l' },
{ "polltime", required_argument, 0, 'p' },
{ NULL, 0, 0, 0 } { NULL, 0, 0, 0 }
}; };
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -67,6 +68,7 @@ static void print_help() ...@@ -67,6 +68,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("[-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("[-t|--timeout] msec - Timeout. Default: 2000.\n"); printf("[-t|--timeout] msec - Timeout. Default: 2000.\n");
printf("[-p|--polltime] msec - Polling time. Default: 200 msec.\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("[-v|--verbose] - Print all messages to stdout\n"); printf("[-v|--verbose] - Print all messages to stdout\n");
} }
...@@ -119,6 +121,7 @@ int main( int argc, char** argv ) ...@@ -119,6 +121,7 @@ int main( int argc, char** argv )
string tofile(""); string tofile("");
int use485 = 0; int use485 = 0;
int ncycles = -1; int ncycles = -1;
int polltime = 200;
ModbusRTU::ModbusByte devID = 0; ModbusRTU::ModbusByte devID = 0;
ModbusRTU::ModbusByte objID = 0; ModbusRTU::ModbusByte objID = 0;
...@@ -126,7 +129,7 @@ int main( int argc, char** argv ) ...@@ -126,7 +129,7 @@ int main( int argc, char** argv )
{ {
while(1) while(1)
{ {
opt = getopt_long(argc, argv, "hva:w:z:m:r:x:c:b:d:s:t:qn:u:yl:t:o:e:", longopts, &optindex); opt = getopt_long(argc, argv, "hva:w:z:m:r:x:c:b:d:s:t:qn:u:yl:t:o:e:p:", longopts, &optindex);
if( opt == -1 ) if( opt == -1 )
break; break;
...@@ -274,6 +277,10 @@ int main( int argc, char** argv ) ...@@ -274,6 +277,10 @@ int main( int argc, char** argv )
tout = uni_atoi(optarg); tout = uni_atoi(optarg);
break; break;
case 'p':
polltime = uni_atoi(optarg);
break;
case 'a': case 'a':
myaddr = ModbusRTU::str2mbAddr(optarg); myaddr = ModbusRTU::str2mbAddr(optarg);
break; break;
...@@ -298,7 +305,7 @@ int main( int argc, char** argv ) ...@@ -298,7 +305,7 @@ int main( int argc, char** argv )
} }
} }
break; break;
#if 0
case 'g': case 'g':
{ {
if( cmd == cmdNOP ) if( cmd == cmdNOP )
...@@ -318,7 +325,7 @@ int main( int argc, char** argv ) ...@@ -318,7 +325,7 @@ int main( int argc, char** argv )
} }
} }
break; break;
#endif
case 'v': case 'v':
verb = 1; verb = 1;
break; break;
...@@ -739,7 +746,7 @@ int main( int argc, char** argv ) ...@@ -739,7 +746,7 @@ int main( int argc, char** argv )
break; break;
} }
msleep(200); msleep(polltime);
} }
} }
catch( ModbusRTU::mbException& ex ) catch( ModbusRTU::mbException& ex )
......
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