Coder Social home page Coder Social logo

escpos's People

Contributors

dependabot[bot] avatar haavardlian avatar ryall 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

Watchers

 avatar  avatar  avatar  avatar  avatar

escpos's Issues

I need more examples。

Hello, my English is not very good, The following text is translated by the translation software
, I hope it will not affect your reading.
Your project helped me a lot. But I don't know much about NodeJs, Can you write a few more examples? Such as pictures, QR Code, bar code, such as a simple example.
Thanks very much!

Work with ionic bluetooth printer?

Hi, I print with ionic bluetooth but I can't print qr code, your library it's a alternative.
Works with cordova? import { BluetoothSerial } from '@ionic-native/bluetooth-serial/ngx';

Error module not found

i got these errors

WARNING in ./~/bindings/bindings.js
76:22-40 Critical dependency: the request of a dependency is an expression

WARNING in ./~/bindings/bindings.js
76:43-53 Critical dependency: the request of a dependency is an expression

ERROR in .//escpos-print/adapters/Network.js
Module not found: Error: Can't resolve 'net' in '/home/adty/Projects/klopos/web/myklopos/dev/node_modules/escpos-print/adapters'
@ ./
/escpos-print/adapters/Network.js 3:14-28
@ ./~/escpos-print/Adapters.js
@ ./src/js/pages/Report/Sales/BranchSales.js
@ ./src/js/config/routes.js
@ ./src/js/client.js
@ multi (webpack)-dev-server/client?http://192.168.1.19:8080 webpack/hot/dev-server ./js/client.js

ERROR in .//serialport/lib/serialport.js
Module not found: Error: Can't resolve 'fs' in '/home/adty/Projects/klopos/web/myklopos/dev/node_modules/serialport/lib'
@ ./
/serialport/lib/serialport.js 16:9-22
@ .//escpos-print/adapters/Serial.js
@ ./
/escpos-print/Adapters.js
@ ./src/js/pages/Report/Sales/BranchSales.js
@ ./src/js/config/routes.js
@ ./src/js/client.js
@ multi (webpack)-dev-server/client?http://192.168.1.19:8080 webpack/hot/dev-server ./js/client.js

ERROR in .//serialport/lib/list-unix.js
Module not found: Error: Can't resolve 'fs' in '/home/adty/Projects/klopos/web/myklopos/dev/node_modules/serialport/lib'
@ ./
/serialport/lib/list-unix.js 5:9-22
@ .//serialport/lib/bindings.js
@ ./
/serialport/lib/serialport.js
@ .//escpos-print/adapters/Serial.js
@ ./
/escpos-print/Adapters.js
@ ./src/js/pages/Report/Sales/BranchSales.js
@ ./src/js/config/routes.js
@ ./src/js/client.js
@ multi (webpack)-dev-server/client?http://192.168.1.19:8080 webpack/hot/dev-server ./js/client.js

ERROR in .//serialport/lib/list-unix.js
Module not found: Error: Can't resolve 'child_process' in '/home/adty/Projects/klopos/web/myklopos/dev/node_modules/serialport/lib'
@ ./
/serialport/lib/list-unix.js 4:19-43
@ .//serialport/lib/bindings.js
@ ./
/serialport/lib/serialport.js
@ .//escpos-print/adapters/Serial.js
@ ./
/escpos-print/Adapters.js
@ ./src/js/pages/Report/Sales/BranchSales.js
@ ./src/js/config/routes.js
@ ./src/js/client.js
@ multi (webpack)-dev-server/client?http://192.168.1.19:8080 webpack/hot/dev-server ./js/client.js

ERROR in .//bindings/bindings.js
Module not found: Error: Can't resolve 'fs' in '/home/adty/Projects/klopos/web/myklopos/dev/node_modules/bindings'
@ ./
/bindings/bindings.js 6:9-22
@ .//serialport/lib/bindings.js
@ ./
/serialport/lib/serialport.js
@ .//escpos-print/adapters/Serial.js
@ ./
/escpos-print/Adapters.js
@ ./src/js/pages/Report/Sales/BranchSales.js
@ ./src/js/config/routes.js
@ ./src/js/client.js
@ multi (webpack)-dev-server/client?http://192.168.1.19:8080 webpack/hot/dev-server ./js/client.js

what error are those and how to solve them? thanks.

Unable to build this library

Hi Thanks for writing this library.
I am trying to add bluetooth functionality to this library and add it to my main project. I download this git project and tried executing $npm i which throws lot of error as below.Can you tell me how to add this project to my other project as node module after making changes.

Mac:escpos-master Nadeem$ npm i

[email protected] install /Users/Nadeem/Downloads/escpos-master/node_modules/usb
node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using needle for node-pre-gyp https download
node-pre-gyp WARN Tried to download(404): https://github.com/tessel/node-usb/releases/download/1.5.0/usb_bindings-v1.5.0-node-v72-darwin-x64
.tar.gz
node-pre-gyp WARN Pre-built binaries not found for [email protected] and [email protected] (node-v72 ABI, unknown) (falling back to source compile with n
ode-gyp)
CC(target) Release/obj.target/libusb/libusb/libusb/core.o
../libusb/libusb/core.c:2241:35: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare]
if (header_len < 0 || header_len >= sizeof(buf)) {
~~~~~~~~~~ ^ ~~~~~~~~~~~
../libusb/libusb/core.c:2250:44: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare]
if (text_len < 0 || text_len + header_len >= sizeof(buf)) {
~~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~
2 warnings generated.
CC(target) Release/obj.target/libusb/libusb/libusb/descriptor.o
CC(target) Release/obj.target/libusb/libusb/libusb/hotplug.o
CC(target) Release/obj.target/libusb/libusb/libusb/io.o
CC(target) Release/obj.target/libusb/libusb/libusb/strerror.o
CC(target) Release/obj.target/libusb/libusb/libusb/sync.o
CC(target) Release/obj.target/libusb/libusb/libusb/os/poll_posix.o
CC(target) Release/obj.target/libusb/libusb/libusb/os/threads_posix.o
CC(target) Release/obj.target/libusb/libusb/libusb/os/darwin_usb.o
../libusb/libusb/os/darwin_usb.c:344:3: warning: 'objc_registerThreadWithCollector' is deprecated: it does nothing. Define
OBJC_SILENCE_GC_DEPRECATIONS=1 to temporarily silence this diagnostic. [-Wdeprecated-declarations]
objc_registerThreadWithCollector();
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/objc-auto.h:243:1: note:
'objc_registerThreadWithCollector' has been explicitly marked deprecated here
OBJC_GC_DEPRECATED("it does nothing")
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/objc/objc-auto.h:45:55: note:
expanded from macro 'OBJC_GC_DEPRECATED'

define OBJC_GC_DEPRECATED(message) attribute((deprecated(message ". Define OBJC_SILENCE_GC_DEPRECATIONS=1 to temporarily sil...

                                                  ^

../libusb/libusb/os/darwin_usb.c:1281:27: warning: expression which evaluates to zero treated as a null pointer constant of type
'IOUSBInterfaceInterface550 **' (aka 'struct IOUSBInterfaceStruct550 **') [-Wnon-literal-null-conversion]
cInterface->interface = IO_OBJECT_NULL;
^~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/IOKit.framework/Headers/IOTypes.h:167:25: note:
expanded from macro 'IO_OBJECT_NULL'
#define IO_OBJECT_NULL ((io_object_t) 0)
^~~~~~~~~~~~~~~~~
2 warnings generated.
LIBTOOL-STATIC Release/usb.a
CXX(target) Release/obj.target/usb_bindings/src/node_usb.o
../src/node_usb.cc:66:10: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
target->Set(Nan::New("INIT_ERROR").ToLocalChecked(), Nan::New(res));
^
/Users/Nadeem/Library/Caches/node-gyp/12.14.1/include/node/v8.h:3402:3: note: 'Set' has been explicitly marked deprecated here
V8_DEPRECATED("Use maybe version",
^
/Users/Nadeem/Library/Caches/node-gyp/12.14.1/include/node/v8config.h:311:29: note: expanded from macro 'V8_DEPRECATED'
declarator attribute((deprecated(message)))
^
../src/node_usb.cc:99:73: error: too few arguments to function call, single argument 'context' was not specified
if (info.Length() != 1 || !info[0]->IsUint32() || info[0]->Uint32Value() > 4) {
~~~~~~~~~~~~~~~~~~~~ ^
/Users/Nadeem/Library/Caches/node-gyp/12.14.1/include/node/v8.h:2611:3: note: 'Uint32Value' declared here
V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value(
^
/Users/Nadeem/Library/Caches/node-gyp/12.14.1/include/node/v8config.h:351:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT attribute((warn_unused_result))
^
../src/node_usb.cc:103:53: error: too few arguments to function call, single argument 'context' was not specified
libusb_set_debug(usb_context, info[0]->Uint32Value());
~~~~~~~~~~~~~~~~~~~~ ^
/Users/Nadeem/Library/Caches/node-gyp/12.14.1/include/node/v8.h:2611:3: note: 'Uint32Value' declared here
V8_WARN_UNUSED_RESULT Maybe<uint32_t> Uint32Value(
^
/Users/Nadeem/Library/Caches/node-gyp/12.14.1/include/node/v8config.h:351:31: note: expanded from macro 'V8_WARN_UNUSED_RESULT'
#define V8_WARN_UNUSED_RESULT attribute((warn_unused_result))
^
../src/node_usb.cc:116:8: warning: 'Set' is deprecated: Use maybe version [-Wdeprecated-declarations]
arr->Set(i, Device::get(devs[i]));
^
/Users/Nadeem/Library/Caches/node-gyp/12.14.1/include/node/v8.h:3411:3: note: 'Set' has been explicitly marked deprecated here
V8_DEPRECATED("Use maybe version",
^
/Users/Nadeem/Library/Caches/node-gyp/12.14.1/include/node/v8config.h:311:29: note: expanded from macro 'V8_DEPRECATED'
declarator attribute((deprecated(message)))
^
../src/node_usb.cc:151:7: warning: 'MakeCallback' is deprecated [-Wdeprecated-declarations]
Nan::MakeCallback(Nan::New(hotplugThis), "emit", 2, argv);
^
../../nan/nan.h:1066:3: note: 'MakeCallback' has been explicitly marked deprecated here
NAN_DEPRECATED inline v8::Localv8::Value MakeCallback(
^
../../nan/nan.h:104:40: note: expanded from macro 'NAN_DEPRECATED'

define NAN_DEPRECATED attribute((deprecated))

                                   ^

../src/node_usb.cc:301:5: error: no matching member function for call to 'ToObject'
e->ToObject()->Set(Nan::New("errno").ToLocalChecked(), Nan::New(errorno));
~~~^~~~~~~~
/Users/Nadeem/Library/Caches/node-gyp/12.14.1/include/node/v8.h:2576:44: note: candidate function not viable: requires single argument
'context', but no arguments were provided
V8_WARN_UNUSED_RESULT MaybeLocal ToObject(
^
/Users/Nadeem/Library/Caches/node-gyp/12.14.1/include/node/v8.h:2590:31: note: candidate function not viable: requires single argument
'isolate', but no arguments were provided
Local ToObject(Isolate* isolate) const);
^
3 warnings and 3 errors generated.
make: *** [Release/obj.target/usb_bindings/src/node_usb.o] Error 1
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack at ChildProcess.emit (events.js:223:5)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Darwin 19.2.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/Users/Nadeem/Downloads/escpos-master/node_modules/usb/src/binding/usb_bindings.node" "--module_name=usb_bindings" "--module_path=/Users/Nadeem/Downloads/escpos-master/node_modules/usb/src/binding" "--napi_version=5" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v72"
gyp ERR! cwd /Users/Nadeem/Downloads/escpos-master/node_modules/usb
gyp ERR! node -v v12.14.1
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/Users/Nadeem/Downloads/escpos-master/node_modules/usb/src/binding/usb_bindings.node --module_name=usb_bindings --module_path=/Users/Nadeem/Downloads/escpos-master/node_modules/usb/src/binding --napi_version=5 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v72' (1)
node-pre-gyp ERR! stack at ChildProcess. (/Users/Nadeem/Downloads/escpos-master/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack at ChildProcess.emit (events.js:223:5)
node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:1021:16)
node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
node-pre-gyp ERR! System Darwin 19.2.0
node-pre-gyp ERR! command "/usr/local/bin/node" "/Users/Nadeem/Downloads/escpos-master/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /Users/Nadeem/Downloads/escpos-master/node_modules/usb
node-pre-gyp ERR! node -v v12.14.1
node-pre-gyp ERR! node-pre-gyp -v v0.11.0
node-pre-gyp ERR! not ok
Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/Users/Nadeem/Downloads/escpos-master/node_modules/usb/src/binding/usb_bindings.node --module_name=usb_bindings --module_path=/Users/Nadeem/Downloads/escpos-master/node_modules/usb/src/binding --napi_version=5 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v72' (1)
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/usb):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] install: node-pre-gyp install --fallback-to-build
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

audited 315 packages in 8.032s

3 packages are looking for funding
run npm fund for details

found 0 vulnerabilities

Mac:escpos-master Nadeem$

Network printer - error when calling close

this.device.on("close", () => {
this.connected = false;

           if (this.retrying && (retries === 0 || this.retries < retries)) {
            this.retries++;
            setTimeout(() => {
                this.device.connect(this.options.port, this.options.address);
            }, 5000);
        }
        else { //this line will always hit and throw exception on close.
            this.retrying = false;
            throw new Error(`Cannot connect to ${this.options.address}:${this.options.port}`);
        }
    });

when calling close on the printer object the network adapter throws the exception, causing the awaiter to fail, trying to catch the exception has proven tough, causing node to crash. simple fix is to return upon retrying === false, and only throw the exception when it is in a retrying state

'On' event support for Serial / USB adapters

Firstly, thank you for the fantastic library! Having TS built as standard into the library without relying on an external [at]Types definition is wonderful.

Onto the main issue. With node-serialport and node-usb, both support 'on' events, such as 'on data', 'on error', etc. These are usually handled as callbacks - e.g. serialport.on("data", (data: any) => callback(data)) - which triggers each time the serialport device sends data.

At present, this library doesn't provide such functionality. I have tried to implement such functionality myself, but I believe I may be implementing it incorrectly into the library.

One such use case for this is retrieving printer status (usually returned as a stream of bytes of n length). By sending certain thermal printers certain bytes (e.g. 0x10, 0x14, 0x07, 0x01), the device will respond with a stream of bytes (e.g. 0x14, 0x00, 0x00, 0x0f) which can be interpreted as multiple possible statuses such as 'ready', or 'cutter error', or 'paper being fed', etc, or a combination of statuses. The bytes to be sent and the bytes returned vary from printer to printer, so the ability to write bytes, and receive a callback when data is sent from the device would be highly beneficial.

Is it possible for such functionality to be added into this library?

Use library for ionic bluetooth printer

I have adapted your code to my code to be able to print a qr by a bluetooth printer using esc / pos command on ionic 4

prepareToPrint2() {
    const data = this.qr('We can put all kinds of cool things in these...', QRErrorCorrectLevel.M, 8).buffer;
    console.log(data);
    this.mountAlertBt(data);
  }

  public qr(code: string, errorCorrect: QRErrorCorrectLevel, size: 1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16): any {
    const GS = 0x1D;
    this.write(GS);
    this.write('(k');
    this.buffer.writeUInt16LE(code.length + 3);
    this.write(new Uint8Array([49, 80, 48]));
    this.write(code);

    this.write(GS);
    this.write('(k');
    this.write(new Uint8Array([3, 0, 49, 69]));
    this.write(errorCorrect);

    this.write(GS);
    this.write('(k');
    this.write(new Uint8Array([3, 0, 49, 67]));
    this.write(size);

    this.write(GS);
    this.write('(k');
    this.write(new Uint8Array([3, 0, 49, 81, 48]));
    return this;
}
public write(value: string | Uint8Array | number, encoding?: string): any {
  this.buffer = new MutableBuffer();
  if (typeof value === 'number') {
      this.buffer.writeUInt8(value);
  } else if (typeof value === 'string') {
      this.buffer.write(iconv.encode(value, encoding || 'ascii'));
  } else {
      this.buffer.write(value);
  }
  return this;
}

This is the method that sends the data to the ionic library

async print(device, data) {
    console.log('Data a imprimir');
    console.log(data);
    console.log(JSON.stringify(device));
    this.presentLoading('Printing....');
    this.printer.connectBluetooth(device).subscribe(
      (status) => {
        console.log(status);
        //this.printer.printData(noSpecialChars(data))
        this.printer.printData(data)
          .then(async printStatus => {
            console.log('Impresión correcta');
            console.log(printStatus);
          })
          .catch((error) => {
            console.log('Impresión fallida');
            console.log(JSON.stringify(error));
          });
      },
      (error) => {
      },
    );
  }

import { BluetoothSerial } from '@ionic-native/bluetooth-serial/ngx';

Print but not the QR code only many characters in Japanese

I was able to print pure text using the hexadecimal code directly
For example

TEXT_FORMAT: {
       TXT_NORMAL: '\ x1b \ x21 \ x00', // Normal text
       TXT_2HEIGHT: '\ x1b \ x21 \ x10', // Double height text
       TXT_2WIDTH: '\ x1b \ x21 \ x20'}

do you have any idea

USB

I was about to write the USB adapter for this but then i noticed the feature/next branch which has the USB adapter. When are you planning to release that on NPM?

//ysf

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.