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

Adapter enumeration #1180

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

marcel-kanter
Copy link
Contributor

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).

Each interface should provide a means for enumerating all matching adapters. The result should be an list of adapter identifiers. An adapter identifier is not limited or equal to serial number, it can be a place in a device tree (like PCI or USB tree).

The adapter identifier then can be used with the init of the bus/interface.
Add the enumeration functionality and test it. The enumeration is useful to skip tests which rely on connected hardware.
@mergify mergify bot requested a review from hardbyte December 3, 2021 14:46
Create a HRESULT fallback if platform is not win32
Make the method list_adapters a class method correctly
Fix the formatting
@codecov
Copy link

codecov bot commented Dec 3, 2021

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     

@felixdivo
Copy link
Collaborator

felixdivo commented Dec 4, 2021

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

@pierreluctg
Copy link
Collaborator

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

@marcel-kanter
Copy link
Contributor Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants