当前位置: 首页>>代码示例>>Python>>正文


Python can.CanError方法代码示例

本文整理汇总了Python中can.CanError方法的典型用法代码示例。如果您正苦于以下问题:Python can.CanError方法的具体用法?Python can.CanError怎么用?Python can.CanError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在can的用法示例。


在下文中一共展示了can.CanError方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: send_data_to_bus

# 需要导入模块: import can [as 别名]
# 或者: from can import CanError [as 别名]
def send_data_to_bus(self, data, config, data_check=True, raise_exception=False):
        try:
            self.__bus.send(Message(arbitration_id=config["nodeId"],
                                    is_extended_id=config.get("isExtendedId", self.DEFAULT_EXTENDED_ID_FLAG),
                                    is_fd=config.get("isFd", self.DEFAULT_FD_FLAG),
                                    bitrate_switch=config.get("bitrateSwitch", self.DEFAULT_BITRATE_SWITCH_FLAG),
                                    data=data,
                                    check=data_check))
            return True
        except (ValueError, TypeError) as e:
            log.error("[%s] Wrong CAN message data: %s", self.get_name(), str(e))
        except CanError as e:
            log.error("[%s] Failed to send CAN message: %s", self.get_name(), str(e))
            if raise_exception:
                raise e
            else:
                self.__on_bus_error(e)
        return False 
开发者ID:thingsboard,项目名称:thingsboard-gateway,代码行数:20,代码来源:can_connector.py

示例2: internal_send

# 需要导入模块: import can [as 别名]
# 或者: from can import CanError [as 别名]
def internal_send(self, sender, msg):
        with self.pool_mutex:
            try:
                t = self.pool[sender.name]
            except KeyError:
                return

            try:
                t.bus.send(msg)
                for sock in t.sockets:
                    if sock != sender and sock._matches_filters(msg):
                        m = copy.copy(msg)
                        m.timestamp = time.time()
                        sock.rx_queue.put(m)
            except can_CanError:
                pass 
开发者ID:secdev,项目名称:scapy,代码行数:18,代码来源:cansocket_python_can.py

示例3: _rx_thread

# 需要导入模块: import can [as 别名]
# 或者: from can import CanError [as 别名]
def _rx_thread(self, bus):
        msg = None
        try:
            while self._running:
                if msg is not None:
                    with self._lock:
                        for callback in self.listeners:
                            callback(msg)
                msg = bus.recv(self.timeout)

        # 
        # The next two handlers are intended to mask race conditions that can occur when 
        # we are blocked on a can-receive and close the bus.
        except CanError as err:
            if self._running:
                raise
        except ValueError as err:
            if self._running:
                raise
                
        except Exception as exc:
            self.exception = exc
            raise 
开发者ID:milhead2,项目名称:python-j1939,代码行数:25,代码来源:notifier.py

示例4: connect

# 需要导入模块: import can [as 别名]
# 或者: from can import CanError [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) 
开发者ID:benkfra,项目名称:j1939,代码行数:23,代码来源:electronic_control_unit.py

示例5: send_message

# 需要导入模块: import can [as 别名]
# 或者: from can import CanError [as 别名]
def send_message(self, can_id, data):
        """Send a raw CAN message to the bus.

        This method may be overridden in a subclass if you need to integrate
        this library with a custom backend.
        It is safe to call this from multiple threads.

        :param int can_id:
            CAN-ID of the message (always 29-bit)
        :param data:
            Data to be transmitted (anything that can be converted to bytes)

        :raises can.CanError:
            When the message fails to be transmitted
        """

        if not self._bus:
            raise RuntimeError("Not connected to CAN bus")
        msg = can.Message(extended_id=True,
                          arbitration_id=can_id,
                          data=data
                          )
        with self._send_lock:
            self._bus.send(msg)
        # TODO: check error receivement 
开发者ID:benkfra,项目名称:j1939,代码行数:27,代码来源:electronic_control_unit.py

示例6: send_message

# 需要导入模块: import can [as 别名]
# 或者: from can import CanError [as 别名]
def send_message(self, can_id, data, remote=False):
        """Send a raw CAN message to the network.

        This method may be overridden in a subclass if you need to integrate
        this library with a custom backend.
        It is safe to call this from multiple threads.

        :param int can_id:
            CAN-ID of the message
        :param data:
            Data to be transmitted (anything that can be converted to bytes)
        :param bool remote:
            Set to True to send remote frame

        :raises can.CanError:
            When the message fails to be transmitted
        """
        if not self.bus:
            raise RuntimeError("Not connected to CAN bus")
        msg = can.Message(is_extended_id=can_id > 0x7FF,
                          arbitration_id=can_id,
                          data=data,
                          is_remote_frame=remote)
        with self.send_lock:
            self.bus.send(msg)
        self.check() 
开发者ID:christiansandberg,项目名称:canopen,代码行数:28,代码来源:network.py

示例7: send_msg

# 需要导入模块: import can [as 别名]
# 或者: from can import CanError [as 别名]
def send_msg(self, msg):
        try:
            self.bus.send(msg)
            print("Message sent on {}".format(self.bus.channel_info))
        except can.CanError:
            print("Message NOT sent") 
开发者ID:rookiepeng,项目名称:socket-test,代码行数:8,代码来源:cancomm.py

示例8: _process_cts

# 需要导入模块: import can [as 别名]
# 或者: from can import CanError [as 别名]
def _process_cts(self, msg):
        logger.debug("_process_cts")
        logger.debug("MIL8: cts message is: %s" % msg)
        #logger.debug("MIL8:    len(pdu-send-buffer) = %d" % len(self._incomplete_transmitted_pdus[0][23]))


        if msg.arbitration_id.pgn.pdu_specific in self._incomplete_transmitted_pdus:
            if msg.arbitration_id.source_address in self._incomplete_transmitted_pdus[
                    msg.arbitration_id.pgn.pdu_specific]:
                # Next packet number in CTS message (Packet numbers start at 1 not 0)
                start_index = msg.data[2] - 1
                # Using total number of packets in CTS message
                end_index = start_index + msg.data[1]
                for _msg in self._incomplete_transmitted_pdus[msg.arbitration_id.pgn.pdu_specific][
                        msg.arbitration_id.source_address][start_index:end_index]:
                    logger.debug("MIL8:        msg=%s" % (_msg))
                    # TODO: Needs to be pacing if we get this working...
                    try:
                        # Shouldent send a J1939 PDU as a CAN Message unless we are careful
                        canMessage =  Message(arbitration_id=_msg.arbitration_id, data=_msg.data)
                        self.can_bus.send(canMessage)
                    except CanError:
                        
                        if self._ignore_can_send_error:
                            pass
                        raise
        logger.debug("MIL8:    _process_cts complete") 
开发者ID:milhead2,项目名称:python-j1939,代码行数:29,代码来源:__init__.py

示例9: _throttler_function

# 需要导入模块: import can [as 别名]
# 或者: from can import CanError [as 别名]
def _throttler_function(self):
        while self.can_notifier._running:
            _msg = None
            try:
                _msg = self._long_message_segment_queue.get(timeout=0.1)
            except Empty:
                pass
            if _msg is not None:
                try:
                    self.can_bus.send(_msg)
                    time.sleep(0.05)
                except CanError:
                    if self._ignore_can_send_error:
                        pass
                    raise 
开发者ID:milhead2,项目名称:python-j1939,代码行数:17,代码来源:__init__.py

示例10: read

# 需要导入模块: import can [as 别名]
# 或者: from can import CanError [as 别名]
def read(self):
        if not self.connected:
            return None
        try:
            frame = self.bus.recv(5)
        except CanError:
            return None
        else:
            if frame is None:
                return None # Timeout condition.
            extended = frame.is_extended_id
            identifier = can.Identifier.make_identifier(frame.arbitration_id, extended)
            return can.Frame(id_ = identifier, dlc = frame.dlc, data = frame.data, timestamp = frame.timestamp) 
开发者ID:christoph2,项目名称:pyxcp,代码行数:15,代码来源:python_can.py

示例11: connect

# 需要导入模块: import can [as 别名]
# 或者: from can import CanError [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 
开发者ID:christiansandberg,项目名称:canopen,代码行数:31,代码来源:network.py

示例12: _send

# 需要导入模块: import can [as 别名]
# 或者: from can import CanError [as 别名]
def _send(self, msg):
        try:
            self._iface.send(msg)
            log.debug('TX: '+canframe_to_string(msg))
        except can.CanError:
            raise IOError('Sending error') 
开发者ID:marcinbor85,项目名称:can-prog,代码行数:8,代码来源:abstract.py


注:本文中的can.CanError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。