CodeMinion / another_brother

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

After accepting USB permission, print doesn't continue #67

Open REI7ER opened 11 months ago

REI7ER commented 11 months ago

Hi, Can you help to me with this? I remember that from version 0.0.33 this feature stop working, I solved it using a button to execute the function again after accepting the usb permission, but I really appreciated if you can guide me, so I can handle this and avoid using the button.

Thank you. 👍

CodeMinion commented 11 months ago

Hi @REI7ER ,

Thanks for reaching out about this. That feature hasn't really been touched since the initial version so I am curious what could have made it stopped working.

The one thing to keep in mind about the USB connection is that you need to plug the cable to your phone and the printer while the printer is off, then turn on the printer.

I'll set some time aside this weekend to take a look at what could be going on. Could you help me out by giving me a bit more information about your setup like:

Thanks in advance,

REI7ER commented 11 months ago

You made me realice that this is happening only with android 13 devices, may be its something with the usb permissions in this version. I just tried with an android 11 device and it's working flawlessly. (I'm using the QL-800)

ebapp-dev commented 11 months ago

Hi REIZER, I really need help connecting a Brother QL800, via USB, to Android. I can't find any examples. Please help me.

CodeMinion commented 11 months ago

Hi @ebapp-dev ,

You can print over USB using the same configuration as with the other printers. An example may be found here: https://github.com/CodeMinion/Demo-Another-Brother/blob/main/lib/main.dart#L381C5-L388C74

In the case of USB you'll need to use the Port.USB instead. As for the QL-800 I believe you'll need to specify the QL-700 labels because there is no mapping present for the QL-800

Don't hesitate to share you configuration code if you still run into any trouble printing,

ebapp-dev commented 11 months ago

Hi CodeMinion,

Thanks for your response I still have no success. Follow the code and log.

===code===

class _QlBluetoothPrintPageState extends State<QlBluetoothPrintPage> {
  bool _error = false;

  void print(BuildContext context) async {
    //////////////////////////////////////////////////
    /// Request the Storage permissions required by
    /// another_brother to print.
    //////////////////////////////////////////////////
    if (!await Permission.storage.request().isGranted) {
      ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
        content: Padding(
          padding: EdgeInsets.all(8.0),
          child: Text("Access to storage is needed in order print."),
        ),
      ));
      return;
    }

    var printer = new Printer();
    var printInfo = PrinterInfo();
    printInfo.printerModel = Model.QL_800;
    printInfo.printMode = PrintMode.FIT_TO_PAGE;
    printInfo.isAutoCut = true;
    printInfo.port = Port.USB;
    // Set the label type.
    printInfo.labelNameIndex = QL700.ordinalFromID(QL700.W62.getId());

    // Set the printer info so we can use the SDK to get the printers.
    await printer.setPrinterInfo(printInfo);

    PrinterStatus status =
        await printer.printImage(await loadImage('assets/brother_hack.png'));
    debugPrint('==status==> ${status.toString()}');
  }

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: Center(
        // Center is a layout widget. It takes a single child and positions it
        // in the middle of the parent.
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text(
                "Don't forget to grant permissions to your app in Settings.",
                textAlign: TextAlign.center,
              ),
            ),
            Image(image: AssetImage('assets/brother_hack.png'))
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => print(context),
        tooltip: 'Print',
        child: Icon(Icons.print),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }

===LOG=== E/Brother ( 5476): PrintInfo: {binCustomPaper=null, isSpecialTape=false, rollPrinterCase={name=PJ_ROLLCASE_OFF, id=1}, customPaperLength=0, align={name=LEFT, id=1}, pjSpeed=2, isCutMark=false, printMode={name=FIT_TO_PAGE, id=2}, isCutAtEnd=true, savePrnPath=, isLabelEndCut=false, mirrorPrint=false, customFeed=0, overwrite=true, margin={top=0, left=0}, pjFeedMode={name=PJ_FEED_MODE_FIXEDPAGE, id=2}, isHalfCut=false, ipAddress=, rotate180=false, labelMargin=0, valign={name=TOP, id=1}, customPaper=, localName=, useLegacyHalftoneEngine=false, macAddress=, port={name=USB, id=1}, lastConnectedAddress=, printQuality={name=NORMAL, id=2}, pjCarbon=false, customPaperWidth=0, printerModel={name=QL_800, id=51}, labelNameIndex=15, skipStatusCheck=false, paperPosition={name=CENTER, id=2}, mode9=true, workPath=, timeout={connectionWaitMSec=500, receiveTimeoutSec=180, processTimeoutSec=-1, sendTimeoutSec=90, closeWaitMSec=500, closeWaitDisusingStatusCheckSec=3}, pjPaperKind={name=PJ_CUT_PAPER, id=2}, rawMode=false, useCopyCommandInTemplatePrint=false, peelMode=false, thresholdingValue=127, customPaperInfo=null, numberOfCopies=1, labelName={name=W62, model=QL700, id=16}, orientation={name=PORTRAIT, id=1}, isAutoCut=true, dashLine=false, rjDensity=0, softFocusing=false, scaleValue=1.0, paperSize={name=A4, id=1}, halftone={name=PATTERNDITHER, id=2}, checkPrintEnd={name=CPE_CHECK, id=3}, enabledTethering=false, banishMargin=false, trimTapeAfterData=false, pjDensity=5} E/Brother ( 5476): Parsed Info: com.brother.ptouch.sdk.PrinterInfo@d038bae

ebapp-dev commented 11 months ago

I can print in QL800. I didn't know that the "Lite Edit" LED has to be off.

CodeMinion commented 11 months ago

Hi @ebapp-dev ,

Great to hear you were able to print and thank you for the information. I had no idea there was such a feature on the printer.