CodeMinion / another_brother

Another Brother Flutter SDK
BSD 3-Clause "New" or "Revised" License
21 stars 21 forks source link

USB devices not showing #26

Closed smaharjan974 closed 2 years ago

smaharjan974 commented 2 years ago

How to show the list of devices throught the USB?

CodeMinion commented 2 years ago

Hey @smaharjan974 !

Thanks for reaching out about this. The library does not include an API for listing the USB devices and it instead prints to a single connected printer via USB.

If you have having trouble printing to a printer connected over USB make sure to check the following:

  1. You are using an OTG cable.
  2. Your device support OTG.
  3. You are connecting your device to your printer over USB while the printer is off, and then turning the printer on.

In my experience if you connect the USB cable while the printer is on, the device will not find the printer.

Hope this helps but please don't hesitate to reach out anytime if you are still having any trouble,

smaharjan974 commented 2 years ago

Hello @CodeMinion I have tired as you said. And My device support the OTG and i have successfully connect with another dependencies. Can you show the demo code to print through USB? I am using QL_800 brother printer.

Future<List> getMyNetworkPrinters() async { Printer printer = new Printer(); PrinterInfo printInfo = new PrinterInfo(); printInfo.port = Port.USB;

await printer.setPrinterInfo(printInfo);
return printer.getNetPrinters([
  Model.QL_1110NWB.getName(),
  Model.PJ_773.getName(),
  Model.QL_800.getName(),
  Model.QL_810W.getName(),
  Model.QL_820NWB.getName()
]);

}

From this above code i always got No printer found.

CodeMinion commented 2 years ago

Hey @smaharjan974 !

After you set the port to USB you should just be able to call one of the print functions. You are not getting any printers because the getNetPrinters() function is for getting a list of printers to connect over WiFi.

Here is a short sample for printing over USB using a QL-1110NWB and a W103 roll.

var printer = new Printer();
var printInfo = PrinterInfo();
printInfo.printerModel = Model.QL_1110NWB;
printInfo.printMode = PrintMode.FIT_TO_PAGE;
printInfo.isAutoCut = true;

printInfo.port = Port.USB;
printInfo.labelNameIndex = QL1100.ordinalFromID(QL1100.W103.getId());
await printer.setPrinterInfo(printInfo);

PrinterStatus status = await printer.printImage(picture);