1- import collections
1+ from collections import deque
22from ctypes import c_ubyte
33import logging
44import time
55from typing import Any , Dict , Optional , Deque , Sequence , Tuple , Union
66
77from can import BitTiming , BusABC , Message , BitTimingFd
8- from can .exceptions import CanTimeoutError , CanInitializationError
8+ from can .exceptions import CanTimeoutError
99from can .typechecking import CanFilters
1010from can .util import deprecated_args_alias , check_or_adjust_timing_clock
1111
@@ -50,11 +50,12 @@ def __init__(
5050 If set, software received message queue can only grow to this many
5151 messages (for all channels) before older messages are dropped
5252 """
53- super ().__init__ (channel = channel , can_filters = can_filters , ** kwargs )
54-
5553 if not (bitrate or timing ):
5654 raise ValueError ("Either bitrate or timing argument is required" )
5755
56+ # Do this after the error handling
57+ super ().__init__ (channel = channel , can_filters = can_filters , ** kwargs )
58+
5859 if isinstance (channel , str ):
5960 # Assume comma separated string of channels
6061 self .channels = [int (ch .strip ()) for ch in channel .split ("," )]
@@ -63,23 +64,23 @@ def __init__(
6364 else : # Sequence[int]
6465 self .channels = list (channel )
6566
66- self .rx_queue = collections .deque (
67- maxlen = rx_queue_size
68- ) # type: Deque[Tuple[int, driver.Message]]
67+ self .rx_queue : Deque [Tuple [int , driver .Message ]] = deque (maxlen = rx_queue_size )
6968
7069 self .channel_info = f"CANalyst-II: device { device } , channels { self .channels } "
7170
7271 self .device = driver .CanalystDevice (device_index = device )
73- for channel in self .channels :
72+ for single_channel in self .channels :
7473 if isinstance (timing , BitTiming ):
7574 timing = check_or_adjust_timing_clock (timing , valid_clocks = [8_000_000 ])
76- self .device .init (channel , timing0 = timing .btr0 , timing1 = timing .btr1 )
75+ self .device .init (
76+ single_channel , timing0 = timing .btr0 , timing1 = timing .btr1
77+ )
7778 elif isinstance (timing , BitTimingFd ):
7879 raise NotImplementedError (
7980 f"CAN FD is not supported by { self .__class__ .__name__ } ."
8081 )
8182 else :
82- self .device .init (channel , bitrate = bitrate )
83+ self .device .init (single_channel , bitrate = bitrate )
8384
8485 # Delay to use between each poll for new messages
8586 #
0 commit comments