Is there a way to print a barcode using Web-Bluetooth?

563 Views Asked by At

I've recently gotten a Zebra ZQ210 printer and I've been using Web-Bluetooth to print text on it, but I cannot seem to find how to print a barcode on it. Here's my algorithm for printing text:

 writeMessage(message) {  
    return this.device.gatt.getPrimaryService("38eb4a80-c570-11e3-9507-0002a5d5c51b")

        .then(service => service.getCharacteristic("38eb4a82-c570-11e3-9507-0002a5d5c51b"))
        .then(characteristic => {
          var maxChunk = 500;
          var j = 0;

          if ( message.length > maxChunk ) {
            for ( var i = 0; i < message.length; i += maxChunk ) {
              var subStr;
              if ( i + maxChunk <= message.length ) {
                subStr = message.substring(i, i + maxChunk);

              } else {
                subStr = message.substring(i, message.length);
              }

              setTimeout(writeStrToCharacteristic, 4900 * j, subStr);
              j++;
            }
          } else {
            writeStrToCharacteristic(message);
          }

          function writeStrToCharacteristic (str) {
            let buffer = new ArrayBuffer(str.length);
            let dataView = new DataView(buffer);
            for (var i = 0; i <str.length; i++) {
              dataView.setUint8( i, str.charAt(i).charCodeAt() );
            }
            return characteristic.writeValue(buffer);
          }
        }).catch(error => { console.error(
          error.message
        ); });
  }

If there's a way to print barcodes on it using Web-Bluetooth I would love to know how. Thank you in advance!

EDIT: I have tried sending zpl codes as text to the printer, and it hasn't worked. I've also tried to send ESC/POS codes but it also didn't do anything, so far I'm lost.

0

There are 0 best solutions below