Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 37 additions & 13 deletions can/interfaces/vector/canlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class VectorBus(BusABC):

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", serial=None, fd=False, data_bitrate=None, sjwAbr=2, tseg1Abr=6, tseg2Abr=3, sjwDbr=2, tseg1Dbr=6, tseg2Dbr=3, **config):
"""
:param list channel:
The channel indexes to create this bus with.
Expand All @@ -66,6 +66,10 @@ def __init__(self, channel, can_filters=None, poll_interval=0.01,
:param str app_name:
Name of application in Hardware Config.
If set to None, the channel should be a global channel index.
:param int serial:
Serial number of the hardware to be used.
If set, the channel parameter refers to the channels ONLY on the specified hardware.
If set, the app_name is unused.
:param bool fd:
If CAN-FD frames should be supported.
:param int data_bitrate:
Expand All @@ -86,13 +90,30 @@ def __init__(self, channel, can_filters=None, poll_interval=0.01,
self.channel_info = 'Application %s: %s' % (
app_name, ', '.join('CAN %d' % (ch + 1) for ch in self.channels))

if serial is not None:
app_name = None
channel_index = []
channel_configs = get_channel_configs()
for channel_config in channel_configs:
if channel_config.serialNumber == serial:
if channel_config.hwChannel in self.channels:
channel_index.append(channel_config.channelIndex)
if len(channel_index) > 0:
if len(channel_index) != len(self.channels):
LOG.info("At least one defined channel wasn't found on the specified hardware.")
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).


vxlapi.xlOpenDriver()
self.port_handle = vxlapi.XLportHandle(vxlapi.XL_INVALID_PORTHANDLE)
self.mask = 0
self.fd = fd
# Get channels masks
self.channel_masks = {}
self.index_to_channel = {}

for channel in self.channels:
if app_name:
# Get global channel index from application channel
Expand Down Expand Up @@ -363,22 +384,25 @@ def reset(self):
@staticmethod
def _detect_available_configs():
configs = []
if vxlapi is None:
return configs
driver_config = vxlapi.XLdriverConfig()
try:
vxlapi.xlOpenDriver()
vxlapi.xlGetDriverConfig(driver_config)
vxlapi.xlCloseDriver()
except:
pass
LOG.info('Found %d channels', driver_config.channelCount)
for i in range(driver_config.channelCount):
channel_config = driver_config.channel[i]
channel_configs = get_channel_configs()
LOG.info('Found %d channels', len(channel_configs))
for channel_config in channel_configs:
LOG.info('Channel index %d: %s',
channel_config.channelIndex,
channel_config.name.decode('ascii'))
configs.append({'interface': 'vector',
'app_name': None,
'channel': channel_config.channelIndex})
return configs

def get_channel_configs():
if vxlapi is None:
return []
driver_config = vxlapi.XLdriverConfig()
try:
vxlapi.xlOpenDriver()
vxlapi.xlGetDriverConfig(driver_config)
vxlapi.xlCloseDriver()
except:
pass
return [driver_config.channel[i] for i in range(driver_config.channelCount)]