grandchef / escpos-buffer

Library to generate buffer for thermal printers.
MIT License
49 stars 16 forks source link

bematech mp-4200 th miniprinter not workin #34

Closed daniloab closed 1 year ago

daniloab commented 1 year ago

I cannot use bematech mp-4200 as a printer.

the problem happens in the function when trying to connect with the printer.

static async CONNECT(
    _model: SupportedModel | Model,
    connection: Connection,
  ): Promise<Printer> {
    let model: Model;
    if (typeof _model === 'string') {
      model = new Model(_model);
    } else {
      model = _model;
    }
    await connection.open();
    model.profile.connection = connection;
    await model.profile.initialize?.();
    return new Printer(model);
  }

When calling const printer = await Printer.CONNECT(model, connection); inside the CONNECT function, the open await connection.open(); that comes from WebUsb has the param interface number with a fixed number of 0.

async open({
    configuration = 1,
    interface: interfaceNumber = 1,
  }

then, it breaks returning the same error of this issue #29.

To try to fix it, my machine has 2 interfaces. The problem is that zero doesn't work. To get around I changed the node_modules directly to 1 and the open function worked

open({ configuration = 1, interface: interfaceNumber = 1 } = {}) {

Returning and following the CONNECT function, the problem is that when calling await model.profile.initialize?.(); nothing else happens.

It has no errors or warnings.

What could be the problem? Do you have any idea how to solve it?

mazinsw commented 1 year ago

Can you provide a pull request using the answer provided in #29 suggestions?

daniloab commented 1 year ago

Can you provide a pull request using the answer provided in #29 suggestions?

What do you think could be the best solution?

Pass the interfaceNumber to connection.open() function instead of a fixed value?

And, do you have any idea why bematech didn't work?

mazinsw commented 1 year ago

fixed in v3

configuration number and interface number are now auto detected or can be passed by WebUSB constructor like:

const configuration = 2;
const interfaceNumber = 1;
const webUsb = new WebUSB(device, configuration, interfaceNumber);