@@ -28,13 +28,16 @@ public class AntDeviceCollection : ObservableCollection<AntDevice>
2828 /// </remarks>
2929 public object CollectionLock = new object ( ) ;
3030
31- private readonly IAntRadio antRadio ;
32- private int channelNum = 0 ;
31+ private int channelNum = 1 ;
3332 private readonly ILoggerFactory _loggerFactory ;
3433 private readonly ILogger < AntDeviceCollection > logger ;
3534 private readonly ushort timeout ;
35+ private readonly IAntChannel [ ] channels ;
3636
37- /// <summary>Initializes a new instance of the <see cref="AntDeviceCollection" /> class.</summary>
37+ /// <summary>
38+ /// Initializes a new instance of the <see cref="AntDeviceCollection" /> class. The ANT radio is configured
39+ /// for continuous scan mode.
40+ /// </summary>
3841 /// <param name="antRadio">The ANT radio interface.</param>
3942 /// <param name="loggerFactory">Logger factory to generate type specific ILogger from. Can be null.</param>
4043 /// <param name="antDeviceTimeout">ANT device timeout in milliseconds. The default is 2000 milliseconds.</param>
@@ -51,18 +54,12 @@ public class AntDeviceCollection : ObservableCollection<AntDevice>
5154 /// </remarks>
5255 public AntDeviceCollection ( IAntRadio antRadio , ILoggerFactory loggerFactory , ushort antDeviceTimeout = 2000 )
5356 {
54- this . antRadio = antRadio ;
5557 _loggerFactory = loggerFactory ?? NullLoggerFactory . Instance ;
5658 logger = _loggerFactory . CreateLogger < AntDeviceCollection > ( ) ;
5759 logger . LogInformation ( "Created AntDeviceCollection" ) ;
5860 timeout = antDeviceTimeout ;
59- antRadio . GetChannel ( 0 ) . ChannelResponse += Channel_ChannelResponse ;
60-
61- // assign channels for devices to use for sending messages
62- for ( int i = 1 ; i < antRadio . NumChannels ; i ++ )
63- {
64- _ = antRadio . GetChannel ( i ) . AssignChannel ( ChannelType . BaseSlaveReceive , 0 , 500 ) ;
65- }
61+ channels = antRadio . InitializeContinuousScanMode ( ) ;
62+ channels [ 0 ] . ChannelResponse += Channel_ChannelResponse ;
6663 }
6764
6865 private void Channel_ChannelResponse ( object sender , AntResponse e )
@@ -114,8 +111,8 @@ private void DeviceOffline(object sender, EventArgs e)
114111
115112 private AntDevice CreateAntDevice ( ChannelId channelId )
116113 {
117- if ( ++ channelNum == antRadio . NumChannels ) channelNum = 1 ;
118- IAntChannel channel = antRadio . GetChannel ( channelNum ) ;
114+ IAntChannel channel = channels [ channelNum ++ ] ;
115+ if ( channelNum == channels . Length ) { channelNum = 1 ; }
119116
120117 switch ( channelId . DeviceType )
121118 {
0 commit comments