Skip to content

Commit

Permalink
Use Environment.OSVersion.Version.Build directly
Browse files Browse the repository at this point in the history
  • Loading branch information
AskBojesen committed May 17, 2024
1 parent e423738 commit 722df26
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@
"PrivateKeyFile" = "8:"
"TimeStampServer" = "8:"
"InstallerBootstrapper" = "3:2"
"BootstrapperCfg:{63ACBE69-63AA-4F98-B2B6-99F9E24495F2}"
{
"Enabled" = "11:TRUE"
"PromptEnabled" = "11:TRUE"
"PrerequisitesLocation" = "2:1"
"Url" = "8:"
"ComponentsUrl" = "8:"
}
}
}
"Deployable"
Expand Down Expand Up @@ -156,23 +164,23 @@
{
"Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:BLE.Client.WinConsole"
"ProductCode" = "8:{F6BA5731-7436-4762-A612-E16066951342}"
"PackageCode" = "8:{D8837791-AD30-4637-A38E-E4873DBC15A2}"
"ProductCode" = "8:{5F449E95-7E87-4E64-B500-80A6AF1D97DA}"
"PackageCode" = "8:{B9329BAB-7161-4B70-A339-EFC0E40F2D22}"
"UpgradeCode" = "8:{2DC56EBC-822F-4B47-93C7-DCBD97994976}"
"AspNetVersion" = "8:4.0.30319.0"
"RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:TRUE"
"DetectNewerInstalledVersion" = "11:TRUE"
"InstallAllUsers" = "11:FALSE"
"ProductVersion" = "8:1.0.0"
"ProductVersion" = "8:1.0.2"
"Manufacturer" = "8:Plugin.BLE"
"ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:"
"Title" = "8:BLE Client WinConsole "
"Subject" = "8:"
"ARPCONTACT" = "8:Ask Bojesen"
"Keywords" = "8:"
"ARPCOMMENTS" = "8:v1.0.0"
"ARPCOMMENTS" = "8:v1.0.2"
"ARPURLINFOABOUT" = "8:https://github.com/dotnet-bluetooth-le/dotnet-bluetooth-le"
"ARPPRODUCTICON" = "8:"
"ARPIconIndex" = "3:0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<TargetFramework>net8.0-windows10.0.22621.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>1.0.0</Version>
<Version>1.0.2</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
23 changes: 15 additions & 8 deletions Source/BLE.Client/BLE.Client.WinConsole/PluginDemos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,19 @@ public async Task ShowBondState()
dev.Dispose();
}

public async Task Connect_Read_Services_Disconnect_5X()
public async Task Connect_Read_Services_Disconnect_Loop()
{
string bleaddress = BleAddressSelector.GetBleAddress();
var id = bleaddress.ToBleDeviceGuid();
var connectParameters = new ConnectParameters(connectionParameterSet: ConnectionParameterSet.Balanced);

new Task(ConsoleKeyReader).Start();
using (IDevice dev = await Adapter.ConnectToKnownDeviceAsync(id, connectParameters))
{
for (int i = 0; i < 5; i++)
int count = 1;
while(true)
{
await Task.Delay(100);
Write($"---------------- {i} ------------------");
Write($"---------------- {count++} ------- (Esc to stop) ------");
if (dev.State != DeviceState.Connected)
{
Write("Connecting");
Expand All @@ -135,19 +136,25 @@ public async Task Connect_Read_Services_Disconnect_5X()
Write("Disconnecting");
await Adapter.DisconnectDeviceAsync(dev);
Write("Test_Connect_Disconnect done");
if (consoleKey == ConsoleKey.Escape)
{
break;
}
}
}
}

public async Task Connect_Read_Services_Dispose_5X()
public async Task Connect_Read_Services_Dispose_Loop()
{
string bleaddress = BleAddressSelector.GetBleAddress();
var id = bleaddress.ToBleDeviceGuid();
var connectParameters = new ConnectParameters(connectionParameterSet: ConnectionParameterSet.Balanced);
for (int i = 0; i < 5; i++)
new Task(ConsoleKeyReader).Start();
int count = 1;
while (true)
{
await Task.Delay(100);
Write($"---------------- {i} ------------------");
Write($"---------------- {count++} ------- (Esc to stop) ------");
IDevice dev = await Adapter.ConnectToKnownDeviceAsync(id, connectParameters);
Write("Reading services");
var services = await dev.GetServicesAsync();
Expand All @@ -165,7 +172,7 @@ public async Task Connect_Read_Services_Dispose_5X()
charlist.Clear();
Write("Waiting 3 secs");
await Task.Delay(3000);
//await Adapter.DisconnectDeviceAsync(dev);
await Adapter.DisconnectDeviceAsync(dev);
Write("Disposing");
dev.Dispose();
}
Expand Down
6 changes: 3 additions & 3 deletions Source/BLE.Client/BLE.Client.WinConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Windows.Media.Capture;

Console.WriteLine("Hello, BLE World!");
Console.WriteLine($"BleImplementation.OsRuntimeBuildNumber: {BleImplementation.OsRuntimeBuildNumber}");
Console.WriteLine($"Environment.OSVersion.Version.Build: {Environment.OSVersion.Version.Build}");
using (var ct = new ConsoleTracer())
{

Expand All @@ -25,8 +25,8 @@
{ConsoleKey.D4, new Demo("Pair -> Connect -> Disconnect", ppemos.Pair_Connect_Disconnect) },
{ConsoleKey.D5, new Demo("Connect -> Change Parameters -> Disconnect", ppemos.Connect_Change_Parameters_Disconnect) },
{ConsoleKey.D6, new Demo("Run GetSystemConnectedOrPairedDevices", ppemos.RunGetSystemConnectedOrPairedDevices) },
{ConsoleKey.D7, new Demo("5X: Connect -> Read services -> Disconnect", ppemos.Connect_Read_Services_Disconnect_5X) },
{ConsoleKey.D8, new Demo("5X: Connect -> Read services -> Dispose", ppemos.Connect_Read_Services_Dispose_5X) },
{ConsoleKey.D7, new Demo("Loop: Connect -> Read services -> Disconnect", ppemos.Connect_Read_Services_Disconnect_Loop) },
{ConsoleKey.D8, new Demo("Loop: Connect -> Read services -> Dispose", ppemos.Connect_Read_Services_Dispose_Loop) },
{ConsoleKey.D9, new Demo("Connect -> Loop: ConnectionLost -> Connect", ppemos.Connect_ConnectionLost_Reconnect) },
{ConsoleKey.Q, new Demo("Adapter.BondAsync", ppemos.BondAsync) },
{ConsoleKey.W, new Demo("Adapter.BondedDevices", ppemos.GetBondedDevices) },
Expand Down
1 change: 1 addition & 0 deletions Source/Plugin.BLE/Plugin.BLE.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<TargetFrameworks>netstandard2.0;net7.0-android33.0;net8.0-android34.0</TargetFrameworks>
<TargetFrameworks Condition="!$([MSBuild]::IsOSPlatform('linux'))">$(TargetFrameworks);net7.0-ios;net7.0-maccatalyst;net8.0-ios;net8.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);MonoAndroid13.0;Xamarin.iOS10;Xamarin.Mac20;uap10.0.19041;net7.0-windows10.0.19041;net8.0-windows10.0.19041;net8.0-windows10.0.22000.0</TargetFrameworks>
<TargetFrameworks>net8.0-windows10.0.22000.0</TargetFrameworks>
<AssemblyName>Plugin.BLE</AssemblyName>
<RootNamespace>Plugin.BLE</RootNamespace>
<Version>3.1.0-rc.1</Version>
Expand Down
2 changes: 1 addition & 1 deletion Source/Plugin.BLE/Windows/Adapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private void Device_ConnectionStatusChanged(BluetoothLEDevice nativeDevice, obje
&& ConnectedDeviceRegistry.TryGetValue(id, out var connectedDevice))
{
#if WINDOWS10_0_22000_0_OR_GREATER
if (BleImplementation.OsRuntimeBuildNumber >= 22000)
if (Environment.OSVersion.Version.Build >= 22000)
{
var conpar = nativeDevice.GetConnectionParameters();
Trace.Message(
Expand Down
20 changes: 0 additions & 20 deletions Source/Plugin.BLE/Windows/BleImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,6 @@ public class BleImplementation : BleImplementationBase
public static BluetoothCacheMode CacheModeGetCharacteristics { get; set; } = BluetoothCacheMode.Cached;
public static BluetoothCacheMode CacheModeGetServices { get; set; } = BluetoothCacheMode.Cached;

private static int? runtimeBuildNumber = null;

/// <summary>
/// Get the Windows runtime build number
/// Eg running on Windows 10 gives 19041 even though it is executing an application compiled as eg net8.0-windows10.0.22621.0
/// ref https://learn.microsoft.com/en-us/windows/release-health/release-information
/// ref https://learn.microsoft.com/en-us/windows/release-health/windows11-release-information
/// </summary>
public static int OsRuntimeBuildNumber
{
get
{
if (runtimeBuildNumber is null)
{
runtimeBuildNumber = Environment.OSVersion.Version.Build;
}
return runtimeBuildNumber.Value;
}
}

protected override IAdapter CreateNativeAdapter()
{
return new Adapter(btAdapter);
Expand Down
2 changes: 1 addition & 1 deletion Source/Plugin.BLE/Windows/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ protected override bool UpdateConnectionIntervalNative(ConnectionInterval interv
static bool MaybeRequestPreferredConnectionParameters(BluetoothLEDevice device, ConnectParameters connectParameters)
{
#if WINDOWS10_0_22000_0_OR_GREATER
if (BleImplementation.OsRuntimeBuildNumber < 22000)
if (Environment.OSVersion.Version.Build < 22000)
{
return false;
}
Expand Down

0 comments on commit 722df26

Please sign in to comment.