@@ -89,49 +89,48 @@ print(channels)
8989
9090This driver now supports opening multiple channels from the same device in a single ` CandleBus ` instance.
9191
92- - Pass a list of channels belonging to the same device, e.g. ` ['SERIAL:0', 'SERIAL:1' ]` .
93- - Alternatively , pass a list of indices with ` serial_number=SERIAL ` .
94- - A single instance must NOT mix channels from different devices .
92+ - Pass a list of channel indices belonging to the same device, e.g. ` channel=[0, 1 ]` .
93+ - For multiple devices , pass ` serial_number=SERIAL ` to select the device by serial number .
94+ - Configure each channel separately with ` channel_configs ` .
9595
96- ``` python
97- import can
98- from candle import CandleBus
96+ Create a CandleBus instance with multiple channels.
97+
98+ ``` pycon
99+ bus = CandleBus(channel=[0, 1], serial_number='208233AD5003', bitrate=1000000)
100+ ```
101+
102+ Create and configure channels with different bitrates.
99103
100- # Option A: list of "serial:idx" strings
101- bus = CandleBus(channel = [' 208233AD5003:0' , ' 208233AD5003:1' ], fd = True , bitrate = 1000000 , data_bitrate = 5000000 , loop_back = True )
104+ ``` pycon
105+ bus = CandleBus(channel=[0, 1], serial_number='208233AD5003', channel_configs={0: {'bitrate': 500000}, 1: {'bitrate': 1000000})
106+ ```
107+
108+ Send to a specific channel.
102109
103- # Option B: list of indices with explicit serial number
104- bus = CandleBus(channel = [0 , 1 ], serial_number = ' 208233AD5003' , fd = True , bitrate = 1000000 , data_bitrate = 5000000 , loop_back = True )
110+ ``` pycon
111+ msg = can.Message(arbitration_id=0x100, channel=1, data=[0x1, 0x2, 0x3, 0x4])
112+ bus.send(msg)
113+ ```
105114
106- # Send to a specific channel by setting msg.channel
107- m0 = can.Message(arbitration_id = 0x 100 , data = b ' \x00 ' * 8 , is_fd = True )
108- m0.channel = 0
109- bus.send(m0)
115+ Send to multiple channels.
110116
111- m1 = can.Message(arbitration_id = 0x 101 , data = b ' \x01 ' * 8 , is_fd = True )
112- m1.channel = 1
113- bus.send(m1)
117+ ``` pycon
118+ msg = can.Message(arbitration_id=0x100, channel=[0, 1], data=[0x1, 0x2, 0x3, 0x4])
119+ bus.send(msg)
120+ ```
114121
115- # Receive frames: msg.channel indicates the source channel
116- rx = bus.recv(timeout = 0.5 )
117- print (rx.channel, hex (rx.arbitration_id))
122+ Distinguish channels in received messages.
118123
119- bus.shutdown()
124+ ``` pycon
125+ msg = bus.recv()
126+ print(f'Received message on channel {msg.channel}.')
120127```
121128
122129### Notes on multi-channel behavior
123130
124- - A single ` CandleBus ` instance manages multiple channels of one device using one device handle.
125- - ` send() ` routes frames to the target channel based on ` msg.channel ` (int, ` "SERIAL:idx" ` , or ` "idx" ` ).
131+ - ` send() ` routes frames to the target channel based on ` msg.channel ` (int, ` "SERIAL:idx" ` , or ` Sequence[int] ` ).
126132- ` recv() ` returns ` Message.channel ` set to the source channel number.
127- - When ` msg.channel ` is not set, ` send() ` defaults to the first managed channel.
128- - To test multiple devices simultaneously, create one ` CandleBus ` per device.
129-
130- ### Backward compatibility
131-
132- - Existing single-channel usage is unchanged; ` channel=0 ` or ` channel='SERIAL:0' ` still works.
133- - ` can.detect_available_configs('candle') ` continues to report channels as ` serial:idx ` strings.
134- - The stress test ` python -m candle.stress ` (single-channel) remains compatible.
133+ - When ` msg.channel ` is not set, ` send() ` defaults to the first channel.
135134
136135### Performance
137136
@@ -142,7 +141,7 @@ For single-channel performance:
142141python -m candle.stress
143142```
144143
145- For multi-channel and multi-device performance and correctness verification :
144+ For multi-channel performance:
146145``` shell
147146python -m candle.stress_multichannel
148147```
0 commit comments