Skip to content

Select vector hardware by serial number - #387

Merged
christiansandberg merged 6 commits into
hardbyte:developfrom
AntonioCohimbra:Vector_HW_serialNumber
Aug 13, 2018
Merged

christiansandberg merged 6 commits into
hardbyte:developfrom
AntonioCohimbra:Vector_HW_serialNumber

Conversation

@AntonioCohimbra

Copy link
Copy Markdown
Contributor

No description provided.

@codecov

codecov Bot commented Aug 9, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #387 into develop will decrease coverage by 0.09%.
The diff coverage is 22.22%.

@@            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 christiansandberg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Python code that is not directly from the vxlapi should follow PEP-8 standard. So for example serialNumber should be serial_number.

Comment thread can/interfaces/vector/canlib.py Outdated
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):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use serial as that is used in the ICS NeoVI implementation already.

Comment thread can/interfaces/vector/canlib.py Outdated
app_name = None
globalChannel = []
hwSpecificChannel = 0
hardwareConfigs = self._detect_available_configs()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread can/interfaces/vector/canlib.py Outdated
if hardwareConfig['serialNumber'] == serialNumber:
if hwSpecificChannel in self.channels:
globalChannel.append(hardwareConfig['channel'])
hwSpecificChannel = hwSpecificChannel + 1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread can/interfaces/vector/canlib.py Outdated
'app_name': None,
'channel': channel_config.channelIndex})
'channel': channel_config.channelIndex,
'serialNumber': channel_config.serialNumber})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@felixdivo felixdivo changed the title select vector hardware by serial number Select vector hardware by serial number Aug 9, 2018
@felixdivo felixdivo added this to the 2.3 Release milestone Aug 9, 2018
Comment thread can/interfaces/vector/canlib.py Outdated
vxlapi.xlCloseDriver()
except:
pass
return driver_config.channel, driver_config.channelCount

@christiansandberg christiansandberg Aug 9, 2018 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that one!

Comment thread can/interfaces/vector/canlib.py Outdated
if serial is not None:
app_name = None
channel_index = []
channel_configs, channel_count = get_channel_configs()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe ValueError? Should be changed in #356 anyway.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So may I leave it as it is for now?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or change to CanError as that is what most other interfaces will raise (or a subclass of it).

Comment thread can/interfaces/vector/canlib.py Outdated
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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change channel_count to len(channel_configs) (or remove line since it does not provide additional information).

Comment thread can/interfaces/vector/canlib.py Outdated

def get_channel_configs():
if vxlapi is None:
return [], 0

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just [].

@christiansandberg
christiansandberg merged commit 7acf9fd into hardbyte:develop Aug 13, 2018
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.

3 participants