Python can.BusABC() Examples

The following are 7 code examples of can.BusABC(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module can , or try the search function .
Example #1
Source File: electronic_control_unit.py    From j1939 with MIT License 6 votes vote down vote up
def connect(self, *args, **kwargs):
        """Connect to CAN bus using python-can.

        Arguments are passed directly to :class:`can.BusABC`. Typically these
        may include:

        :param channel:
            Backend specific channel for the CAN interface.
        :param str bustype:
            Name of the interface. See
            `python-can manual <https://python-can.readthedocs.io/en/latest/configuration.html#interface-names>`__
            for full list of supported interfaces.
        :param int bitrate:
            Bitrate in bit/s.

        :raises can.CanError:
            When connection fails.
        """
        self._bus = can.interface.Bus(*args, **kwargs)
        logger.info("Connected to '%s'", self._bus.channel_info)
        self._notifier = can.Notifier(self._bus, self._listeners, 1) 
Example #2
Source File: network.py    From canopen with MIT License 6 votes vote down vote up
def __init__(self, bus=None):
        """
        :param can.BusABC bus:
            A python-can bus instance to re-use.
        """
        #: A python-can :class:`can.BusABC` instance which is set after
        #: :meth:`canopen.Network.connect` is called
        self.bus = bus
        #: A :class:`~canopen.network.NodeScanner` for detecting nodes
        self.scanner = NodeScanner(self)
        #: List of :class:`can.Listener` objects.
        #: Includes at least MessageListener.
        self.listeners = [MessageListener(self)]
        self.notifier = None
        self.nodes = {}
        self.subscribers = {}
        self.send_lock = threading.Lock()
        self.sync = SyncProducer(self)
        self.time = TimeProducer(self)
        self.nmt = NmtMaster(0)
        self.nmt.network = self

        self.lss = LssMaster()
        self.lss.network = self
        self.subscribe(self.lss.LSS_RX_COBID, self.lss.on_message_received) 
Example #3
Source File: network.py    From canopen with MIT License 6 votes vote down vote up
def __init__(self, can_id, data, period, bus, remote=False):
        """
        :param int can_id:
            CAN-ID of the message
        :param data:
            Data to be transmitted (anything that can be converted to bytes)
        :param float period:
            Seconds between each message
        :param can.BusABC bus:
            python-can bus to use for transmission
        """
        self.bus = bus
        self.period = period
        self.msg = can.Message(is_extended_id=can_id > 0x7FF,
                               arbitration_id=can_id,
                               data=data, is_remote_frame=remote)
        self._task = None
        self._start() 
Example #4
Source File: protocol.py    From python-can-isotp with MIT License 5 votes vote down vote up
def set_bus(self, bus):
        if not isinstance(bus, can.BusABC):
            raise ValueError('bus must be a python-can BusABC object')
        self.bus=bus 
Example #5
Source File: electronic_control_unit.py    From j1939 with MIT License 5 votes vote down vote up
def __init__(self, bus=None):
        """
        :param can.BusABC bus:
            A python-can bus instance to re-use.
        """
        #: A python-can :class:`can.BusABC` instance
        self._bus = bus
        # Locking object for send 
        self._send_lock = threading.Lock()

        #: Includes at least MessageListener.
        self._listeners = [MessageListener(self)]
        self._notifier = None
        self._subscribers = []
        # List of ControllerApplication
        self._cas = []
        # Receive buffers
        self._rcv_buffer = {}
        # Send buffers
        self._snd_buffer = {}
        # List of timer events the job thread should care of
        self._timer_events = []

        self._job_thread_end = threading.Event()
        logger.info("Starting ECU async thread")
        self._job_thread_wakeup_queue = queue.Queue()
        self._job_thread = threading.Thread(target=self._async_job_thread, name='j1939.ecu job_thread')
        # A thread can be flagged as a "daemon thread". The significance of 
        # this flag is that the entire Python program exits when only daemon 
        # threads are left.
        self._job_thread.daemon = True
        self._job_thread.start()
        # TODO: do we have to stop the tread somehow? 
Example #6
Source File: network.py    From canopen with MIT License 5 votes vote down vote up
def connect(self, *args, **kwargs):
        """Connect to CAN bus using python-can.

        Arguments are passed directly to :class:`can.BusABC`. Typically these
        may include:

        :param channel:
            Backend specific channel for the CAN interface.
        :param str bustype:
            Name of the interface. See
            `python-can manual <https://python-can.readthedocs.io/en/latest/configuration.html#interface-names>`__
            for full list of supported interfaces.
        :param int bitrate:
            Bitrate in bit/s.

        :raises can.CanError:
            When connection fails.
        """
        # If bitrate has not been specified, try to find one node where bitrate
        # has been specified
        if "bitrate" not in kwargs:
            for node in self.nodes.values():
                if node.object_dictionary.bitrate:
                    kwargs["bitrate"] = node.object_dictionary.bitrate
                    break
        self.bus = can.interface.Bus(*args, **kwargs)
        logger.info("Connected to '%s'", self.bus.channel_info)
        self.notifier = can.Notifier(self.bus, self.listeners, 1)
        return self 
Example #7
Source File: abstract.py    From can-prog with MIT License 5 votes vote down vote up
def __init__(self, iface):
        if not isinstance(iface, can.BusABC):
            raise TypeError('canbus interface not compatible')
        self._iface = iface