andrey-ushakov / esc_pos_utils

Basic Flutter/Dart classes for ESC/POS printing
BSD 3-Clause "New" or "Revised" License
140 stars 308 forks source link

[Feature Request] USB support #45

Open sergiotucano opened 3 years ago

sergiotucano commented 3 years ago

This feature is possible? Printing in Windows / Linux USB printers.

MarcoGolin commented 3 years ago

I need that function too

A1000carZ commented 3 years ago

Same request

denisrudnei commented 2 years ago

In order to print via USB, simply write the return as if it were in a file.

Linux:

File('/dev/usb/lp0').writeAsBytes(bytes);

Windows:

 File('\\computer-name\share').writeAsBytes(bytes);

I'm using this method to communicate with the printer

Video with the system working like this: https://www.youtube.com/watch?v=NZngrlGkISU

Abdulazeezvp commented 2 years ago

Using Flutter usb printer package we can print with ESC pos printer, but problem is its not working good for images as expected, Don't know whether its the problem with esc_pos_utils package or flutter usb printer package. we can print as follows:

///list connected printers using flutter usb package
static Future<List> getAllUsbDevices() async {
    List<Map<String, dynamic>> results = [];
    results = await FlutterUsbPrinter.getUSBDeviceList();
    return results;
  }

///connect to a printer like this
 static Future<bool> connectUsbPrinter(
      {required String vendorId, required String productId}) async {
    bool? returned;
    try {
      returned = await flutterUsbPrinter.connect(
          int.parse(vendorId), int.parse(productId));
      log('device connecetd');
    } catch (e) {
      returned = false;
      log(e.toString());
      //response = 'Failed to get platform version.';
    }
    return returned ?? false;
  }

///prepare message using this package(esc pos utils)

  static Future<List<int>> prepareMessage() async {

    final profile = await CapabilityProfile.load();
    late final Generator generator;
      generator = Generator(PaperSize.mm58, profile);
    List<int> bytes = [];
    bytes += generator.text('Aa Bb Cc Dd Ee Ff Gg Hh');
    bytes += generator.cut(mode: PosCutMode.partial);
    return bytes;
  }

///print message with help of flutter usb printer package.
 static Future<void> doPrint() async {
    List<int> list = await prepareMessage();
        try {
      await flutterUsbPrinter.write(Uint8List.fromList(list));
    } catch (e) {
      log('catch ' + e.toString());
    }
  }
samo92 commented 2 years ago

Hi everyone, I have the same problem too, does anyone have a suggestion regarding this issue? My printer is an Epson TM-T88V, and it only has an USB and ecom port to communicate with my computer.

Abdulazeezvp commented 2 years ago

@samo92 my suggestion is, you can use pos_printer_manager(git repo) (In pub.dev) package, which is a intergrated solution for usb, bluetooth and network. And its working good. (Pos printer manager is devleoped with help of utils package). In some new printers, you might have to use image bit raster option.

samo92 commented 2 years ago

Oh noooo! flutter web is not supported, i make a quick sample to test the repo.