More detailed instructions can be found on the GitHub page.
Getting Started Guide
Imports
Once the library is installed, the Omniscan450 and definitions modules can be imported like this:
from brping import Omniscan450from brping import definitions
Omniscan450 contains the relevant class and methods for controlling the device. definitions contains packet definitions needed for sending and receiving packets.
Initialization
An Omniscan450 object can be created with the Omniscan450 class.
The Omniscan450 class allows for logging to the SonarView log file format. Logging can be enabled and log directory can be set during initialization. (Note: When no log directory is specified, it defaults to ../logs/omniscan )
Typically, Omniscan communication happens through TCP which requires an IP address and port number. The default IP address for the Omniscan is 192.168.2.92 and the port number is 51200 . Both connect_tcp() and connect_udp() expect a string IP address and an integer port number. TCP is recommended.
The last step in initializing the Omniscan 450 is to call the initialize() method. This method will request a device information packet and set up logging if it's enabled. It returns True if a response packet is returned or False otherwise.
Controlling The Device
The Omniscan450 object contains several methods related to controlling and processing data. To set Omniscan 450 parameters, the device needs an os_ping_params packet as described here. The methods titled control_<message_name> will send the device a packet. Each of the parameters in os_ping_params contains a default value that can be changed by assigning that variable.
The Omniscan450 class also contains several static methods that allow for related data calculations.
To calculate the milliseconds per ping from a ping rate:
To calculate the pulse length percent from a percent value:
Receiving Packets
Packets are received through the wait_message() method. While packets can be requested through the get_os_mono_profile() method, this is not the recommended way as the Omniscan 450 will continually send packets after pinging is enabled.
wait_message() returns a PingMessage object, which has the payload fields as its attributes. The payload fields are defined here. For example, to access the ping_number field the corresponding attribute can be accessed like so:
To continually receive packets from the Omniscan 450, a while True block can be used. The try/except blocks allow for the loop to keep going until the user enters CTRL-C.
The os_mono_profile packet contains power data that is scaled to fit into 16 bit values. The Omniscan class contains a method for converting this data to dB values:
Elements of this list can be accessed with normal list operations:
To stop pinging on the Omniscan:
Logging
The Omniscan450 class provides methods to start and stop logging. Logging occurs after wait_message() receives a message. To enable logging, use:
The start_logging() method takes two optional parameters:
new_log
If True, creates a new .svlog file
If False, appends to the most recent .svlog file created by that Omniscan450 instance
log_directory
A string that specifies the path of a directory where the log file will be saved. Defaults to the instance's configured log directory.
To stop logging, use:
Example Code
The full example is provided below and can be run like this:
The GitHub repository contains a more detailed example which demonstrates more features like command-line arguments, signal handlers, and replaying from .svlog files.
ip = "192.168.2.92"
port = 51200
myOS450.connect_tcp(ip, port)
if myOS450.initialize() is False:
exit(1)
myOS450.control_os_ping_params(
start_mm=0,
length_mm=5000, # Set range to 5m
msec_per_ping=my_msec_per_ping,
pulse_len_percent=my_pulse_length,
gain_index=-1, # Auto gain
enable=1 # Enable pinging
)
ping_rate = 10 # 10 pings per second
my_msec_per_ping = Omniscan450.calc_msec_per_ping(ping_rate)