Very simple application to run on both android and windows using Maui. Enter in some data and it will then print a receipt via a bluetooth thermal printer.
I have built a simple IPrintingService interface and two separate implementations in Platforms/Android and Platforms/Windows.
The problem is interacting with the printer in Windows
Andoid
using BluetoothManager and the BluetoothAdapter class i can find the printer, open a bluetooth socket and fire down ESC printer commands ! perfect i get my receipt.
Windows
after much research i can not find much on this subject for windows win ui3,
//get paired devices
DeviceInformationCollection PairedBluetoothDevices = await DeviceInformation.FindAllAsync(BluetoothDevice.GetDeviceSelectorFromPairingState(true));
//get the device im interested in
var device = PairedBluetoothDevices.FirstOrDefault(x=>x.Name == printerName);
strangely the device returned has Pairing.IsPaired as false, as is Pairing.CanPair ? but it was returned in the paired device list ???
await device.PairAsync(DevicePairingProtectionLevel.None) does nothing and i have also attempted to use a custom pairing request handler but strangely that returns with ‘already paired.
i was then going so use
var serialDevice = await SerialDevice.FromIdAsync(device.Id)
and from there use a datawriter to write to the serialDevice outputstream, but SerialDevice.FromIdAsync(device.Id) throws Exception thrown: ‘System.Runtime.InteropServices.COMException’ in System.Private.CoreLib.dll
I think i am approaching the window side incorrectly, any help would be much appreciated.