added library to csproj file
This commit is contained in:
BIN
ProftaakRH/BLELibrary.dll
Normal file
BIN
ProftaakRH/BLELibrary.dll
Normal file
Binary file not shown.
92
ProftaakRH/FietsDemo.cs
Normal file
92
ProftaakRH/FietsDemo.cs
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
using Avans.TI.BLE;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace FietsDemo
|
||||||
|
{
|
||||||
|
internal class Program
|
||||||
|
{
|
||||||
|
private static async Task Main(string[] args)
|
||||||
|
{
|
||||||
|
int errorCode = 0;
|
||||||
|
BLE bleBike = new BLE();
|
||||||
|
BLE bleHeart = new BLE();
|
||||||
|
Thread.Sleep(1000); // We need some time to list available devices
|
||||||
|
|
||||||
|
// List available devices
|
||||||
|
List<String> bleBikeList = bleBike.ListDevices();
|
||||||
|
Console.WriteLine("Devices found: ");
|
||||||
|
foreach (var name in bleBikeList)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Device: {name}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Connecting
|
||||||
|
errorCode = errorCode = await bleBike.OpenDevice("Avans Bike B5F0");
|
||||||
|
// __TODO__ Error check
|
||||||
|
|
||||||
|
var services = bleBike.GetServices;
|
||||||
|
foreach (var service in services)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Service: {service}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set service
|
||||||
|
errorCode = await bleBike.SetService("6e40fec1-b5a3-f393-e0a9-e50e24dcca9e");
|
||||||
|
// __TODO__ error check
|
||||||
|
|
||||||
|
// Subscribe
|
||||||
|
bleBike.SubscriptionValueChanged += BleBike_SubscriptionValueChanged;
|
||||||
|
errorCode = await bleBike.SubscribeToCharacteristic("6e40fec2-b5a3-f393-e0a9-e50e24dcca9e");
|
||||||
|
|
||||||
|
// Heart rate
|
||||||
|
errorCode = await bleHeart.OpenDevice("Avans Bike B5F0");
|
||||||
|
|
||||||
|
await bleHeart.SetService("HeartRate");
|
||||||
|
|
||||||
|
bleHeart.SubscriptionValueChanged += BleBike_SubscriptionValueChanged;
|
||||||
|
await bleHeart.SubscribeToCharacteristic("HeartRateMeasurement");
|
||||||
|
|
||||||
|
Console.Read();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void BleBike_SubscriptionValueChanged(object sender, BLESubscriptionValueChangedEventArgs e)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Received from {0}: {1}, {2}", e.ServiceName,
|
||||||
|
BitConverter.ToString(e.Data).Replace("-", " "),
|
||||||
|
Encoding.UTF8.GetString(e.Data));
|
||||||
|
|
||||||
|
string[] bytes = BitConverter.ToString(e.Data).Split('-');
|
||||||
|
string[] ANT = new string[5];
|
||||||
|
if (e.ServiceName == "6e40fec2-b5a3-f393-e0a9-e50e24dcca9e")
|
||||||
|
{
|
||||||
|
Console.WriteLine("SYNC : " + bytes[0]);
|
||||||
|
ANT[0] = bytes[0];
|
||||||
|
Console.WriteLine("LENGTH : " + bytes[1]);
|
||||||
|
|
||||||
|
int length = Convert.ToInt32(bytes[1], 16);
|
||||||
|
ANT[1] = length.ToString();
|
||||||
|
Console.WriteLine("MSG ID : " + bytes[2]);
|
||||||
|
ANT[2] = bytes[2];
|
||||||
|
string msg = string.Empty;
|
||||||
|
for (int i = 3; i < 3 + length; i++)
|
||||||
|
{
|
||||||
|
msg += bytes[i];
|
||||||
|
}
|
||||||
|
ANT[3] = msg;
|
||||||
|
|
||||||
|
Console.WriteLine("MSG : " + msg);
|
||||||
|
string checksum = bytes[3 + length];
|
||||||
|
ANT[4] = checksum;
|
||||||
|
Console.WriteLine("CHECKSUM : " + checksum);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
Console.WriteLine("BPM: " + Convert.ToInt32(bytes[1], 16));
|
||||||
|
}
|
||||||
|
Console.WriteLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,5 +4,10 @@
|
|||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="BLELibrary">
|
||||||
|
<HintPath>.\BLELibrary.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 16
|
# Visual Studio Version 16
|
||||||
VisualStudioVersion = 16.0.30413.136
|
VisualStudioVersion = 16.0.30413.136
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProftaakRH", "ProftaakRH.csproj", "{82761495-F7CD-4F52-8293-6E6AEBE6CBAF}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProftaakRH", "ProftaakRH.csproj", "{0F053CC5-D969-4970-9501-B3428EA3D777}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -11,15 +11,15 @@ Global
|
|||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{82761495-F7CD-4F52-8293-6E6AEBE6CBAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{0F053CC5-D969-4970-9501-B3428EA3D777}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{82761495-F7CD-4F52-8293-6E6AEBE6CBAF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{0F053CC5-D969-4970-9501-B3428EA3D777}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{82761495-F7CD-4F52-8293-6E6AEBE6CBAF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{0F053CC5-D969-4970-9501-B3428EA3D777}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{82761495-F7CD-4F52-8293-6E6AEBE6CBAF}.Release|Any CPU.Build.0 = Release|Any CPU
|
{0F053CC5-D969-4970-9501-B3428EA3D777}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {AD8FC239-049F-4332-A21F-76C30779630C}
|
SolutionGuid = {E8D4CDF6-747D-47AE-B655-159CEBA801D5}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
Reference in New Issue
Block a user