kechankrisna / flutter_usb_printer

GNU General Public License v3.0
6 stars 50 forks source link

How to Open Cash Drawer ? #19

Open DeepakChopra0 opened 1 year ago

DeepakChopra0 commented 1 year ago

Hello,

I am using this Hex Codes to Open Cash Drawer. But its not working. Please help to fix the issue.

var data = Uint8List.fromList([0x1B, 0x70, 0x00, 0x20, 0x20]); await flutterUsbPrinter.write(data);

YXwong01 commented 1 year ago

@DeepakChopra0 any updates?

RTdevteam commented 9 months ago

use esc_pos_utils

  Future<void> openCashDrawerUSB({required USBPrinter device, required String? drawPin})async{
    // flutterUsbPrinter.connect(device.vendorId!, device.productId!);
    Map<String, dynamic> printerData = device.toJson();
    bool isOk = await checkUsbPrinter(printerData) ?? false;
    if(!isOk){
      return;
    }
    final profile = await CapabilityProfile.load();
    List<int> bytes = [];
    final Generator ticket = Generator(paper, profile);
    // Example ESC/POS command to open a cash drawer (replace with the actual command)
    // Uint8List openCashDrawerCommand = Uint8List.fromList([27, 112, 0, 50, 250]);

    // flutterUsbPrinter.close()
    if(drawPin != null && drawPin != "no"){
      PosDrawer pin = PosDrawer.pin2;
      if(drawPin == "pin2"){
        pin = PosDrawer.pin2;
      }
      if(drawPin == "pin5"){
        pin = PosDrawer.pin5;
      }
      bytes += ticket.drawer(pin: pin);
      Uint8List openCashDrawerCommand = Uint8List.fromList(bytes);
      flutterUsbPrinter.write(openCashDrawerCommand);
    }
  }