1
0
mirror of https://github.com/DarthAffe/OBD.NET.git synced 2025-12-13 09:18:31 +00:00

Implemented predefined bluetooth device

This commit is contained in:
Roman Lumetsberger 2017-05-08 22:35:48 +02:00
parent 03b28b2af0
commit 2c5d90140c

View File

@ -6,6 +6,7 @@ using OBD.NET.Common.Communication.EventArgs;
using Windows.Devices.Bluetooth.Rfcomm; using Windows.Devices.Bluetooth.Rfcomm;
using Windows.Networking.Sockets; using Windows.Networking.Sockets;
using Windows.Storage.Streams; using Windows.Storage.Streams;
using System.Linq;
namespace OBD.NET.Communication namespace OBD.NET.Communication
{ {
@ -88,8 +89,22 @@ namespace OBD.NET.Communication
//use first serial service //use first serial service
if (services.Count > 0) if (services.Count > 0)
{ {
// Initialize the target Bluetooth BR device var id = services[0].Id;
var service = await RfcommDeviceService.FromIdAsync(services[0].Id);
//use predefined device from constructor
if (!string.IsNullOrWhiteSpace(device))
{
id = services.Where(x => x.Name.Equals(device, StringComparison.OrdinalIgnoreCase))
.Select(x => x.Id).FirstOrDefault();
if (id == null)
{
throw new InvalidOperationException($"Device {device} not found");
}
}
// Initialize the target Bluetooth device
var service = await RfcommDeviceService.FromIdAsync(id);
// Check that the service meets this App's minimum requirement // Check that the service meets this App's minimum requirement