python-can icon indicating copy to clipboard operation
python-can copied to clipboard

Adapter enumeration

Open marcel-kanter opened this issue 4 years ago • 4 comments

First part with the fix of #1179

The basic principle of the adapter enumeration is described in the commit message and here:

In case you have connected multiple IXXAT adapters, you have to select them by using their unique hardware id. To get a list of all connected IXXAT adapters you can use the function list_adapters() as demonstrated below:

>>> from can.interfaces.ixxat import IXXATBus
>>> for hwid in IXXATBus.list_adapters():
...     print("Found IXXAT adapter with hardware id '%s'." % hwid)
Found IXXAT adapter with hardware id 'HW441489'.
Found IXXAT adapter with hardware id 'HW107422'.

The method list_adapters shall return an iterable with adapter identifiers or an empty list. If an driver must be installed, then an exception shall be thrown.

This principle should be rolled out to all other interfaces, because most of the time you deal with one type of interface but more likely with multiple adapters. To unify the interface for creating the busses, the adapter keyword argument should be used. As this does not imply that a serial number exists. For PCI cards the adapter identifier maybe the place in the PCI bus, or for network bridges this might be an arbitraty name which stands for an IP-address and port, etc.

The next step should be an method that returns the capabilities for an adapter. Both methods then can be used to build a dict of all configurations of an interface. The methods in each interface then can be used to build an dict of all configurations of all interfaces (recursively).

marcel-kanter avatar Dec 03 '21 14:12 marcel-kanter

Codecov Report

Merging #1180 (10a8e8e) into develop (998615a) will decrease coverage by 1.35%. The diff coverage is 25.92%.

@@             Coverage Diff             @@
##           develop    #1180      +/-   ##
===========================================
- Coverage    70.95%   69.59%   -1.36%     
===========================================
  Files           79       79              
  Lines         7808     7812       +4     
===========================================
- Hits          5540     5437     -103     
- Misses        2268     2375     +107     

codecov[bot] avatar Dec 03 '21 17:12 codecov[bot]

Just as a note, this will probably conflict with the much older #1119, which I'd recommend merging first. (And there's also #1141)

felixdivo avatar Dec 04 '21 18:12 felixdivo

@marcel-kanter , how is this different from detect_available_configs https://github.com/hardbyte/python-can/blob/develop/can/interface.py#L128?

pierreluctg avatar Dec 09 '21 13:12 pierreluctg

@marcel-kanter , how is this different from detect_available_configs https://github.com/hardbyte/python-can/blob/develop/can/interface.py#L128?

Basically this provides the steps in between and is an attempt to unify the arguments for the bus instantiation. The list of init arguments for defining the adapter:

neovi : serial ixxat : unique_hardware_id kvaser : (channel ?) neousys : device pcan : (channel ?) seedstudio: channel serial: channel socketcan: (channel ?) systec: device_number udp_multicase: channel + port usb2can: channel or serial (serial is declared legacy) vector: app_name ?

(The ones with the question mark are a guess.)

In the end detect_available_configs can needs to enumerate the adapters and needs to find the configurations for each adapter. You can do this in one big step or provide the intermediate steps.

However _detect_available_configs should be without the leading underscore. _detect_available_configs is not implemented for ixxat interface.

marcel-kanter avatar Dec 10 '21 17:12 marcel-kanter