@@ -11,7 +11,7 @@ public partial class ConnectViewModel : ObservableObject
11
11
{
12
12
private readonly IDialogService _dialogService ;
13
13
private readonly IDeviceManagementService _deviceManagementService ;
14
- private ISerialPortConnectionService ? _serialPortConnectionService ;
14
+ private ISerialPortConnectionService _serialPortConnectionService ;
15
15
16
16
/// <summary>
17
17
/// ViewModel for the Connect page.
@@ -77,7 +77,7 @@ private void DeviceManagementServiceOnNakReplyReceived(object? sender, string na
77
77
78
78
[ ObservableProperty ] private int _selectedBaudRate = 9600 ;
79
79
80
- [ ObservableProperty ] private byte _selectedAddress ;
80
+ [ ObservableProperty ] private double _selectedAddress ;
81
81
82
82
[ ObservableProperty ] private byte _connectedAddress ;
83
83
@@ -107,7 +107,6 @@ private async Task ScanSerialPorts()
107
107
AvailableSerialPorts . Clear ( ) ;
108
108
109
109
var serialPortConnectionService = _serialPortConnectionService ;
110
- if ( serialPortConnectionService == null ) return ;
111
110
112
111
var foundAvailableSerialPorts = await serialPortConnectionService . FindAvailableSerialPorts ( ) ;
113
112
@@ -135,7 +134,6 @@ await _dialogService.ShowMessageDialog("Error",
135
134
private async Task DiscoverDevice ( CancellationToken token )
136
135
{
137
136
var serialPortConnectionService = _serialPortConnectionService ;
138
- if ( serialPortConnectionService == null ) return ;
139
137
140
138
string serialPortName = SelectedSerialPort ? . Name ?? string . Empty ;
141
139
if ( string . IsNullOrWhiteSpace ( serialPortName ) ) return ;
@@ -173,7 +171,7 @@ private async Task DiscoverDevice(CancellationToken token)
173
171
StatusText =
174
172
$ "Successfully discovered device { current . Connection . BaudRate } with address { current . Address } ";
175
173
StatusLevel = StatusLevel . Discovered ;
176
- _serialPortConnectionService = current . Connection as ISerialPortConnectionService ;
174
+ if ( current . Connection is ISerialPortConnectionService service ) _serialPortConnectionService = service ;
177
175
ConnectedAddress = current . Address ;
178
176
ConnectedBaudRate = current . Connection . BaudRate ;
179
177
break ;
@@ -225,7 +223,6 @@ private async Task DiscoverDevice(CancellationToken token)
225
223
private async Task ConnectDevice ( )
226
224
{
227
225
var serialPortConnectionService = _serialPortConnectionService ;
228
- if ( serialPortConnectionService == null ) return ;
229
226
230
227
string serialPortName = SelectedSerialPort ? . Name ?? string . Empty ;
231
228
if ( string . IsNullOrWhiteSpace ( serialPortName ) ) return ;
@@ -252,9 +249,9 @@ await _dialogService.ShowMessageDialog("Connect", $"Invalid security key entered
252
249
253
250
await _deviceManagementService . Shutdown ( ) ;
254
251
await _deviceManagementService . Connect (
255
- serialPortConnectionService . GetConnection ( serialPortName , SelectedBaudRate ) , SelectedAddress ,
252
+ serialPortConnectionService . GetConnection ( serialPortName , SelectedBaudRate ) , ( byte ) SelectedAddress ,
256
253
UseSecureChannel , UseDefaultKey , securityKey ) ;
257
- ConnectedAddress = SelectedAddress ;
254
+ ConnectedAddress = ( byte ) SelectedAddress ;
258
255
ConnectedBaudRate = SelectedBaudRate ;
259
256
}
260
257
}
@@ -276,5 +273,4 @@ public enum StatusLevel
276
273
Disconnected ,
277
274
ConnectingManually
278
275
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
279
-
280
276
}
0 commit comments