Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const usb = require("webusb").usb;
  2. const escpos = require('escpos');  
  3.  
  4. function connect(){
  5.  
  6.     var vid;
  7.     var pid;
  8.  
  9.     navigator.usb.requestDevice({ filters: [{ vendorId: 0x04b8 }] })
  10.     .then(devicePrinter => {
  11.    
  12.     console.log(device.vendorId);      
  13.     console.log(device.productId);
  14.     vid = device.vendorId.toString(16);
  15.     pid = device.productId.toString(16);
  16.     console.log(vid + pid);
  17.     })
  18.     .catch(error => { console.log(error); });
  19.  
  20.     const device  = new escpos.USB("0x0"+vid, "0x0"+pid);
  21.     const printer = new escpos.Printer(device);
  22.  
  23.     device.open(function(){
  24.  
  25.         printer
  26.         .align('ct')
  27.         .text("nice")
  28.  
  29.         .cut()
  30.         .close();
  31.    
  32.     });
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement