Skip to content

Commit f1ef1c7

Browse files
committed
examples: add auto-baudrate test example
1 parent 0d1459d commit f1ef1c7

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

examples/autoBaudrate.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python
2+
3+
#simplePingExample.py
4+
from brping import Ping1D
5+
import time
6+
import argparse
7+
8+
from builtins import input
9+
10+
##Parse Command line options
11+
############################
12+
13+
parser = argparse.ArgumentParser(description="Ping python library example.")
14+
parser.add_argument('--device', action="store", required=True, type=str, help="Ping device port.")
15+
args = parser.parse_args()
16+
17+
#Make a new Ping
18+
myPing = Ping1D(args.device)
19+
20+
baudrates = [9600, 115200]
21+
22+
while (True):
23+
for baudrate in baudrates:
24+
if not myPing.initialize(baudrate):
25+
print("failed to initialize at %d bps", baudrate)
26+
exit(1)
27+
print("ok")
28+
time.sleep(0.01)

0 commit comments

Comments
 (0)