예제 #1
0
    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()
예제 #2
0
 def setUpClass(self):
     ics.override_library_name(r"icsneo40-legacy.dll")
     if _DEBUG:
         import os
         input("Pause... " + str(os.getpid()))