Yahalom Software
Yahalom Software

Reputation: 724

Flutter and Xprinter on bluetooth not printing

I am trying to print to Xprinter 365B 80mm thermal printer through Bluetooth on flutter (unsing an Android device - check multiple devices) and cannot get it to print.

The printer is working fine with native Android / IOS applications by xprintertech.com in both through bluetooth,

I have managed to connect/disconnect with the printer, but nothing happens, the app is notifying the command sent to the printer, sending any type of data, including text/image/esc codes. No error massage, just not printing.

I have implemented numerous libraries from pub dev for Bluetooth printers like:

One assumption I have is that it is all about the configuration of the printing mode,

In one of the apps I found a way to select "Mode", it has 3 different modes:

My printer is printing only when working with TSC mode

I believe if I could set the mode in the code, I will be able to print, but I didn't figure out a way to do it.

Here are relevant parts of the code I am using (with print_bluetooth_thermal / esc_pos libraries from pub.dev)

Query Bluetooth devices:

Future<void> getBluetoothDevices() async {
  final List<BluetoothInfo> listResult =
    await PrintBluetoothThermal.pairedBluetooths;
  if (listResult.isEmpty) {
    _msg =
      "There are no bluetooth devices linked, go to settings and link the printer";
  } else {
    _msg = "Touch an item in the list to connect";
  }
  setState(() {
    items = listResult;
  });
}

Connect with the printer

Future<void> connect(String mac) async {
  setState(() {
    _connecting = true;
  });
  final bool result =
    await PrintBluetoothThermal.connect(macPrinterAddress: mac);
  print("state connected $result");
  if (result) connected = true;
  setState(() {
    _connecting = false;
  });
}

print a full ticket:

Future<List<int>> testTicket() async {
  List<int> bytes = [];
  final profile = await CapabilityProfile.load();
  final generator = Generator(PaperSize.mm58, profile);
  bytes += generator.reset();
  final ByteData data = await rootBundle.load('assets/myLogo.jpg');
  final Uint8List bytesImg = data.buffer.asUint8List();
  final image = img.decodeImage(bytesImg);
  bytes += generator.image(image!);
  bytes += generator.text(
     'Regular: aA bB cC dD eE fF gG hH iI jJ kK lL mM nN oO pP qQ rR sS tT uU vV wW xX yY zZ',
     styles: const PosStyles());
  bytes += generator.text('Special 1: ñÑ àÀ èÈ éÉ üÜ çÇ ôÔ',
      styles: const PosStyles(codeTable: 'CP1252'));
  bytes += generator.text(
    'Special 2: blåbærgrød',
    styles: const PosStyles(codeTable: 'CP1252'),
  );

  bytes += generator.text('Bold text', styles: const PosStyles(bold: true));
  bytes +=
      generator.text('Reverse text', styles: const PosStyles(reverse: true));
  bytes += generator.text('Underlined text',
      styles: const PosStyles(underline: true), linesAfter: 1);
  bytes += generator.text('Align left',
      styles: const PosStyles(align: PosAlign.left));
  bytes += generator.text('Align center',
      styles: const PosStyles(align: PosAlign.center));
  bytes += generator.text('Align right',
      styles: const PosStyles(align: PosAlign.right), linesAfter: 1);

  bytes += generator.row([
    PosColumn(
      text: 'col3',
      width: 3,
      styles: const PosStyles(align: PosAlign.center, underline: true),
    ),
    PosColumn(
      text: 'col6',
      width: 6,
      styles: const PosStyles(align: PosAlign.center, underline: true),
    ),
    PosColumn(
      text: 'col3',
      width: 3,
      styles: const PosStyles(align: PosAlign.center, underline: true),
    ),
  ]);

  //barcode
  final List<int> barData = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 4];
  bytes += generator.barcode(Barcode.upcA(barData));

  //QR code
  bytes += generator.qrcode('example.com');

  bytes += generator.text(
    'Text size 50%',
    styles: const PosStyles(
      fontType: PosFontType.fontB,
    ),
  );
  bytes += generator.text(
    'Text size 100%',
    styles: const PosStyles(
      fontType: PosFontType.fontA,
    ),
  );
  bytes += generator.text(
    'Text size 200%',
    styles: const PosStyles(
      height: PosTextSize.size2,
      width: PosTextSize.size2,
    ),
  );

  bytes += generator.feed(2);
  //bytes += generator.cut();
  return bytes;
}

Upvotes: 0

Views: 3003

Answers (1)

AMTP G
AMTP G

Reputation: 1

print label(tsc) (i use xprinter for print ticket) https://github.com/e3m-software/bluetooth_x_print

Upvotes: 0

Related Questions