@@ -50,7 +50,7 @@ class VectorBus(BusABC):
5050
5151 def __init__ (self , channel , can_filters = None , poll_interval = 0.01 ,
5252 receive_own_messages = False ,
53- 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 ):
53+ 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 ):
5454 """
5555 :param list channel:
5656 The channel indexes to create this bus with.
@@ -66,6 +66,10 @@ def __init__(self, channel, can_filters=None, poll_interval=0.01,
6666 :param str app_name:
6767 Name of application in Hardware Config.
6868 If set to None, the channel should be a global channel index.
69+ :param int serial:
70+ Serial number of the hardware to be used.
71+ If set, the channel parameter refers to the channels ONLY on the specified hardware.
72+ If set, the app_name is unused.
6973 :param bool fd:
7074 If CAN-FD frames should be supported.
7175 :param int data_bitrate:
@@ -86,13 +90,30 @@ def __init__(self, channel, can_filters=None, poll_interval=0.01,
8690 self .channel_info = 'Application %s: %s' % (
8791 app_name , ', ' .join ('CAN %d' % (ch + 1 ) for ch in self .channels ))
8892
93+ if serial is not None :
94+ app_name = None
95+ channel_index = []
96+ channel_configs = get_channel_configs ()
97+ for channel_config in channel_configs :
98+ if channel_config .serialNumber == serial :
99+ if channel_config .hwChannel in self .channels :
100+ channel_index .append (channel_config .channelIndex )
101+ if len (channel_index ) > 0 :
102+ if len (channel_index ) != len (self .channels ):
103+ LOG .info ("At least one defined channel wasn't found on the specified hardware." )
104+ self .channels = channel_index
105+ else :
106+ # Is there any better way to raise the error?
107+ raise Exception ("None of the configured channels could be found on the specified hardware." )
108+
89109 vxlapi .xlOpenDriver ()
90110 self .port_handle = vxlapi .XLportHandle (vxlapi .XL_INVALID_PORTHANDLE )
91111 self .mask = 0
92112 self .fd = fd
93113 # Get channels masks
94114 self .channel_masks = {}
95115 self .index_to_channel = {}
116+
96117 for channel in self .channels :
97118 if app_name :
98119 # Get global channel index from application channel
@@ -363,22 +384,25 @@ def reset(self):
363384 @staticmethod
364385 def _detect_available_configs ():
365386 configs = []
366- if vxlapi is None :
367- return configs
368- driver_config = vxlapi .XLdriverConfig ()
369- try :
370- vxlapi .xlOpenDriver ()
371- vxlapi .xlGetDriverConfig (driver_config )
372- vxlapi .xlCloseDriver ()
373- except :
374- pass
375- LOG .info ('Found %d channels' , driver_config .channelCount )
376- for i in range (driver_config .channelCount ):
377- channel_config = driver_config .channel [i ]
387+ channel_configs = get_channel_configs ()
388+ LOG .info ('Found %d channels' , len (channel_configs ))
389+ for channel_config in channel_configs :
378390 LOG .info ('Channel index %d: %s' ,
379391 channel_config .channelIndex ,
380392 channel_config .name .decode ('ascii' ))
381393 configs .append ({'interface' : 'vector' ,
382394 'app_name' : None ,
383395 'channel' : channel_config .channelIndex })
384396 return configs
397+
398+ def get_channel_configs ():
399+ if vxlapi is None :
400+ return []
401+ driver_config = vxlapi .XLdriverConfig ()
402+ try :
403+ vxlapi .xlOpenDriver ()
404+ vxlapi .xlGetDriverConfig (driver_config )
405+ vxlapi .xlCloseDriver ()
406+ except :
407+ pass
408+ return [driver_config .channel [i ] for i in range (driver_config .channelCount )]
0 commit comments