Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Driver for electron application #214

Open
atulatulatul opened this issue Feb 19, 2023 · 2 comments
Open

Driver for electron application #214

atulatulatul opened this issue Feb 19, 2023 · 2 comments

Comments

@atulatulatul
Copy link

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.

TeamViewer_9xl8UXRqI6.mp4
@mwsoofy
Copy link

mwsoofy commented Mar 9, 2023

have you found any solutions or alternatives ?

@adnanlah
Copy link

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();
        });
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants