mirror of
https://github.com/wjwwood/serial.git
synced 2026-01-22 19:54:57 +08:00
Updating the example to allow variable bauds
This commit is contained in:
parent
241daf3073
commit
5324caf2a3
@ -7,14 +7,17 @@
|
|||||||
|
|
||||||
int run(int argc, char **argv)
|
int run(int argc, char **argv)
|
||||||
{
|
{
|
||||||
if(argc < 2) {
|
if(argc < 3) {
|
||||||
std::cerr << "Usage: test_serial <serial port address>" << std::endl;
|
std::cerr << "Usage: test_serial <serial port address> <baudrate>" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
std::string port(argv[1]);
|
std::string port(argv[1]);
|
||||||
|
unsigned long baud = 0;
|
||||||
|
|
||||||
|
sscanf(argv[2], "%lu", &baud);
|
||||||
|
|
||||||
// port, baudrate, timeout in milliseconds
|
// port, baudrate, timeout in milliseconds
|
||||||
serial::Serial serial(port, 115200, 250);
|
serial::Serial serial(port, baud, 250);
|
||||||
|
|
||||||
std::cout << "Is the serial port open?";
|
std::cout << "Is the serial port open?";
|
||||||
if(serial.isOpen())
|
if(serial.isOpen())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user