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


Python can.Bus方法代码示例

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


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

示例1: _create_bus

# 需要导入模块: import can [as 别名]
# 或者: from can import Bus [as 别名]
def _create_bus(self):
        return Bus(
            channel="virtual_channel",
            bustype="virtual",
            receive_own_messages=False
        ) 
开发者ID:thingsboard,项目名称:thingsboard-gateway,代码行数:8,代码来源:test_can_connector.py

示例2: create_bus

# 需要导入模块: import can [as 别名]
# 或者: from can import Bus [as 别名]
def create_bus(self, args):
        kwargs = {}

        if args.bit_rate is not None:
            kwargs['bitrate'] = int(args.bit_rate)

        try:
            return can.Bus(bustype=args.bus_type,
                           channel=args.channel,
                           **kwargs)
        except:
            raise Exception(
                "Failed to create CAN bus with bustype='{}' and "
                "channel='{}'.".format(args.bus_type,
                                       args.channel)) 
开发者ID:eerimoq,项目名称:cantools,代码行数:17,代码来源:monitor.py

示例3: connect

# 需要导入模块: import can [as 别名]
# 或者: from can import Bus [as 别名]
def connect(self):
        self.kwargs = OrderedDict()
        # Fetch driver keyword arguments.
        self._fetch_kwargs(False)
        self._fetch_kwargs(True)
        self.bus = Bus(bustype = self.bustype, **self.kwargs)
        self.bus.set_filters(None)
        self.parent.logger.debug("Python-CAN driver: {} - {}]".format(self.bustype, self.bus))
        self.connected = True 
开发者ID:christoph2,项目名称:pyxcp,代码行数:11,代码来源:python_can.py

示例4: __init__

# 需要导入模块: import can [as 别名]
# 或者: from can import Bus [as 别名]
def __init__(self,
                 ifaceName,
                 bitrate=500000,
                 fdBitrate=2000000,
                 isFD=False):
        """
        This method initializes the can.Message CAN interface using the passed parameters and the start() method.
        Please note the active-flag which protects the object from being deleted while being in use.

        :param ifaceName: Name of the interface as displayed by ``ifconfig -a``
        :param bitrate: Desired bitrate of the interface
        """

        self.ifaceName = ifaceName
        self.VCAN = self.checkVCAN()

        self.bitrate = bitrate if not self.VCAN else -1
        self.fdBitrate = fdBitrate if not self.VCAN else -1
        self.isFD = isFD

        self.iface = can.Bus(
            interface="socketcan",
            channel=self.ifaceName,
            receive_own_messages=False,
            fd=isFD)

        self.updateBitrate(bitrate, fdBitrate, fd=isFD)

        #: 100 ms read timeout for async reads (see :func:`readPacketAsync`)
        self.timeout = 0.1

        self.active = False 
开发者ID:schutzwerk,项目名称:CANalyzat0r,代码行数:34,代码来源:CANData.py

示例5: __init__

# 需要导入模块: import can [as 别名]
# 或者: from can import Bus [as 别名]
def __init__(self, bus=None):
        self.message_process = None
        if bus is None:
            self.bus = can.Bus(DEFAULT_INTERFACE)
        else:
            self.bus = bus 
开发者ID:CaringCaribou,项目名称:caringcaribou,代码行数:8,代码来源:mock_ecu.py

示例6: setUp

# 需要导入模块: import can [as 别名]
# 或者: from can import Bus [as 别名]
def setUp(self):
        # Initialize mock ECU
        self.ecu = MockEcuIsoTp(self.ARB_ID_REQUEST, self.ARB_ID_RESPONSE)
        self.ecu.start_server()
        # Initialize virtual CAN bus
        can_bus = can.Bus(DEFAULT_INTERFACE)
        # Setup ISO-TP layer
        self.tp = iso15765_2.IsoTp(self.ARB_ID_REQUEST, self.ARB_ID_RESPONSE, bus=can_bus) 
开发者ID:CaringCaribou,项目名称:caringcaribou,代码行数:10,代码来源:test_iso_15765_2.py

示例7: setUp

# 需要导入模块: import can [as 别名]
# 或者: from can import Bus [as 别名]
def setUp(self):
        # Initialize mock ECU
        self.ecu = MockEcuIso14229(self.ARB_ID_REQUEST, self.ARB_ID_RESPONSE)
        self.ecu.start_server()
        # Initialize virtual CAN bus
        can_bus = can.Bus(DEFAULT_INTERFACE)
        # Setup diagnostics on top of ISO-TP layer
        self.tp = iso15765_2.IsoTp(self.ARB_ID_REQUEST, self.ARB_ID_RESPONSE, bus=can_bus)
        self.diagnostics = iso14229_1.Iso14229_1(self.tp)
        # Reduce timeout value to speed up testing
        self.diagnostics.P3_CLIENT = 0.5 
开发者ID:CaringCaribou,项目名称:caringcaribou,代码行数:13,代码来源:test_iso_14229_1.py

示例8: __init__

# 需要导入模块: import can [as 别名]
# 或者: from can import Bus [as 别名]
def __init__(self, arb_id=None, notifier_enabled=True):
        """
        CanActions constructor

        :param arb_id: int default arbitration ID for object or None
        :param notifier_enabled: bool indicating whether a notifier for incoming message callbacks should be enabled
        """
        self.bus = can.Bus(DEFAULT_INTERFACE)
        self.arb_id = arb_id
        self.bruteforce_running = False
        self.notifier = None
        if notifier_enabled:
            self.enable_notifier() 
开发者ID:CaringCaribou,项目名称:caringcaribou,代码行数:15,代码来源:can_actions.py

示例9: updateBitrate

# 需要导入模块: import can [as 别名]
# 或者: from can import Bus [as 别名]
def updateBitrate(self, bitrate, fdBitrate, fd=False):
        """
        Updates the bitrate of the SocketCAN interface (if possible).

        :param bitrate: The desired bitrate in bit/s
        :return: A boolean value indicating success of updating the bitrate value
        """

        # Physical CAN or CAN FD or virtual CAN ?
        if not self.VCAN:
            # Put interface down first so the new bitrate can be applied
            cmds = []
            cmds.append("ip link set " + self.ifaceName + " down")
            cmds.append("ip link set " + self.ifaceName + " type can fd off")

            for cmd in cmds:
                process = subprocess.Popen(
                    cmd.split(),
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE)
                output, error = process.communicate()

            # prepare cmd for next call
            if fd:

                cmd = "ip link set " + self.ifaceName + " up type can bitrate " + str(
                    bitrate) + " dbitrate " + str(fdBitrate) + " fd on"

            else:
                cmd = "ip link set " + self.ifaceName + \
                    " up type can bitrate " + str(bitrate)

        else:
            cmd = "ip link set up " + self.ifaceName

        process = subprocess.Popen(
            cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        output, error = process.communicate()

        if output.decode("utf-8") == "" and error.decode("utf-8") == "":
            if self.VCAN:
                self.bitrate = -1
                self.fdBitrate = -1
                self.isFD = False
            else:
                self.bitrate = bitrate
                self.fdBitrate = fdBitrate
                self.isFD = fd

            self.iface = can.Bus(
                interface="socketcan",
                channel=self.ifaceName,
                receive_own_messages=False,
                fd=fd)

            return True

        else:
            CANData.logger.error(error.decode("utf-8"))
            return False 
开发者ID:schutzwerk,项目名称:CANalyzat0r,代码行数:62,代码来源:CANData.py

示例10: auto_blacklist

# 需要导入模块: import can [as 别名]
# 或者: from can import Bus [as 别名]
def auto_blacklist(bus, duration, classifier_function, print_results):
    """Listens for false positives on the CAN bus and generates an arbitration ID blacklist.

    Finds all can.Message <msg> on 'bus' where 'classifier_function(msg)' evaluates to True.
    Terminates after 'duration' seconds and returns a set of all matching arbitration IDs.
    Prints progress, time countdown and list of results if 'print_results' is True.

    :param bus: CAN bus instance
    :param duration: duration in seconds
    :param classifier_function: function which, when called upon a can.Message instance,
                                returns a bool indicating if it should be blacklisted
    :param print_results: whether progress and results should be printed to stdout
    :type bus: can.Bus
    :type duration: float
    :type classifier_function: function
    :type print_results: bool
    :return set of matching arbitration IDs to blacklist
    :rtype set(int)
    """
    if print_results:
        print("Scanning for arbitration IDs to blacklist")
    blacklist = set()
    start_time = time.time()
    end_time = start_time + duration
    while time.time() < end_time:
        if print_results:
            time_left = end_time - time.time()
            num_matches = len(blacklist)
            print("\r{0:> 5.1f} seconds left, {1} found".format(time_left, num_matches), end="")
            stdout.flush()
        # Receive message
        msg = bus.recv(0.1)
        if msg is None:
            continue
        # Classify
        if classifier_function(msg):
            # Add to blacklist
            blacklist.add(msg.arbitration_id)
    if print_results:
        num_matches = len(blacklist)
        print("\r  0.0 seconds left, {0} found".format(num_matches), end="")
        if len(blacklist) > 0:
            print("\n  Detected IDs: {0}".format(" ".join(sorted(list(map(hex, blacklist))))))
        else:
            print()
    return blacklist 
开发者ID:CaringCaribou,项目名称:caringcaribou,代码行数:48,代码来源:can_actions.py


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