WeChat Mini Programs Bluetooth Printer

is connected to the printer, but the garbled code is printed. The problem now is that Mini Program"s Bluetooth interface requires the data to be written in the form of ArrayBuffer, while the printer needs to accept the gb2312 format. I save the print command locally, how to convert the string to gb2312, and then to ArrayBuffer? Bosses call for help ~

Mar.30,2021

use this library iconv-lite

import iconv from "iconv-lite"
let toWrite = iconv.encode (item.values, 'GBK');
let base64Value = toWrite .toString (' base64');


var hex = strToHexCharCode ("! 0200 200 560 1") + "0D0A" +

   strToHexCharCode("PAGE-WIDTH 450") + "0D0A" + 
   strToHexCharCode("TEXT 24 2 20 80 ") + strToHexCharCode(str) + "0D0A"+
    strToHexCharCode("PRINT") + "0D0A" 
  var typedArray = new Uint8Array(hex.match(/[\da-f]{2}/gi).map(function (h) { return parseInt(h, 16) }))
  var buffer1 = typedArray.buffer
  ~
Menu