Skip to content

Commit 346600a

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

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

examples/autoBaudrate.py

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

0 commit comments

Comments
 (0)