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();
|
||||
}
|
||||
}
|
||||
}
|
||||
13
ProftaakRH/ProftaakRH.csproj
Normal file
13
ProftaakRH/ProftaakRH.csproj
Normal file
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="BLELibrary">
|
||||
<HintPath>.\BLELibrary.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
25
ProftaakRH/ProftaakRH.sln
Normal file
25
ProftaakRH/ProftaakRH.sln
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.30413.136
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProftaakRH", "ProftaakRH.csproj", "{0F053CC5-D969-4970-9501-B3428EA3D777}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{0F053CC5-D969-4970-9501-B3428EA3D777}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0F053CC5-D969-4970-9501-B3428EA3D777}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0F053CC5-D969-4970-9501-B3428EA3D777}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0F053CC5-D969-4970-9501-B3428EA3D777}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {E8D4CDF6-747D-47AE-B655-159CEBA801D5}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
12
ProftaakRH/Program.cs
Normal file
12
ProftaakRH/Program.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
|
||||
namespace ProftaakRH
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello World!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user