Skip to content

Instantly share code, notes, and snippets.


Peter Foot peterfoot

View GitHub Profile
peterfoot / BluetoothComPort.cs
Last active Aug 24, 2021
enumerate the Bluetooth COM ports on desktop Windows. Determine the mappings between Bluetooth addresses and COM port names.
View BluetoothComPort.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
namespace BluetoothDiagnostics
public sealed class BluetoothComPort
peterfoot / BluetoothTest.cs
Created Apr 23, 2018
Sample Bluetooth printing from Unity
View BluetoothTest.cs
var devices = DeviceInformation.FindAll(RfcommDeviceService.GetDeviceSelector(RfcommServiceId.SerialPort));
var deviceInfo = devices[0]; // this makes some assumptions about your paired devices so really the results should be enumerated and checked for the correct device
var device = BluetoothDevice.FromDeviceInformation(deviceInfo);
var serResults = device.GetRfcommServices(BluetoothCacheMode.Cached);
foreach(RfcommDeviceService serv in serResults.Services)
if(serv.ServiceId == RfcommServiceId.SerialPort)
var stream = serv.OpenStream();
byte[] buff = System.Text.Encoding.ASCII.GetBytes("Testing\r\n");
peterfoot / NotificationMessageGeneric.cs
Created Jul 14, 2021
MvvmLight style NotificationMessage<T> for Microsoft.Toolkit.Mvvm
View NotificationMessageGeneric.cs
namespace Microsoft.Toolkit.Mvvm.Messaging.Messages
public sealed class NotificationMessage<T>
public NotificationMessage(T content, string notification)
Content = content;
Notification = notification;