microsoft / WindowsAppSDK

The Windows App SDK empowers all Windows desktop apps with modern Windows UI, APIs, and platform features, including back-compat support, shipped via NuGet.
https://docs.microsoft.com/windows/apps/windows-app-sdk/
MIT License
3.82k stars 321 forks source link

PosPrinter.FromIdAsync() returns null in WinUI3 app, no pairing dialog shown #3089

Open 1888games opened 2 years ago

1888games commented 2 years ago

Describe the bug

Using XF/UWP, we are successfully using the Windows.Devices.PointOfService.PosPrinting API to connect to network receipt printers.

The PosPrinter.FromIdAsync() call will popup a dialog for the user to confirm they wish to pair with the printer. From there we claim the printer, enable, and send it a print job.

Using MAUI/WinUI3, the same code with the same 'pointOfService' capability set in the manifest returns null almost instantly. No dialog is shown. I know the printer is available because I retrieved the ID using:

DeviceInformation.FindAllAsync(PosPrinter.GetDeviceSelector(PosConnectionTypes.IP));

...and I can of course run the UWP version side by side and successfully get the PosPrinter handle using the same ID once I have confirmed using the pairing dialog.

The same happens on a vanilla WinUI3 app without using MAUI.

Steps to reproduce the bug

1) Ensure a POS printer (such as Epson TM-M30) is connected to the network. 2) Create a blank WinUI3 desktop app. 3) Add PointOfService capability to the manifest. 3) Add this method to MainWindow.xaml.cs and call PosPrinting() in the myButton_Click listener.

async void PosPrinting()
        {

            DeviceInformationCollection deviceCollection = await DeviceInformation.FindAllAsync(PosPrinter.GetDeviceSelector(PosConnectionTypes.IP));

            if (deviceCollection.Count > 0)
            {
                DeviceInformation deviceInfo = deviceCollection[0];

                PosPrinter p = await PosPrinter.FromIdAsync(deviceInfo.Id);

                if (p != null)
                {
                    Debug.WriteLine(p.DeviceId);
                }

            }
        }

p will be null.

Expected behavior

Successfully retrieve a PosPrinter object using PosPrinter.FromIdAsync(deviceInfo.Id). If first attempt to connect to the PosPrinter, first show a dialog for the user to confirm pairing.

Screenshots

PXL_20220914_140312767 MP PXL_20220914_140317970

NuGet package version

No response

Windows app type

Device form factor

Desktop

Windows version

Windows 11 (21H2): Build 22000

Additional context

Microsoft.WindowsAppSDK versions is

1.1.3 1.2.2.220902.1.-preview1

1888games commented 2 years ago

This is what happens using the same code on UWP:

PXL_20220914_141354030 MP