Giter Club home page Giter Club logo

node-escpos's Introduction

ESCPOS PROJECT

ESC/POS Printer driver for Node.js

npm version Build Status

NPM

Packages Available:

Example

const escpos = require('escpos');
// install escpos-usb adapter module manually
escpos.USB = require('escpos-usb');
// Select the adapter based on your printer type
const device  = new escpos.USB();
// const device  = new escpos.Network('localhost');
// const device  = new escpos.Serial('/dev/usb/lp0');

const options = { encoding: "GB18030" /* default */ }
// encoding is optional

const printer = new escpos.Printer(device, options);

device.open(function(error){
  printer
  .font('a')
  .align('ct')
  .style('bu')
  .size(1, 1)
  .text('The quick brown fox jumps over the lazy dog')
  .text('敏捷的棕色狐狸跳过懒狗')
  .barcode('1234567', 'EAN8')
  .table(["One", "Two", "Three"])
  .tableCustom(
    [
      { text:"Left", align:"LEFT", width:0.33, style: 'B' },
      { text:"Center", align:"CENTER", width:0.33},
      { text:"Right", align:"RIGHT", width:0.33 }
    ],
    { encoding: 'cp857', size: [1, 1] } // Optional
  )
  .qrimage('https://github.com/song940/node-escpos', function(err){
    this.cut();
    this.close();
  });
});
  • See ./examples for more examples.

Screencast

img_1031


Contributing

  • Fork this repo
  • Clone your repo
  • Install dependencies
  • Checkout a feature branch
  • Feel free to add your features
  • Make sure your features are fully tested
  • Open a pull request, and enjoy <3

Contributors

Thanks to our contributors 🎉👏


MIT license

Copyright (c) 2015 ~ now Lsong [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


node-escpos's People

Contributors

2ec0b4 avatar askeroff avatar atton16 avatar danielruf avatar deka58 avatar dominik-korsa avatar f1mp3r avatar fethisu avatar jamie3 avatar jdckl avatar jor3l avatar lbarthon avatar mln4you avatar moegoewetter avatar mrcsxsiq avatar mreis1 avatar nadbm avatar ozgursel avatar pcapanna avatar pfirpfel avatar psychopoulet avatar pyrliu avatar risleylima avatar sinanmtl avatar song940 avatar techana avatar toadums avatar uyu423 avatar windastella avatar zch622 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-escpos's Issues

Example not working - truncated image qrcode

Hello,

thank you for the project.

I've tried the following snippet with both USB and Serial device connection
image

the result is a truncated qrcode. (Every time at the same spot) .... I'm not sure if that's a bug in raster process or just a communication issue somewhere.
image

cannot print single image

const image = (uri,location) => new Promise((resolve,reject) => {
  const device  = new escpos.USB(uri);
  const printer = new escpos.Printer(device);
  escpos.Image.load(__dirname + '/google.png', function(image){
    device.open(function(){
      printer
      .image(image)
      .cut()
    })
  })
})

I cannot print single image. I write the code as you shown in example. When I print a series of image, it is work. But When I print only one image, got the printer error and image is corrupted. My Printer is "bixolon srp-350iii".

Error:LIBUSB_ERROR_NOT_SUPPORTED on Windows

1-https://github.com/tessel/node-usb

Windows

Use Zadig to install the WinUSB driver for your USB device. Otherwise you will get LIBUSB_ERROR_NOT_SUPPORTED when attempting to open devices.

http://zadig.akeo.ie/
下载安装

2-http://zadig.akeo.ie/
下载安装配置好驱动之后
isKernelDriverActive
Error:LIBUSB_ERROR_NOT_SUPPORTED

参考:
http://libusb.sourceforge.net/api-1.0/group__dev.html

int libusb_detach_kernel_driver ( libusb_device_handle * dev,
int interface_number
)

This functionality is not available on Darwin or Windows.
LIBUSB_ERROR_NOT_SUPPORTED on platforms where the functionality is not available

Libusb issue when initializing the library

Hi!

I was getting this issue when running your sample program:

sami@jevich:~/Documents/projects/infodispenser$ node test_node_escpos.js 
/home/sami/node_modules/escpos/node_modules/usb/usb.js:168
    this.device.__claimInterface(this.id)
                ^

Error: LIBUSB_ERROR_BUSY
    at Error (native)
    at Interface.claim (/home/sami/node_modules/escpos/node_modules/usb/usb.js:168:14)
    at /home/sami/node_modules/escpos/adapter/usb.js:22:11
    at Array.forEach (native)
    at USB.open (/home/sami/node_modules/escpos/adapter/usb.js:21:26)
    at new Printer (/home/sami/node_modules/escpos/printer.js:12:16)
    at Object.<anonymous> (/home/sami/Documents/projects/infodispenser/test_node_escpos.js:4:17)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)

After a little bit of research, I solved the problem by opening adapter/usb.js and moving the "iface.claim();" to after the try/catch. This seems to work for me! I'm not sure that this is the "right" way to solve the problem though.

Thanks for your great work!

sorry but i can´t do that

I'm sorry it's my fault, I'm new to this, I ran the zadig program, select the printer, wait for it to finish and close the program, run the server.js and tell me that it can not find the printer, look for this problem but without success , Any idea of my error, thank you very much.

Suggestions for JavaScript convention rules, including eslint

Thank you very much for letting me work together as a collaborator. But I will not push it directly into the master branch. All commits will be made through pull requests.

I think we should set coding rules for our escpos package. And I hope to have a serious discussion on this topic. In fact, I was very embarrassed when I first checked the source code for the escpos package. Because it was the first coding rule to be born and born.

I personally would like to follow the coding rules that are common to many developers around the world. For example, JavaScript coding conventions such as eslint-config-airbnb will be very powerful and effective rules. If we follow Airbnb 's coding rules, I think external developers will be a little easier to contribute to our open source.

We have drawn some coding styles that will change if we follow the rules of airbnb.

printer.js (1~10 line)

image

Printer.prototype.align

image

Printer.prototype.size

image

Printer.prototype.image

image

Network.prototype.open

image

All of the above changes are the result of using eslint's auto-fix feature. Eslint shows me that there are 162 problems left after auto-fix.

image

I have committed the automatically modified source code to my private repository branch. Ask for confirmation. (https://github.com/uyu423/node-escpos/tree/feature/eslint-airbnb)

I have not tried the actual test because it is still a suggested step. We need to verify the compatibility of Airbnb's rules with each version of Node.js, and it's a matter to consider which version to support. If Airbnb's rules cause big problems with package compatibility, we can use Google or Standard JavaScript rules instead of Airbnb. Even if we can not use everything, we should at least specify a minimum rule like express.js. (https://github.com/expressjs/express/blob/master/.eslintrc)

I want to hear feedback.

Print accent (é - è - ù - ...)

Hi, currently working on a NodeJS app. I would like to print accent, but I'm not able to made it work, only printing some weirds symbols. I do try with different encoding (UTF-8, Windows-1250, ...), but same issue.

Here is my code :

// Include lib
var escpos = require('escpos');

// Define device and printer
const device = new escpos.Serial('COM1');
const printer = new escpos.Printer(device);

// Open connection
device.open(function(){
     printer
      .font('a)
      .align('lt')
      .style('normal')
      .text('Héllô Wùrldè', 'UTF-8');
});

According to comments in printer.js, method text can only print alpha-numeric value, but method print and println do not have\use encoding parameter.

Any help would be appreciate !

Can not find printer

Hi, I am using this in my electron app. Name of the printer is Epson TM-T20 and I have connected using a usb. Module is not able to find my printer where as test printer button is working in my printer settings.

Here is my code :-

const escpos = require('escpos');
const device = new escpos.USB();
console.log(device.getDevices());

Setting the margins does not work

Hi, I'm trying to have my text not be so close to the edges of my receipt, but it does not seem to be working. Here is the code I am running

const escpos = require('escpos');
 
const device  = new escpos.USB();

const printer = new escpos.Printer(device);

function printItems(items){
  device.open(function(){
    printer.font('a')
      .style('NORMAL')
      .size(1,1);
    items.forEach(function(item) {
      printer.align("LT")
        .marginLeft('8')
        .marginRight('8')
        .marginBottom('8')
        .print(item["name"])
        .control("HT")
        .println(parseFloat(item["price"]));
    });
  });
}

var items = [
  {"name": "hotdog",
    "price" : 2.01}
];
printItems(items);

device.open(function(){
  printer.cut();
  printer.close();
});

When the receipt prints, the text is right up against the left and bottom edges (the text is not long enough to reach the right edge).

SyntaxError on node v5.10.1

/var/wifi/dist/backend/node_modules/escpos/adapter/usb.js:21                                                                                                                  
  this.device.interfaces.forEach(function(interface){                                                                                                                         
                                          ^^^^^^^^^                                                                                                                           

SyntaxError: Unexpected strict mode reserved word                                                                                                                             
    at exports.runInThisContext (vm.js:53:16)                                                                                                                                 
    at Module._compile (module.js:387:25)                                                                                                                                     
    at Object.Module._extensions..js (module.js:422:10)                                                                                                                       
    at Module.load (module.js:357:32)                                                                                                                                         
    at Function.Module._load (module.js:314:12)                                                                                                                               
    at Module.require (module.js:367:17)                                                                                                                                      
    at require (internal/module.js:16:19)                                                                                                                                     
    at Object.<anonymous> (/var/wifi/dist/backend/node_modules/escpos/index.js:8:21)                                                                                          
    at Module._compile (module.js:413:34)                                                                                                                                     
    at Object.Module._extensions..js (module.js:422:10)                   

node v5.10.1
npm v3.8.3

'Can not find endpoint from printer' error message on printer having 'out' endpoint

I get 'Can not find endpoint from printer', so I debugged and found that there is interface having endpoint with direction=out.

I have tested on windows, not sure for other platforms.

I believe the issue is in following code:
https://github.com/song940/node-escpos/blob/master/adapter/usb.js#L77
where iface.setAltSetting is called, this is async function and returns immediately, this leaves endpoints empty and leads to the explained error.

LIBUSB_ERROR_NOT_FOUND

系统环境 win10 x64 nodejs 4.6
打印机是 佳博t2120 小票打印机
npm i 过程没有报错,但是运行下面的命令就报错

D:\work\nodejs\node-escpos>node examples/image.js
events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: LIBUSB_ERROR_NOT_FOUND
    at Error (native)
    at Device.usb.Device.open (D:\work\nodejs\node-escpos\node_modules\usb\usb.js:33:7)
    at USB.open (D:\work\nodejs\node-escpos\adapter\usb.js:77:15)
    at D:\work\nodejs\node-escpos\examples\image.js:9:10
    at D:\work\nodejs\node-escpos\image.js:51:5
    at D:\work\nodejs\node-escpos\node_modules\get-pixels\node-pixels.js:22:5
    at null.<anonymous> (D:\work\nodejs\node-escpos\node_modules\get-pixels\node_modules\pngjs\lib\png.js:74:7)
    at g (events.js:260:16)
    at emitOne (events.js:77:13)
    at emit (events.js:169:7)

下面是运行npm i的log

D:\work\nodejs\node-escpos>npm i
-
> [email protected] install D:\work\nodejs\node-escpos\node_modules\serialport
> node-pre-gyp install --fallback-to-build

[serialport] Success: "D:\work\nodejs\node-escpos\node_modules\serialport\build\Release\serialport.node" is installed via remote

> [email protected] install D:\work\nodejs\node-escpos\node_modules\usb
> node-pre-gyp install --fallback-to-build

[usb] Success: "D:\work\nodejs\node-escpos\node_modules\usb\src\binding\usb_bindings.node" is installed via remote
[email protected] node_modules\mutable-buffer

[email protected] node_modules\iconv-lite

[email protected] node_modules\qr-image
└── [email protected]

[email protected] node_modules\get-pixels
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])

[email protected] node_modules\serialport
├── [email protected]
├── [email protected] ([email protected])
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected], [email protected])
└── [email protected] ([email protected])

[email protected] node_modules\usb
└── [email protected]

Error: Can not find printer

Hi,
I'm trying to print from node.js to a Epson Tm-T70II thermal printer connect with an usb cable.
I get the error "Error: Can not find printer" when trying the index.js. The printer is working. Even configured in cups, and i can print with another module (just not images/logos).
Can someone help, please?
Thank you

Help with escpos

Hello,

I am using your node escape pos driver to use with a Star termal printer. I have a problem with USB code that I can’t understand. First time I open the device, it works but no more works in next printing.

This is my code:

var escpos = require('escpos');
var device  = new escpos.USB();
var printer = new escpos.Printer(device);

app.post('/api/printer', function(req, res) {   
  var data = req.body;
  try{
    escpos.Image.load(data.img, function(image){          
      device.open(function(){
        printer
        .align('ct')
        .image(image, 's8')
        .cut(false, 3)
        .close(function(){
        });                                       
      });             
      res.json();
    });
  }catch(e){
    console.log("device.open error: ", e);
    res.json();
  }   
});

First time self.endpoint = null so everything is ok but next call, self.endpoint is filled so never call again callback function. What’s the trick? I tried closing device but is the same behaviour.

Can you help me please? What’s wrong?

Thanks in advance.
Víctor
Enviado desde Correo para Windows 10

Why does Adapter.close () and buffPrint () run at the same time

Printer.prototype.close = function(callback){
  var self = this;
  return this.flush(function(){
    self.adapter.close(callback);
  });
};

I am using escpos as a serial port, but the adapter is not open automatically after the first print is completed, which is causing problems. If you do not close the adapter, it does not seem to be a problem. Is there a reason to keep it close? I am annotating the self.adapter.close(callback); part and using it.

image

I will modify the code as follows.

Printer.prototype.close = function(callback){
  var self = this;
  return this.flush(function(){
    if (!(self.adapter instanceof Serial)) {
      self.adapter.close(callback);
    }
  });
};

LIBUSB_ERROR_ACCESS

I am new to Linux, and im not sure how to solve a problem.
:
Error: LIBUSB_ERROR_ACCESS
at Error (native)
at Device.usb.Device.open (/home/alejandro/node_modules/usb/usb.js:33:7)
at USB.open (/home/alejandro/node_modules/escpos/adapter/usb.js:81:15)
at Object. (/home/alejandro/Dropbox/scripts/nodejs/escpos.js:9:8)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)

I would like to know why I have this problem, I use UBUNTU and I followed the instruction "sudo apt-get install build-essential libudev" that apears in the documantation.

Can you help me resolve this problem? And perhaps show me step by step.
Thanks*

I think this is not really a good logic !

Printer.prototype.size = function(width, height) {
  if (2 >= width && 2 >= height) {
    this.buffer.write(_.TEXT_FORMAT.TXT_NORMAL);
    if (2 == width && 2 == height) {
      this.buffer.write(_.TEXT_FORMAT.TXT_4SQUARE);
    } else if (1 == width && 2 == height) {
      this.buffer.write(_.TEXT_FORMAT.TXT_2HEIGHT);
    } else if (2 == width && 1 == height) {
      this.buffer.write(_.TEXT_FORMAT.TXT_2WIDTH);
    }
  } else {
    this.buffer.write(_.TEXT_FORMAT.TXT_CUSTOM_SIZE(width, height));
  }
  return this;
};

i found this just a moment ago and try to fix this logic here, but i know what you want to express .

USB Adapter, cannot close / disconnecting adapter

My index.js

const escpos = require('escpos');

const device  = new escpos.USB();
const printer = new escpos.Printer(device);

device.open(() => {
  printer
    .text('Hello World')
    .feed()
    .cut()
    .close(() => {
      console.log('Close')
    })
});

I run via terminal

node index.js

Everything is OK... just script not stop, need to press Ctrl + c to stop it,
and close's callback never called.

I try change using Serial. work properly.

Note:

  • OS: Ubuntu 16.04
  • Node: 6.10.2

Setting barcode height and width not working

Setting barcode height and width is not working.
In fact the code isn't doing anything with width and height parameters other than checking them for then to use a default some default.

I made a working solution.

Changed in printer.js barcode prototype function:

Printer.prototype.barcode = function(code, type, width, height, position, font){
  if(width >= 2 || width <= 6){
    this.buffer.write(_.BARCODE_FORMAT.BARCODE_WIDTH[width]);
  }else{
    this.buffer.write(_.BARCODE_FORMAT.BARCODE_WIDTH_DEFAULT);
  }
  if(height >=1  || height <= 255){
    this.buffer.write(_.BARCODE_FORMAT.BARCODE_HEIGHT(height));
  }else{
    this.buffer.write(_.BARCODE_FORMAT.BARCODE_HEIGHT_DEFAULT);
  }

and changed some things in commands.js, all barcode size related stuff. Had to add a function for barcode_height in fact to not have a large 255 size array:

  BARCODE_HEIGHT  : function(height){
    return '\x1d\x68'+String.fromCharCode(height);
  },
  BARCODE_HEIGHT_DEFAULT: '\x1d\x77\x64',

  BARCODE_WIDTH  : { // Barcode Width  [1-5]
      1: '\x1d\x77\x02',
      2: '\x1d\x77\x03',
      3: '\x1d\x77\x04',
      4: '\x1d\x77\x05',
      5: '\x1d\x77\x06'
  } ,
  BARCODE_WIDTH_DEFAULT: '\x1d\x77\x03',

Acording to ESC/POS documentation you can set height from 1 to 255. But don't know why my ESC/POS printer only works with values from like 10 to 128 (which is more than enough for me), other values I get printed 'UNDEFINED'. It could be that my printer does not support all sizes or that I'm not understanding or doing something correctly. It is something to be aware.. It would be great if someone else could test this.

Image support?

Hi, first of all, great module, it's a very impressive project to port all the escpos functionalities to JS.

I was wondering if you had any plans to add image printing support? I currently spawn a python script to do the image processing part, but that's not entirely a native solution.

Barcodes are not printed (only works with EAN8)

Hi, I'm having problems when printing barcodes. I just changed the barcode type on the example code, but no luck. My printer is an EPSON TM-T20II and according to the documentation it supports all the barcode formats available in your code. I hope you can help me find out what's happening.

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

text height not working

When setting other sizes other than 1x1, 1x2, 2x1 or 2x2, text height is always 1, and width whatever you put on it.

I had to add a function on commands.js.. but it works fine and I didn't have to add 64 lines of literals possibilities.

I changed/added on commands.js:

_.TEXT_FORMAT = {
  ...
  TXT_OTHER_SIZE  : function(width, height){ // other sizes
    var charsPreSize = '\x1d\x21';
    var decWidth = (width - 1) * 16;
    var decHeight = height - 1;
    var charPostSize = String.fromCharCode(decWidth+decHeight)
    return charsPreSize + charPostSize;
  },

And on printer.js on size function:

Printer.prototype.size = function(width, height) {

  if (2 >= width && 2 >= height) {
    ...
  }
  else {
    this.buffer.write(_.TEXT_FORMAT.TXT_OTHER_SIZE(width,height));
  }

can not work with node/6.2.2

module.js:568
return process.dlopen(module, path._makeLong(filename));
^

Error: Module version mismatch. Expected 48, got 46.
at Error (native)
at Object.Module._extensions..node (module.js:568:18)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at Object. (/Users/oneway/GitLab/2016/MkCRM/batch/node_modules/escpos/node_modules/usb/usb.js:5:38)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)

Print without qrimage

Hello,
I'm trying to print a text without qrimage. But sometimes, it gives me following error:

/Users/emrealparslan/Projects/print-server/node_modules/usb/usb.js:43
	this.__close()
	     ^

Error: Can't close device with a pending request
    at Error (native)
    at Device.usb.Device.close (/Users/emrealparslan/Projects/print-server/node_modules/usb/usb.js:43:7)
    at USB.close (/Users/emrealparslan/Projects/print-server/node_modules/escpos/adapter/usb.js:141:15)
    at OutEndpoint.<anonymous> (/Users/emrealparslan/Projects/print-server/node_modules/escpos/printer.js:430:18)
    at Transfer.callback (/Users/emrealparslan/Projects/print-server/node_modules/usb/usb.js:362:14)

Here is my print function:

function print(p, text) {
const escpos = require('escpos');

// Select the adapter based on your printer type
const device = new escpos.USB(p.vendorId, p.productId);
const printer = new escpos.Printer(device);
device.open(function() {
    printer
        .font('a')
        .style('bu')
        .align('ct')
        .size(1, 1)
        .text(text);
    printer.cut();
    printer.close();
});
};

Is there a way printing without 'qrimage'. Because it seems only 'qrimage' has a function to cut&close.

npm install in raspberry

Somehow I cant't install the dependencies for this npm, specifically [email protected] install.

I don't need any usb libraries since I'm planing to use only network connections (which it now works perfect, tested in macOS).

is there any work around?

LIBUSB_ERROR_BUSY error

I'm getting an error LIBUSB_ERROR_BUSY when I restart the module after print.

/print-server/node_modules/usb/usb.js:168
	this.device.__claimInterface(this.id)
	            ^

Error: LIBUSB_ERROR_BUSY
    at Interface.claim (/print-server/node_modules/usb/usb.js:168:14)
    at Interface.<anonymous> (/print-server/node_modules/escpos/adapter/usb.js:99:15)
    at Device.<anonymous> (/print-server/node_modules/usb/usb.js:225:6)

As a workaround, I put some code that fixed this.

adapter/usb.js:

/**
 * [open usb device]
 * @param  {Function} callback [description]
 * @return {[type]}            [description]
 */
USB.prototype.open = function (callback, i){
  let self = this, counter = 0, index = i || 0;
  this.device.open();
  this.device.interfaces.forEach(function(iface){
    (function(iface){
      iface.setAltSetting(iface.altSetting, function(){

        // ---------------------------------------------
        // Put this code here to avoid LIBUSB_ERROR_BUSY
        // ---------------------------------------------
        if(iface.isKernelDriverActive()) {
          try {
            iface.detachKernelDriver();
          } catch(e) {
            console.error("[ERROR] Could not detatch kernel driver: %s", e)
          }
        }

        iface.claim(); // must be called before using any endpoints of this interface.
        iface.endpoints.filter(function(endpoint){
          if(endpoint.direction == 'out' && !self.endpoint) {
            self.endpoint = endpoint;
            self.devices[index]._endpoint = endpoint; // store each endpoint for later
          }
        });

        if(self.endpoint) {
          self.emit('connect', self.device);
          callback && callback(null, self);
        } else if(++counter === this.device.interfaces.length && !self.endpoint){
          callback && callback(new Error('Can not find endpoint from printer'));
        }
      });
    })(iface);
  });

  return this;
};

My print code is something like this:

var device  = new escpos.USB(vid, pid);
var printer = new escpos.Printer(device);

device.open(function() {
  printer
    .font('b')
    .align('lt')
    .text('print some text here', 'cp860')
    .control('lf');

  // Performs some iterations and formatting

  printer
    .control('lf')
    .text('another formatted text', 'cp860')
    .control('lf')
    .cut()
    .close();
});

Am I doing something wrong or forgetting something?

Thanks in advance for any help.

Barcode issues (again)

So EAN-8 barcodes print great but they are very limited vs something like UPC-A or CODE128.

Using an EPSON TM-T88III which according to the technical reference guide (http://www.i-o.cz/user/upload/TM88%20III/l7O-TM-T88II_TechnicalRefGuide.pdf) supports UPC-A, CODE128 and the other types supported by this library.

But all I get is blank spaces where the barcode should go (like the printer is seeing a barcode is trying to be printed but fails to generate it) when I try to print anything other than EAN-8

I doubt it is a hardware issue as judging by another issue someone had with an EPSON TM-T20 only printing EAN-8 barcodes it must just be some incompatibility with EPSON printers.

Any one have any ideas for a fix. generating images is not possible simply because they take ages to print and is harder to code for (me like simple)

Suggestions for version-specific release archives

The current version of escpos is still being updated, but the number in the release tab of the repository is zero. I think it's a good idea to use releases and tags when certain versions are fixed.

When the version is fixed, the release update, including the tag and the update history, has a great advantage in checking the update history later.

I would like to hear comments on this issue.

Strange behavior after barcode output. And other things

  1. The alignment or font size does not work properly after outputting the barcode. Are there any expected problems? And what exactly is the role of marginBottom? There is no margin under the barcode.
if (options.barcode) {
  const defaultBarcode = '100000000000'; // length 12
  const baseBarcode = `${defaultBarcode.substring(0, defaultBarcode.length - order.id.length)}${order.id}`;
  printer.align('ct').barcode(`${baseBarcode}${getParityEAN13(baseBarcode)}`, 'EAN13').marginBottom(20);
}

printer.align('rt').size(1, 1).text(moment().format('YYYY-MM-DD HH:mm:ss'), 'CP949');
printer.size(2, 2).cut();

image

  • Exception handling is likely to be needed for the length of the barcode string. If the length of the barcode parameter is not correct or there is a problem, it just does not print. It seems to require an error message.

  • I have a code for parity bit, which is the last bit of EAN13. Will Pull Request help?

Is TSC command supported ?

标签打印机和小票打印机的命令不同,比如需要设置纸张的长度宽度以及两张标签之间的间隙,不知如何通过node-ecspos发送这类指令,我试过node-printer到目前为止还没有成功,只能识别ecs/pos指令。

unable to install node-escpos

I am trying to install node-escpos using followind command on windows 7 x32

npm install node-escpos --save

But unfortunately got bunch of errors....

D:\testndelete\testThird>npm install node-escpos --save

[email protected] install D:\testndelete\testThird\node_modules\iconv
node-gyp rebuild

D:\testndelete\testThird\node_modules\iconv>if not defined npm_config_node_gyp (node "C:\Users\xz\AppData\Roaming\nvm\v0.12.7\node_modules\npm\bin\node-gyp-bin....\nod
e_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node rebuild )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Project file contains ToolsVersion="14.0". This toolset may be unknown or missing, in which case you may be able to resolve this by installing the appropriate version of
MSBuild, or the build may have been forced to a particular ToolsVersion for policy reasons. Treating the project as if it had ToolsVersion="4.0". For more information,
please see http://go.microsoft.com/fwlink/?LinkId=291333.
C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\Microsoft.Cpp.Win32.Targets(511,5): error MSB8008: Specified platform toolset (v140) is not installed or inva
lid. Please make sure that a supported PlatformToolset value is selected. [D:\testndelete\testThird\node_modules\iconv\build\libiconv.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: C:\windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Users\xz\AppData\Roaming\nvm\v0.12.7\node_modules\npm\node_modules\node-gyp\lib\build.js:270:23)
gyp ERR! stack at ChildProcess.emit (events.js:110:17)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:1074:12)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "C:\Users\xz\AppData\Roaming\nvm\v0.12.7\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd D:\testndelete\testThird\node_modules\iconv
gyp ERR! node -v v0.12.7
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok
D:\testndelete\testThird
└─┬ [email protected]
├── [email protected]
├── [email protected]
├─┬ [email protected]
│ └── [email protected]
├── [email protected]
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ └─┬ [email protected]
│ │ └─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └─┬ [email protected]
│ │ │ ├── [email protected]
│ │ │ ├── [email protected]
│ │ │ ├── [email protected]
│ │ │ └── [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├─┬ [email protected]
│ │ │ │ ├── [email protected]
│ │ │ │ ├── [email protected]
│ │ │ │ ├─┬ [email protected]
│ │ │ │ │ └── [email protected]
│ │ │ │ ├─┬ [email protected]
│ │ │ │ │ └── [email protected]
│ │ │ │ └── [email protected]
│ │ │ ├─┬ [email protected]
│ │ │ │ └── [email protected]
│ │ │ └─┬ [email protected]
│ │ │ ├── [email protected]
│ │ │ ├─┬ [email protected]
│ │ │ │ └── [email protected]
│ │ │ └── [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├── [email protected]
│ │ │ ├── [email protected]
│ │ │ └── [email protected]
│ │ ├─┬ [email protected]
│ │ │ └── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ └─┬ [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ └─┬ [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ └─┬ [email protected]
│ └── [email protected]
├─┬ [email protected] (git://github.com/jacobrosenthal/node-pre-gyp-github.git#cd28d5e71cd99b1d64d786a16a03db811d757234)
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └─┬ [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├── [email protected]
│ │ │ ├── [email protected]
│ │ │ ├─┬ [email protected]
│ │ │ │ └── [email protected]
│ │ │ ├── [email protected]
│ │ │ └── [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├── [email protected]
│ │ │ ├─┬ [email protected]
│ │ │ │ └── [email protected]
│ │ │ ├── [email protected]
│ │ │ └── [email protected]
│ │ └─┬ [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ ├─┬ [email protected]
│ │ │ ├── [email protected]
│ │ │ ├── [email protected]
│ │ │ └── [email protected]
│ │ └─┬ [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ ├── [email protected]
│ └── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ └── [email protected]
└── [email protected]

npm WARN ENOENT ENOENT, open 'D:\testndelete\testThird\package.json'
npm WARN EPACKAGEJSON testThird No description
npm WARN EPACKAGEJSON testThird No repository field.
npm WARN EPACKAGEJSON testThird No README data
npm WARN EPACKAGEJSON testThird No license field.
npm WARN EBUNDLEOVERRIDE Replacing bundled node_modules\serialport\node_modules\node-pre-gyp-github with new installed version
npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "install" "node-escpos" "--save"
npm ERR! node v0.12.7
npm ERR! npm v3.4.0
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node-gyp rebuild'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the iconv package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get their info via:
npm ERR! npm owner ls iconv
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! D:\testndelete\testThird\npm-debug.log

D:\testndelete\testThird>��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

Please review the issue and help me install the package.

How to use Network adapter?

I changed a few lines of code, but I don't get it to work with an IP and Port? how i'm supposed to make it work?

BASE64 image data url support?

I am trying to use base64 image data url but am getting error
TypeError: url.indexOf is not a function

Is there any way around or am doing something wrong here?

let device = new Escpos.USB();
let printer = new Escpos.Printer(device);
Escpos.Image.load(dataUrl, function(image) {
  device.open(function() {
  printer
  .align('ct')
  .raster(image)
  .cut()
  .close();
  });
});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.