iotile.core.hw.hwmanager

This file contains necessary functionality to manage the hardware

Module Contents

class HardwareManager(port=None, record=None, adapter=None)

A module for managing and interacting with IOTile Hardware

This context provides tools to configure, control, debug and program any IOTile module. Specific functionality can be implemented in dynamically loaded proxy objects that are designed to provide access to each IOTile.

To create a HardwareManager, you need to pass a port string that describes the method to be used to connect to the IOTile device. The method should specify the name of the connection method optionally followed by a colon and any extra information possibly needed to connect using that method.

Currently implemented ports are: (eventually auto-detect this)
none bled112 jlink jlink:mux=ftdi virtual:…(e.g. simple)
Currently implemented devices are: (eventually auto-detect this too)

nrf52 lpc824

if using the mux then append ;channel=[7..0] to the device (e.g. –device=”nrf52;channel=0”)

logger
_setup_proxies(self)

Load in proxy module objects for all of the registered components on this system.

_setup_apps(self)

Load in all iotile app objects for all registered or installed components on this system.

get(self, address, basic=False, force=None, uuid=None)

Create a proxy object for a tile by address.

The correct proxy object is determined by asking the tile for its status information and looking up the appropriate proxy in our list of installed proxy objects. If you want to send raw RPCs, you can get a basic TileBusProxyObject by passing basic=True.

app(self, name=None, path=None, uuid=None)

Find the best IOTileApp for the device we are connected to.

Apps are matched by looking at the app tag and version information specified by the connected device. If no installed app matches, an exception will be thrown. You can also force the matching of a specific app by using the name parameter.

Args:

name (str): Optional name of the app that you wish to load. path (str): Optional path to a python file containing the

app that you wish to load.
uuid (int): Optional uuid of device to directly connect to.
Passing this parameter is equivalent to calling connect before calling this method
Returns:
IOTileApp show-as context: The IOTileApp class that was loaded
for this device.
controller(self, uuid=None)

Find an attached IOTile controller and attempt to connect to it.

connect(self, device_uuid, wait=None)

Attempt to connect to a device by its UUID

connect_direct(self, connection_string)

Attempt to connect to a device using a connection string

disconnect(self)

Attempt to disconnect from a device

debug(self, connection_string=None)

Prepare the device for debugging if supported.

Some transport mechanisms support a low level debug channel that permits recovery and test operations such as erasing and forcibly reprogramming a device or dumping memory.

No debug operations are supported, this function will raise an exception.

heartbeat(self)

Check whether the underlying command stream is functional

enable_broadcasting(self)

Enable the collection of broadcast IOTile reports.

Broadcast reports contain tagged readings from an IOTile device but are sent without a connection to that device. The specific method that is used to broadcast the report varies by connection technology but it could be, e.g., a bluetooth low energy advertising packet.

By default all broadcast reports are dropped unless you call enable_broadcasting to allocate a queue to receive them.

There does not need to be an active connection for you to call enable_broadcasting.

Once you call enable_broadcasting, it remains in effect for the duration of this HardwareManager object.

enable_streaming(self)

Enable streaming of report data from the connected device.

This function will create an internal queue to receive and store reports until the user looks at them and then inform the connected IOTile device that is should begin streaming data.

This is done by telling the underlying DeviceAdapter managing the communication with the device that it should open the device’s streaming interface.

There is currently no way to close the streaming interface except by disconnecting from the device and then reconnecting to it.

enable_tracing(self)

Enable tracing of realtime debug information over this interface

count_reports(self)

Return the current size of the reports queue

watch_broadcasts(self, whitelist=None, blacklist=None)

Spawn an interactive terminal UI to watch broadcast data from devices.

Devices are allowed to post a broadcast report containing stream data. This function will create a list in your console window with the latest broadcast value from each device in range.

Args:

whitelist (list(integer)): Only include devices with these listed ids. blacklist (list(integer)): Include every device except those with these

specific ids. If combined with whitelist, whitelist wins and this parameter has no effect.
watch_scan(self, whitelist=None, blacklist=None, sort='id')

Spawn an interactive terminal UI to watch scan results.

This is just a fancy way of calling scan() repeatedly and deduplicating results per device so that each one has a static place on the screen.

You can decide how you want to order the results with the sort parameter.

If you pick “id”, the default, then results will have a largely static order based on the UUID of each device so that there will not be too much screen churn.

Args:

whitelist (list(integer)): Only include devices with these listed ids. blacklist (list(integer)): Include every device except those with these

specific ids. If combined with whitelist, whitelist wins and this parameter has no effect.
sort (str): The specific way to sort the list on the screen. Options are
id, signal. Defaults to id.
watch_reports(self, whitelist=None, blacklist=None)

Spawn an interactive terminal UI to watch reports once connected to a device.

Args:

whitelist (list(integer)): Only include streams with these listed ids. blacklist (list(integer)): Include every stream except those with these

specific ids. If combined with whitelist, whitelist wins and this parameter has no effect.
dump_trace(self, encoding)

Dump all received tracing data currently received from the device to stdout

The data is encoded per the encoding parmeter which must be either the string ‘hex’ or ‘raw’. If hex is passed, the data is printed as hex digits, if raw is passed, the data is printed as received from the device.

wait_trace(self, size, timeout=None, drop_before=False, progress_callback=None)

Wait for a specific amount of tracing data to be received.

This function is the equivalent of wait_reports for streaming data. It allows you to block until a specific amount of tracing data has been received. The optional timeout parameter allows you to stop waiting if you never receive enough tracing data after a specific amount of time.

Args:

size (int): The number of bytes to wait for. timeout (float): The maximum number of seconds to wait for

these bytes to be received.
drop_before (bool): Truncate all data received until now
before waiting for size bytes.
progress_callback (callable): An optional progress callback that
is called periodically with updates. It should have the signature progress_callback(received_byte_count, total_byte_count)
Returns:
bytearray: The raw trace data obtained.
_accumulate_trace(self)

Copy tracing data from trace queue into _trace_data

iter_broadcast_reports(self, blocking=False)

Iterate over broadcast reports that have been received.

This function is designed to allow the creation of dispatch or processing systems that process broadcast reports as they come in.

Args:
blocking (bool): Whether to stop when there are no more readings or
block and wait for more.
wait_broadcast_reports(self, num_reports, timeout=2.0)

Wait until a specific number of broadcast reports have been received.

Args:

num_reports (int): The number of reports to wait for timeout (float): The maximum number of seconds to wait without

receiving another report.
iter_reports(self, blocking=False)

Iterate over reports that have been received.

If blocking is True, this iterator will never stop. Otherwise it will iterate over all reports currently in the queue (and those added during iteration)

Args:
blocking (bool): Whether to stop when there are no more readings or
block and wait for more.
wait_reports(self, num_reports, timeout=2.0)

Wait for a fixed number of reports to be received

Args:

num_reports (int): The number of reports to wait for timeout (float): The maximum number of seconds to wait without

receiving another report.
reset(self)

Attempt to reset the underlying stream back to a known state

__enter__(self)
__exit__(self, exc_type, exc_value, traceback)
close(self)

Close the current AdapterStream

scan(self, wait=None, sort=None, reverse=False, limit=None)

Scan for available devices and print a dictionary of information about them.

If wait is specified as a floating point number in seconds, then the default wait times configured inside of the stream or device adapter used to find IOTile devices is overridden with the value specified.

Args:
wait (float): An optional override time to wait for results to accumulate before returning sort (string): An optional key to sort by reverse (bool): An optional key that will reverse the sort from ascending to descending limit (integer): An optional limit to the number of devices to return
get_proxy(self, short_name)

Find a proxy type given its short name.

If no proxy type is found, return None.

_create_proxy(self, proxy, address)

Create a python proxy object to talk to an IOTile module with the given type at the given address.

_create_stream(self, force_adapter=None)