Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update for abr function #82

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions examples/autoBaudrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python

from brping import Ping1D
import time
import argparse

##Parse Command line options
############################

parser = argparse.ArgumentParser(description="Ping python library example.")
parser.add_argument('--device', action="store", required=True, type=str, help="Ping device port.")
args = parser.parse_args()

#Make a new Ping
myPing = Ping1D(args.device)

baudrates = [9600, 115200]

while (True):
for baudrate in baudrates:
if not myPing.initialize(baudrate):
print("failed to initialize at %d bps", baudrate)
exit(1)
print("ok")
time.sleep(0.01)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will this finish ?

Copy link
Member Author

@jaxxzer jaxxzer Feb 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when you push ctrl + c like ping, or the sensor fails to communicate

13 changes: 11 additions & 2 deletions generate/templates/device.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,19 @@ class PingDevice(object):
return self.iodev.write(data)

##
# @brief Make sure there is a device on and read some initial data
# @brief initialize the device communication interface. A serial break signal
# is sent to the device followed by 'U' (0x55) to begin the autobaurate procedure
# on the device. Some data is then read from the device to verify communications
#
# @param baudrate: the baudrate to use. if None, the baudrate will not
# be changed (default is 115200)
#
# @return True if the device replies with expected data, False otherwise
def initialize(self):
def initialize(self, baudrate=None):
if baudrate is not None:
self.iodev.baudrate = baudrate
self.iodev.send_break()
self.iodev.write("U".encode("utf-8"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that this should be ascii, since it's the U char that we want, and not the utf-8 representation.

Copy link
Member Author

@jaxxzer jaxxzer Feb 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks correct on the wire with a probe (0x55), I will try ascii though

return self.request(definitions.COMMON_PROTOCOL_VERSION) is not None

##
Expand Down
4 changes: 2 additions & 2 deletions generate/templates/ping1d.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class Ping1D(PingDevice):

return self.wait_message([m_id], timeout)

def initialize(self):
if not PingDevice.initialize(self):
def initialize(self, baudrate=None):
if not PingDevice.initialize(self, baudrate):
return False
if self.legacyRequest(definitions.PING1D_GENERAL_INFO) is None:
return False
Expand Down