本文整理汇总了Python中can.Notifier方法的典型用法代码示例。如果您正苦于以下问题:Python can.Notifier方法的具体用法?Python can.Notifier怎么用?Python can.Notifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类can
的用法示例。
在下文中一共展示了can.Notifier方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connect
# 需要导入模块: import can [as 别名]
# 或者: from can import Notifier [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: test_multiple_polling
# 需要导入模块: import can [as 别名]
# 或者: from can import Notifier [as 别名]
def test_multiple_polling(self):
reader = BufferedReader()
bus_notifier = Notifier(self.bus, [reader])
self._create_connector("multiple_polling.json")
config1 = self.config["devices"][0]["timeseries"][0]
config2 = self.config["devices"][0]["timeseries"][1]
config3 = self.config["devices"][0]["timeseries"][2]
time_to_wait = config2["polling"]["period"] * 4
message_count = int(time_to_wait / config2["polling"]["period"]) + 1 + \
int(time_to_wait / config3["polling"]["period"]) + 1 + \
1 # one time polling task
sleep(time_to_wait)
self.connector.close()
bus_notifier.stop()
messages = []
while True:
msg = reader.get_message(time_to_wait)
if msg is None:
break
messages.append(msg)
self.assertEqual(len(messages), message_count)
expected_message_ids = [config1["nodeId"], config2["nodeId"], config3["nodeId"],
config2["nodeId"], config3["nodeId"], config2["nodeId"],
config3["nodeId"], config2["nodeId"], config3["nodeId"],
config2["nodeId"]]
for i in range(0, message_count):
self.assertEqual(messages[i].arbitration_id, expected_message_ids[i])
示例3: __init__
# 需要导入模块: import can [as 别名]
# 或者: from can import Notifier [as 别名]
def __init__(self, stdscr, args):
self._stdscr = stdscr
self._dbase = database.load_file(args.database,
encoding=args.encoding,
frame_id_mask=args.frame_id_mask,
strict=not args.no_strict)
self._single_line = args.single_line
self._filtered_sorted_message_names = []
self._filter = ''
self._compiled_filter = None
self._formatted_messages = {}
self._playing = True
self._modified = True
self._show_filter = False
self._queue = Queue()
self._nrows, self._ncols = stdscr.getmaxyx()
self._received = 0
self._discarded = 0
self._basetime = None
self._page = 0
stdscr.keypad(True)
stdscr.nodelay(True)
curses.use_default_colors()
curses.curs_set(False)
curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_GREEN)
curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_CYAN)
bus = self.create_bus(args)
self._notifier = can.Notifier(bus, [self])
示例4: __init__
# 需要导入模块: import can [as 别名]
# 或者: from can import Notifier [as 别名]
def __init__(self, callback, filter, bus):
self.__bus = bus
listener = can.Listener()
listener.on_message_received = callback
self.__notifier = can.Notifier(self.__bus, [listener], 0)
self.__listeners = [listener]
self.addFilter(filter)
##
# @brief Adds call back (via additional listener) to the notifier which is attached to this bus
示例5: connect
# 需要导入模块: import can [as 别名]
# 或者: from can import Notifier [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: enable_notifier
# 需要导入模块: import can [as 别名]
# 或者: from can import Notifier [as 别名]
def enable_notifier(self):
self.notifier = can.Notifier(self.bus, listeners=[])
示例7: __init__
# 需要导入模块: import can [as 别名]
# 或者: from can import Notifier [as 别名]
def __init__(self,
dut_name,
database,
can_bus,
bus_name=None,
on_message=None,
decode_choices=True,
scaling=True,
padding=False):
self._dut_name = dut_name
self._bus_name = bus_name
self._database = database
self._can_bus = can_bus
self._input_list = []
self._input_queue = queue.Queue()
self._messages = Messages()
self._is_running = False
# DUT name validation.
node_names = [node.name for node in database.nodes]
if not any([name == dut_name for name in node_names]):
raise Error(
"expected DUT name in {}, but got '{}'".format(node_names,
dut_name))
# BUS name validation.
bus_names = [bus.name for bus in database.buses]
if len(bus_names) == 0:
if bus_name is not None:
raise Error(
"expected bus name None as there are no buses defined in "
"the database, but got '{}'".format(bus_name))
elif not any([name == bus_name for name in bus_names]):
raise Error(
"expected bus name in {}, but got '{}'".format(bus_names,
bus_name))
for message in database.messages:
if message.bus_name == bus_name:
self._messages[message.name] = Message(message,
can_bus,
self._input_list,
self._input_queue,
decode_choices,
scaling,
padding)
listener = Listener(self._database,
self._messages,
self._input_queue,
on_message)
self._notifier = can.Notifier(can_bus, [listener])
示例8: test_update
# 需要导入模块: import can [as 别名]
# 或者: from can import Notifier [as 别名]
def test_update(self):
reader = BufferedReader()
bus_notifier = Notifier(self.bus, [reader])
self._create_connector("attribute_updates.json")
configs = self.config["devices"][0]["attributeUpdates"]
updates = {"device": self.config["devices"][0]["name"],
"data": {
"boolAttr": True,
"intAttr": randint(-int(pow(2, configs[1]["dataLength"]) / 2),
pow(2, configs[1]["dataLength"] - 1)),
"floatAttr": uniform(-3.1415926535, 3.1415926535),
"stringAttr": ''.join(choice(ascii_lowercase) for _ in range(8)),
"wrongConfigAttr": True
}}
data_list = [[int(updates["data"]["boolAttr"])],
updates["data"]["intAttr"].to_bytes(configs[1]["dataLength"],
configs[1]["dataByteorder"],
signed=(updates["data"]["intAttr"] < 0)),
list(struct.pack(">f", updates["data"]["floatAttr"])),
list(str("Test" + updates["data"]["stringAttr"]).encode(self.connector.DEFAULT_ENCODING))
]
self.connector.on_attributes_update(updates)
sleep(1)
self.connector.close()
bus_notifier.stop()
messages = []
while True:
msg = reader.get_message(1)
if msg is None:
break
messages.append(msg)
self.assertEqual(len(messages), len(data_list))
messages = sorted(messages, key=lambda message: message.arbitration_id)
for i in range(len(messages)):
self.assertTrue(messages[i].equals(Message(arbitration_id=configs[i]["nodeId"],
is_extended_id=configs[i].get("isExtendedId",
self.connector.DEFAULT_EXTENDED_ID_FLAG),
is_fd=configs[i].get("isFd", self.connector.DEFAULT_FD_FLAG),
bitrate_switch=configs[i].get("bitrateSwitch",
self.connector.DEFAULT_BITRATE_SWITCH_FLAG),
data=data_list[i],
timestamp=messages[i].timestamp,
channel=messages[i].channel)))