Klemen1337 / node-thermal-printer

Node.js module for Epson, Star, Tanca, Drauma and Brother thermal printers command line printing.
MIT License
765 stars 244 forks source link

Driver for electron application #214

Open atulatulatul opened 1 year ago

atulatulatul commented 1 year ago

What's the issue?

Hi. I just wanted to know what should be set as the driver.

I just wanted to open the cash drawer attached to the printer XP-80C (almost similar to EPSON), I've already tried the following packages:

  1. @flovy/node-printer
  2. @thiagoelg/node-printer

When using the above packages as driver whenever I execute this line of code:

printer.openCashDrawer();

The entire electron app crashes and goes blank.

https://user-images.githubusercontent.com/13715884/219932018-616f5ba0-57c6-45b6-af6f-d9977bda6071.mp4

mwsoofy commented 1 year ago

have you found any solutions or alternatives ?

adnanlah commented 6 months ago

have you found any solutions or alternatives ?

This is one of the alternatives that worked for me. My original plan is to run node-thermal-printer without @thiagoelg/node-printer because the latter didn't get installed in my electron app.

let tp = new ThermalPrinter({
    type: PrinterTypes.EPSON, // Printer type: 'star' or 'epson'
    interface: "printer:Xprinter XP-T371U", // Printer interface
    characterSet: CharacterSet.ISO8859_2_LATIN2, // Printer character set
    options: {
      timeout: 5000, // Connection timeout (ms) [applicable only for network printers] - default: 3000
    },
    driver: {}, // Empty object
  });

tp.println("Hello World"); 
tp.table(["One", "Two", "Three"])
tp.cut();

const raw = tp.getBuffer()

let device = usb.findByIds(/*vid*/8137, /*pid*/8214);
if (device) {
    device.open();
    console.log(device.interfaces?.at(0)?.endpoints)
    device.interfaces?.at(0)?.claim();
    const outEndpoint = device.interfaces?.at(0)?.endpoints.find(e => e.direction === 'out');
    if (outEndpoint) {
        outEndpoint.transferType = 2;
        outEndpoint.transfer(raw, (err) => {
            device.close();
        });
    }
}