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

QR code printing example #24

Open
albertorcf opened this issue Jan 17, 2017 · 9 comments
Open

QR code printing example #24

albertorcf opened this issue Jan 17, 2017 · 9 comments

Comments

@albertorcf
Copy link

  printQrCode() {
    const justify_center = '\x1B\x61\x01';
    const justify_left   = '\x1B\x61\x00';
    const qr_model       = '\x32';          // 31 or 32
    const qr_size        = '\x08';          // size
    const qr_eclevel     = '\x33';          // error correction level (30, 31, 32, 33 - higher)
    const qr_data        = 'http://stackoverflow.com/';
    const qr_pL          = String.fromCharCode((qr_data.length + 3) % 256);
    const qr_pH          = String.fromCharCode((qr_data.length + 3) / 256);

    BTPrinter.printText(data => {
      this.msg= 'QR code ok';
    }, err => {
      this.msg= 'QR code ERROR';
    }, justify_center + 
       '\x1D\x28\x6B\x04\x00\x31\x41' + qr_model + '\x00' +        // Select the model
       '\x1D\x28\x6B\x03\x00\x31\x43' + qr_size +                  // Size of the model
       '\x1D\x28\x6B\x03\x00\x31\x45' + qr_eclevel +               // Set n for error correction
       '\x1D\x28\x6B' + qr_pL + qr_pH + '\x31\x50\x30' + qr_data + // Store data 
       '\x1D\x28\x6B\x03\x00\x31\x51\x30' +                        // Print
       '\n\n\n' +
       justify_left);
  }
@kruakz
Copy link

kruakz commented Jun 19, 2017

thanks @albertorcf this method work for me.

function printQR(data){
    var justify_center = ' 1B 61 01';
    var justify_left   = ' 1B 61 00';
    var qr_model       = '\x32';          // 31 or 32
    var qr_size        = '\x06';          // size
    var qr_eclevel     = '\x51';          // error correction level (30, 31, 32, 33 - higher)
    var qr_data        = data;
    var qr_pL          = String.fromCharCode((qr_data.length + 3) % 256);
    var qr_pH          = String.fromCharCode((qr_data.length + 3) / 256);
    
    
    
     BTPrinter.printText(function(data){
      console.log('QR code ok');
    }, function(err){
      console.log('QR code ERROR');
    }, '\x1D\x28\x6B\x04\x00\x31\x41' + qr_model + '\x00' +        // Select the model
       '\x1D\x28\x6B\x03\x00\x31\x43' + qr_size +                  // Size of the model
       '\x1D\x28\x6B\x03\x00\x31\x45' + qr_eclevel +               // Set n for error correction
       '\x1D\x28\x6B' + qr_pL + qr_pH + '\x31\x50\x30' + qr_data + // Store data 
       '\x1D\x28\x6B\x03\x00\x31\x51\x30' +                        // Print
       '\n\n\n');
  }

@vittorbraga
Copy link

I I was able to print the qr code with this method, but my url has 345 characters and the printed qr code is not correct.
Is there a parameter to fix this?
img_0413

@sureshgollapalli
Copy link

Hello
i apply same code but i am not getting
please help me how to get qr code print .
my code is like below.

//This is my js code
var app = {
// Application Constructor
initialize: function () {

    //document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    //debugger;
    document.addEventListener('deviceready', function () {
        debugger;

        BTPrinter.list(function (data) {
            console.log("Success");
            console.log(data); //list of printer in data array
        }, function (err) {
            console.log("Error");
            console.log(err);
        })
        debugger;

        BTPrinter.connect(function (data) {
            console.log("Success");
            console.log(data)
        }, function (err) {
            console.log("Error");
            console.log(err)
        }, "woosim")
        debugger;

        BTPrinter.printPOSCommand(function (data) {
            console.log("Success");
            console.log(data)
        }, function (err) {
            console.log("Error");
            console.log(err)
        }, "1B 45 01")

        debugger;
        function printQR(data) {
            var justify_center = ' 1B 61 01';
            var justify_left = ' 1B 61 00';
            var qr_model = '\x32';          // 31 or 32
            var qr_size = '\x06';          // size
            var qr_eclevel = '\x51';          // error correction level (30, 31, 32, 33 - higher)
            var qr_data = data;
            var qr_pL = String.fromCharCode((qr_data.length + 3) % 256);
            var qr_pH = String.fromCharCode((qr_data.length + 3) / 256);



            BTPrinter.printText(function (data) {
                console.log('QR code ok');
            }, function (err) {
                console.log('QR code ERROR');
            }, '\x1D\x28\x6B\x04\x00\x31\x41' + qr_model + '\x00' +        // Select the model
              '\x1D\x28\x6B\x03\x00\x31\x43' + qr_size +                  // Size of the model
              '\x1D\x28\x6B\x03\x00\x31\x45' + qr_eclevel +               // Set n for error correction
              '\x1D\x28\x6B' + qr_pL + qr_pH + '\x31\x50\x30' + qr_data + // Store data 
              '\x1D\x28\x6B\x03\x00\x31\x51\x30' +                        // Print
              '\n\n\n');
        }

            //BTPrinter.printText(function (data) {
            //    console.log('QR code ok');
            //}, function (err) {
            //    console.log('QR code ERROR');
            //}, "Vehicle No:Ap356637\n\n        Parking Time:10:00 H:M\n\n        Central Parking Services\n\n        THANKYOU");
        

        BTPrinter.printPOSCommand(function (data) {
            console.log("Success");
            console.log(data)
        }, function (err) {
            console.log("Error");
            console.log(err)
        }, "0A")

       
      
    }, false);
},

// deviceready Event Handler
//
// Bind any cordova events here. Common events are:
// 'pause', 'resume', etc.
onDeviceReady: function() {
    this.receivedEvent('deviceready');
    debugger;
  
   

},

// Update DOM on a Received Event
receivedEvent: function(id) {
    var parentElement = document.getElementById(id);
    var listeningElement = parentElement.querySelector('.listening');
    var receivedElement = parentElement.querySelector('.received');

    listeningElement.setAttribute('style', 'display:none;');
    receivedElement.setAttribute('style', 'display:block;');

    console.log('Received Event: ' + id);
}

};

app.initialize();

i am getting texting printing but i am not getting qr code print .

@pvillaverde
Copy link

Hey there! I've been strugling with this for a while and couldn't get it to work. Do you need a special kind of printer in order to print QR Codes? I have a Dapper BM9000-II.

I tried different ways but all came out with same result, some HEX Codes and then the url i put as data.

Would be appreciated any help! :-)

@vittorbraga
Copy link

I do not know if your printer uses escpos language to print. If so, this code below works for me.
But very large data, the qr code that does not print correctly. I use url shortener.

`
var qr_model = '\x32'; // 31 or 32

var qr_size = '\x08'; // size

var qr_eclevel = '\x49'; // error correction level (30, 31, 32, 33 - higher)

var qr_data = 'http://www.google.com';

var qr_pL = String.fromCharCode((qr_data.length + 3) % 256);

var qr_pH = String.fromCharCode((qr_data.length + 3) / 256);

bluetoothSerial.write('\x1B\x61\x01'); // Centralizar texto
bluetoothSerial.write('\x1D\x28\x6B\x04\x00\x31\x41' + qr_model + '\x00'); // Select the model
bluetoothSerial.write('\x1D\x28\x6B\x03\x00\x31\x43' + qr_size); // Size of the model
bluetoothSerial.write('\x1D\x28\x6B\x03\x00\x31\x45' + qr_eclevel); // Set n for error correction
bluetoothSerial.write('\x1D\x28\x6B' + qr_pL + qr_pH + '\x31\x50\x30' + qr_data); // Store data
bluetoothSerial.write('\x1D\x28\x6B\x03\x00\x31\x51\x30'); `

@pvillaverde
Copy link

I tried that code but it didn't work. On the sel test page of the printer it shows a QR Code but I don't know how to get it. I Used google URL as data for test without success. Only way I find to print a QR was with @CesarBalzer image printing method. Thanks for answering nevertheless! :-)

@rgsilva20
Copy link

Hi,
I tried the same code, but it did not work. It is printing the previous and current QRCode every time.

20190513_150911

@jasonchong3329
Copy link

I do not know if your printer uses escpos language to print. If so, this code below works for me.
But very large data, the qr code that does not print correctly. I use url shortener.

`
var qr_model = '\x32'; // 31 or 32

var qr_size = '\x08'; // size

var qr_eclevel = '\x49'; // error correction level (30, 31, 32, 33 - higher)

var qr_data = 'http://www.google.com';

var qr_pL = String.fromCharCode((qr_data.length + 3) % 256);

var qr_pH = String.fromCharCode((qr_data.length + 3) / 256);

bluetoothSerial.write('\x1B\x61\x01'); // Centralizar texto
bluetoothSerial.write('\x1D\x28\x6B\x04\x00\x31\x41' + qr_model + '\x00'); // Select the model
bluetoothSerial.write('\x1D\x28\x6B\x03\x00\x31\x43' + qr_size); // Size of the model
bluetoothSerial.write('\x1D\x28\x6B\x03\x00\x31\x45' + qr_eclevel); // Set n for error correction
bluetoothSerial.write('\x1D\x28\x6B' + qr_pL + qr_pH + '\x31\x50\x30' + qr_data); // Store data
bluetoothSerial.write('\x1D\x28\x6B\x03\x00\x31\x51\x30'); `

This method is working
May i know where can i found the documentation code for escpos language?
i would like to print Barcode instead of QR code.

@Sebdawg
Copy link

Sebdawg commented Apr 16, 2020

I do not know if your printer uses escpos language to print. If so, this code below works for me.
But very large data, the qr code that does not print correctly. I use url shortener.
var qr_model = '\x32'; // 31 or 32 var qr_size = '\x08'; // size var qr_eclevel = '\x49'; // error correction level (30, 31, 32, 33 - higher) var qr_data = 'http://www.google.com'; var qr_pL = String.fromCharCode((qr_data.length + 3) % 256); var qr_pH = String.fromCharCode((qr_data.length + 3) / 256); bluetoothSerial.write('\x1B\x61\x01'); // Centralizar texto bluetoothSerial.write('\x1D\x28\x6B\x04\x00\x31\x41' + qr_model + '\x00'); // Select the model bluetoothSerial.write('\x1D\x28\x6B\x03\x00\x31\x43' + qr_size); // Size of the model bluetoothSerial.write('\x1D\x28\x6B\x03\x00\x31\x45' + qr_eclevel); // Set n for error correction bluetoothSerial.write('\x1D\x28\x6B' + qr_pL + qr_pH + '\x31\x50\x30' + qr_data); // Store data bluetoothSerial.write('\x1D\x28\x6B\x03\x00\x31\x51\x30');

This method is working
May i know where can i found the documentation code for escpos language?
i would like to print Barcode instead of QR code.

Hi Jasonchong3329,

Thank you for this! I'm using bluetooth serial plug in and your code worked!

Were you able to print images using the bluetoothSerial plugin?

I'm trying to print images and was hoping you might have some insight. I'm reviewing this manual
https://www.starmicronics.com/support/Mannualfolder/escpos_cm_en.pdf

I got to page 116 <function 180> to save the QR data but don't understand how you get '\x31\x50\x30' before the QR data.

I'm trying to understand your code 100% in hopes I might be able to use it to print an image instead.

Would you please help me print an image with bluetoothSerial?

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

No branches or pull requests

8 participants