PosPrinter GetDefaultAsync always returns null

281 views Asked by At

I'm trying to print a ticket using .NET POS but i'm not able to get the Default printer.

 PosPrinter defaultPrinter = await PosPrinter.GetDefaultAsync();

I also tried this:

string deviceSelector =  PosPrinter.GetDeviceSelector();
PosPrinter printer = await PosPrinter.FromIdAsync(deviceSelector);

I have my thermal printer configured as default.

1

There are 1 answers

1
KBO On

Have you tried the way using the PosExplorer and the printer name? Snippet:

public PosPrinter GetPrinterByName(System.Windows.Forms.Form mainForm, string printerName)
{
  PosPrinter       printer  = null;
  PosExplorer      explorer = new PosExplorer(mainForm);
  DeviveCollection printers = explorer.GetDevices(DeviceType.PosPrinter);

  if (printers != null && printers.Count > 0)
  {
    for (int i = 0; i < printers.Count; i++)
    {
      if(0 == string.Compare(printerName, printers[i].ServiceObjectName))
      {
        printer = printers[i];
        break;
      }
    }
  }

  return printer;
}