def __init__(self, channel, can_filters=None, **config): """ :param int channel: The Channel id to create this bus with. :param list can_filters: See :meth:`can.BusABC.set_filters` for details. :param use_system_timestamp: Use system timestamp for can messages instead of the hardware time stamp :param str serial: Serial to connect (optional, will use the first found if not supplied) :param int bitrate: Channel bitrate in bit/s. (optional, will enable the auto bitrate feature if not supplied) """ if ics is None: raise ImportError('Please install python-ics') super(NeoViBus, self).__init__(channel=channel, can_filters=can_filters, **config) logger.info("CAN Filters: {}".format(can_filters)) logger.info("Got configuration of: {}".format(config)) self._use_system_timestamp = bool( config.get('use_system_timestamp', False)) try: channel = int(channel) except ValueError: raise ValueError('channel must be an integer') type_filter = config.get('type_filter') serial = config.get('serial') self.dev = self._find_device(type_filter, serial) ics.open_device(self.dev) if 'bitrate' in config: ics.set_bit_rate(self.dev, config.get('bitrate'), channel) self.channel_info = '%s %s CH:%s' % ( self.dev.Name, self.get_serial_number(self.dev), channel) logger.info("Using device: {}".format(self.channel_info)) self.rx_buffer = deque() self.network = channel if channel is not None else None
def __init__(self, channel, can_filters=None, **config): """ :param channel: The channel ids to create this bus with. Can also be a single integer, netid name or a comma separated string. :type channel: int or str or list(int) or list(str) :param list can_filters: See :meth:`can.BusABC.set_filters` for details. :param bool use_system_timestamp: Use system timestamp for can messages instead of the hardware time stamp :param str serial: Serial to connect (optional, will use the first found if not supplied) :param int bitrate: Channel bitrate in bit/s. (optional, will enable the auto bitrate feature if not supplied) :param bool fd: If CAN-FD frames should be supported. :param int data_bitrate: Which bitrate to use for data phase in CAN FD. Defaults to arbitration bitrate. """ if ics is None: raise ImportError('Please install python-ics') super(NeoViBus, self).__init__( channel=channel, can_filters=can_filters, **config) logger.info("CAN Filters: {}".format(can_filters)) logger.info("Got configuration of: {}".format(config)) if isinstance(channel, (list, tuple)): self.channels = channel elif isinstance(channel, int): self.channels = [channel] else: # Assume comma separated string of channels self.channels = [ch.strip() for ch in channel.split(',')] self.channels = [NeoViBus.channel_to_netid(ch) for ch in self.channels] type_filter = config.get('type_filter') serial = config.get('serial') self.dev = self._find_device(type_filter, serial) ics.open_device(self.dev) if 'bitrate' in config: for channel in self.channels: ics.set_bit_rate(self.dev, config.get('bitrate'), channel) fd = config.get('fd', False) if fd: if 'data_bitrate' in config: for channel in self.channels: ics.set_fd_bit_rate( self.dev, config.get('data_bitrate'), channel) self._use_system_timestamp = bool( config.get('use_system_timestamp', False) ) self.channel_info = '%s %s CH:%s' % ( self.dev.Name, self.get_serial_number(self.dev), self.channels ) logger.info("Using device: {}".format(self.channel_info)) self.rx_buffer = deque()
def __init__(self, channel, can_filters=None, **kwargs): """ :param channel: The channel ids to create this bus with. Can also be a single integer, netid name or a comma separated string. :type channel: int or str or list(int) or list(str) :param list can_filters: See :meth:`can.BusABC.set_filters` for details. :param bool receive_own_messages: If transmitted messages should also be received by this bus. :param bool use_system_timestamp: Use system timestamp for can messages instead of the hardware time stamp :param str serial: Serial to connect (optional, will use the first found if not supplied) :param int bitrate: Channel bitrate in bit/s. (optional, will enable the auto bitrate feature if not supplied) :param bool fd: If CAN-FD frames should be supported. :param int data_bitrate: Which bitrate to use for data phase in CAN FD. Defaults to arbitration bitrate. :param override_library_name: Absolute path or relative path to the library including filename. """ if ics is None: raise ImportError("Please install python-ics") super().__init__(channel=channel, can_filters=can_filters, **kwargs) logger.info("CAN Filters: {}".format(can_filters)) logger.info("Got configuration of: {}".format(kwargs)) if "override_library_name" in kwargs: ics.override_library_name(kwargs.get("override_library_name")) if isinstance(channel, (list, tuple)): self.channels = channel elif isinstance(channel, int): self.channels = [channel] else: # Assume comma separated string of channels self.channels = [ch.strip() for ch in channel.split(",")] self.channels = [NeoViBus.channel_to_netid(ch) for ch in self.channels] type_filter = kwargs.get("type_filter") serial = kwargs.get("serial") self.dev = self._find_device(type_filter, serial) with open_lock: ics.open_device(self.dev) if "bitrate" in kwargs: for channel in self.channels: ics.set_bit_rate(self.dev, kwargs.get("bitrate"), channel) fd = kwargs.get("fd", False) if fd: if "data_bitrate" in kwargs: for channel in self.channels: ics.set_fd_bit_rate(self.dev, kwargs.get("data_bitrate"), channel) self._use_system_timestamp = bool( kwargs.get("use_system_timestamp", False)) self._receive_own_messages = kwargs.get("receive_own_messages", True) self.channel_info = "%s %s CH:%s" % ( self.dev.Name, self.get_serial_number(self.dev), self.channels, ) logger.info("Using device: {}".format(self.channel_info)) self.rx_buffer = deque()