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

Multiple printers #210

Closed
diegomachado1 opened this issue May 19, 2019 · 8 comments · Fixed by #283
Closed

Multiple printers #210

diegomachado1 opened this issue May 19, 2019 · 8 comments · Fixed by #283

Comments

@diegomachado1
Copy link

diegomachado1 commented May 19, 2019

Hey guys..

I'm trying to use this module with multiples printers. But some codes aren't working.

So, I read (#23), (#173).

I tried to follow the multiple.js example. But the code for it self doesn't work for some reasons:

  1. The code use device.open(), and device isn't defined
  2. escpos.USB.findPrinter() returns this error:
TypeError: Cannot read property 'getDeviceList' of null
    at Function.USB.findPrinter

I can get findPrinter() working if I call new escpos.USB() before it. But I don't know why..

So, my final code was like this:

let device = new escpos.USB()
const devices = escpos.USB.findPrinter();

const printer = new escpos.Printer([
    devices[0],
    devices[1]
]);

device.open(function(){
    printer
    .font('a')
    .align('ct')
    .style('bu')
    .size(1, 1)
    .text('The quick brown fox jumps over the lazy dog')
    .cut()
    .close();
});

And I get this error when I try to execute it:

TypeError: this.adapter.write is not a function
    at Printer.flush

I don't know if I've misunderstood something on the docs (sorry if I did) or if the docs are wrong. But how can I get it working?

And, what is the best approach to manage different printing formats with this logic? The printers stay on different places and one need to receive less information then another.
If I have two printers with the same VID and PID I can't know what printer should receive less information, right?

@daniellizik
Copy link

It's an issue with your driver or hardware configuration

@diegomachado1
Copy link
Author

I tried this both on mac and windows. I think it's difficult to have the same problem on the two pc. But how can I have sure about it? Has some tip to fix it?

@rssk
Copy link

rssk commented Jul 26, 2019

This fails on my mac as well

@daniellizik
Copy link

This has failed for me in the past if my epson TM-T88* (V or VI) is not configured to vendor class. Sometimes it cannot be discovered if it set to printer class.

@rssk
Copy link

rssk commented Jul 26, 2019

Interesting, I've got everything working now doing it manually on a brother wide format. There are some minor command differences but wasn't hard to mess with, thanks for the library!

@smailmalki
Copy link

smailmalki commented Mar 31, 2020

my answer is (very) late
You have to do :

const escpos = require('escpos');
escpos.USB = require('escpos-usb');
var devices = escpos.USB.findPrinter();

devices.forEach(function(el) { 
    let device = new escpos.USB(el)
    const printer = new escpos.Printer(device);
    device.open(function(){
        printer
        .font('a')
        .align('ct')
        .style('bu')
        .size(1, 1)
        .text('The quick brown fox jumps over the lazy dog')
        .cut()
        .close()
    });
})

Hope it helps you

@strife-cloud
Copy link

strife-cloud commented Oct 26, 2022

Hi, to add some details about how to chose specificaly one printer, I look on object type Device the property portNumbers that is the only distinct property in the object
const devices = escpos.USB.findPrinter(); deviceChosen = devices.find(printerUSB => { return JSON.stringify(printerUSB.portNumbers) === printParam.address; });

Another improve that is looked for serial number like with the usb package:
https://www.npmjs.com/package/usb look for "Find legacy device by SerialNumber" so we can chose specifically one printer

@dohooo
Copy link

dohooo commented Oct 26, 2022

Hi, to add some details about how to chose specificaly one printer, I look on object type Device the property portNumbers that is the only distinct property in the object

`const devices = escpos.USB.findPrinter();

          deviceChosen = devices.find(printerUSB => {

            return JSON.stringify(printerUSB.portNumbers) === printParam.address;

          });`

Another improve that is looked for serial number like with the usb package:

https://www.npmjs.com/package/usb look for "Find legacy device by SerialNumber" so we can chose specifically one printer

#412

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

Successfully merging a pull request may close this issue.

6 participants