本文整理汇总了Python中can.BusABC方法的典型用法代码示例。如果您正苦于以下问题:Python can.BusABC方法的具体用法?Python can.BusABC怎么用?Python can.BusABC使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类can
的用法示例。
在下文中一共展示了can.BusABC方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connect
# 需要导入模块: import can [as 别名]
# 或者: from can import BusABC [as 别名]
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)
示例2: __init__
# 需要导入模块: import can [as 别名]
# 或者: from can import BusABC [as 别名]
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)
示例3: set_bus
# 需要导入模块: import can [as 别名]
# 或者: from can import BusABC [as 别名]
def set_bus(self, bus):
if not isinstance(bus, can.BusABC):
raise ValueError('bus must be a python-can BusABC object')
self.bus=bus
示例4: __init__
# 需要导入模块: import can [as 别名]
# 或者: from can import BusABC [as 别名]
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?
示例5: connect
# 需要导入模块: import can [as 别名]
# 或者: from can import BusABC [as 别名]
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
示例6: __init__
# 需要导入模块: import can [as 别名]
# 或者: from can import BusABC [as 别名]
def __init__(self, iface):
if not isinstance(iface, can.BusABC):
raise TypeError('canbus interface not compatible')
self._iface = iface