Discovery¶
Address¶
- class canlib.kvrlib.Address(type, address)[source]¶
An IP or MAC address
- Parameters
type (
AddressType) – Address type.address (
list[int]) – A list of integers, the numbers in the address.
- classmethod from_c(c_addr)[source]¶
Create an
Addressobject from akvrAddressobject
- to_c()[source]¶
Create a
kvrAddressfrom this object
DeviceInfo¶
- class canlib.kvrlib.DeviceInfo(device_info=None)[source]¶
Information about a device that can be written to the registry
See
DeviceInfoSetfor information about how to getDeviceInfoobjects, process them, and then write them to the registry.- property accessibility¶
The accessibility of this device
- Type
- property availability¶
The availability of this device
- Type
- property connect¶
Whether the service should connect to this device
- Type
bool
- property encryption_key¶
The encryption key to use when encrypting communication
Note
This attribute is write-only.
- Type
bytes
- property firmware_version¶
Firmware version
- Type
- property hostname¶
DNS hostname if available, otherwise an empty string
- Type
str
- info()[source]¶
Create a string with information about the
DeviceInfoTo be used when the
str()representation is not detailed enough.
- property name¶
User-defined name of device
- Type
str
- property password¶
The accessibility password to use when connecting to a device
Note
This attribute is write-only.
- Type
str
- property serial¶
The serial number of the device
- Type
int
- property service_status¶
A tuple with the service status of the device
The returned tuple has the format
(state, start_info, text), wherestateis aServiceState,start_infois aStartInfo, andtextis astrwith local connection status.- Type
- property stored¶
Whether this
DeviceInfowas read from the registry- Type
bool
- update(other)[source]¶
Update the attributes of this instance
This function takes a
dict, and will set the attributes given by the keys to the corresponding value (on this object).
- property usage¶
Usage status (Free/Remote/USB/Config)
- Type
Discovery¶
- class canlib.kvrlib.Discovery(handle)[source]¶
A kvrlib “Discovery” process
Most of the time the discovery process can be handled by
discover_info_set, which returns the results of the discovery as aDeviceInfoSet.Even when interacted with directly, instnances of this class are normally not instantiated directly, but created using
start_discovery, or sometimes usingopenDiscovery.Instances of this class can be used as context handlers, in which case the discovery will be closed when the context is exited. The discovery will also be closed when the instance is garbage collected, if it hasn’t already.
- property addresses¶
The list of addresses to use for discovery
Note
This attribute is write-only.
This attribute should be a list of
Addressobjects.If the
Discoveryobject was created bystart_discovery, the addresses are automatically set. Otherwise, they must be assigned beforeDiscovery.startcan be called.
- close()[source]¶
Close the discovery process
This function is called when the
Discoveryobject is garbage-collected.If the
Discoveryobject is used as a context handler, this function will be called when the context exits.
- results()[source]¶
Return an iterator of the result from the discovery
The results are yielded as
DeviceInfoobjects.
- start(delay, timeout, report_stored=True)[source]¶
Run the discovery
If the
Discoveryobject was created bystart_discovery, the discovery has already been run, and this function does not need to be called.After the discovery has been run, its results can be retrieved using
Discovery.results.- Parameters
delay (
int) – The millisecond delay between sending discovery messages to addresses in the address list.timeout (
int) – The millisecond timeout after all discovery messages have been sent, before returning.report_stored (
bool) – ifTrue(the default), stored devices will be discovered.
get_default_discovery_addresses()¶
- canlib.kvrlib.get_default_discovery_addresses(broadcast=True, stored=False)[source]¶
Retrieve the default discovery addresses
- Parameters
broadcast (
bool) – IfTrue(the default), then the returned list will contain broadcast addresses.stored (
bool) – IfTrue(defaults toFalse), then the returned list will contain earlier stored addresses.
If both arguments are
False, aValueErrorwill be raised.Retruns a
listofAddressobjects.
openDiscovery()¶
- canlib.kvrlib.openDiscovery()[source]¶
Creates and returns a
DiscoveryobjectDevice discovery is normally done using
discover_info_set.
ServiceStatus¶
set_clear_stored_devices_on_exit()¶
start_discovery()¶
- canlib.kvrlib.start_discovery(delay, timeout, addresses=None, report_stored=True)[source]¶
Start and return a
DiscoveryDevice discovery is normally done using
discover_info_set.The returned object should usually be used as a context handler:
with kvrlib.start_discovery(delay=100, timeout=1000) as disc: for result in disc.results(): # process the discovery result print(result)
store_devices()¶
- canlib.kvrlib.store_devices(devices)[source]¶
Store a collection of
DeviceInfoobjects in the registrySee
DeviceInfoSetfor a simpler way of dealing with device infos and the registry.Note
Previously stored devices are cleared.
stored_devices()¶
- canlib.kvrlib.stored_devices()[source]¶
Read the devices stored in the registry as a tuple of
DeviceInfoobjects