Repository navigation
Select vector hardware by serial number - #387
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #387 +/- ##
==========================================
- Coverage 59.34% 59.25% -0.1%
==========================================
Files 55 55
Lines 4248 4263 +15
==========================================
+ Hits 2521 2526 +5
- Misses 1727 1737 +10 |
christiansandberg
left a comment
There was a problem hiding this comment.
The Python code that is not directly from the vxlapi should follow PEP-8 standard. So for example serialNumber should be serial_number.
| def __init__(self, channel, can_filters=None, poll_interval=0.01, | ||
| receive_own_messages=False, | ||
| bitrate=None, rx_queue_size=2**14, app_name="CANalyzer", fd=False, data_bitrate=None, sjwAbr=2, tseg1Abr=6, tseg2Abr=3, sjwDbr=2, tseg1Dbr=6, tseg2Dbr=3, **config): | ||
| bitrate=None, rx_queue_size=2**14, app_name="CANalyzer", serialNumber=None, fd=False, data_bitrate=None, sjwAbr=2, tseg1Abr=6, tseg2Abr=3, sjwDbr=2, tseg1Dbr=6, tseg2Dbr=3, **config): |
There was a problem hiding this comment.
Could use serial as that is used in the ICS NeoVI implementation already.
| app_name = None | ||
| globalChannel = [] | ||
| hwSpecificChannel = 0 | ||
| hardwareConfigs = self._detect_available_configs() |
There was a problem hiding this comment.
Perhaps it's best to create a new lower level method which yields XLchannelConfig that can be used by this code and _detect_available_configs(). That way you will have full access to all information.
| if hardwareConfig['serialNumber'] == serialNumber: | ||
| if hwSpecificChannel in self.channels: | ||
| globalChannel.append(hardwareConfig['channel']) | ||
| hwSpecificChannel = hwSpecificChannel + 1 |
There was a problem hiding this comment.
Could be safer to use XLchannelConfig.hwChannel since I don't think it's explicitly stated that the hardware configs will come in a certain order.
| 'app_name': None, | ||
| 'channel': channel_config.channelIndex}) | ||
| 'channel': channel_config.channelIndex, | ||
| 'serialNumber': channel_config.serialNumber}) |
There was a problem hiding this comment.
See my comment above about creating a new method instead of re-using this one.
I've been thinking that it might be a good idea to create a new base class for representing channels in python-can. Then it could contain more useful information like name, article number, serial number etc in a backend independent manner.
| vxlapi.xlCloseDriver() | ||
| except: | ||
| pass | ||
| return driver_config.channel, driver_config.channelCount |
There was a problem hiding this comment.
A nicer way to do this to avoid even more code later is something like return [driver_config.channel[i] for i in range(driver_config.channelCount)]. But it's really a small detail. :)
There was a problem hiding this comment.
I like that one!
| if serial is not None: | ||
| app_name = None | ||
| channel_index = [] | ||
| channel_configs, channel_count = get_channel_configs() |
There was a problem hiding this comment.
Should probably move vxlapi.xlOpenDriver() above to after get_channel_configs() as it calls vxlapi.xlCloseDriver().
| self.channels = channel_index | ||
| else: | ||
| # Is there any better way to raise the error? | ||
| raise Exception("None of the configured channels could be found on the specified hardware.") |
There was a problem hiding this comment.
Maybe ValueError? Should be changed in #356 anyway.
There was a problem hiding this comment.
So may I leave it as it is for now?
There was a problem hiding this comment.
Or change to CanError as that is what most other interfaces will raise (or a subclass of it).
| for i in range(driver_config.channelCount): | ||
| channel_config = driver_config.channel[i] | ||
| channel_configs = get_channel_configs() | ||
| LOG.info('Found %d channels', channel_count) |
There was a problem hiding this comment.
Change channel_count to len(channel_configs) (or remove line since it does not provide additional information).
|
|
||
| def get_channel_configs(): | ||
| if vxlapi is None: | ||
| return [], 0 |
No description provided.