123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- var encode = require("./encoding.js")
- var app = getApp();
- var jpPrinter = {
- createNew: function() {
- var jpPrinter = {};
- var data = [];
- var bar = ["UPC-A", "UPC-E", "EAN13", "EAN8", "CODE39", "ITF", "CODABAR", "CODE93", "CODE128"];
- jpPrinter.name = "蓝牙打印机";
- jpPrinter.init = function() {
- data.push(27)
- data.push(64)
- };
- jpPrinter.setText = function(content) {
- var code = new encode.TextEncoder(
- 'gb18030', {
- NONSTANDARD_allowLegacyEncoding: true
- }).encode(content)
- for (var i = 0; i < code.length; ++i) {
- data.push(code[i])
- }
- }
- jpPrinter.setFontSize=function(n){
- data.push(29)
- data.push(33)
- data.push(n)
- }
- jpPrinter.bold = function (n) {
- data.push(27)
- data.push(69)
- data.push(n)
- }
-
- jpPrinter.setUnderline=function(n){
- data.push(27)
- data.push(45)
- data.push(n)
- }
- jpPrinter.setUnderline2 = function (n) {
- data.push(28)
- data.push(45)
- data.push(n)
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- jpPrinter.setSelectSizeOfModuleForQRCode = function(n) {
- data.push(29)
- data.push(40)
- data.push(107)
- data.push(3)
- data.push(0)
- data.push(49)
- data.push(67)
- if (n > 15) {
- n = 15
- }
- if (n < 1) {
- n = 1
- }
- data.push(n)
- }
- jpPrinter.setSelectErrorCorrectionLevelForQRCode = function(n) {
-
- data.push(29)
- data.push(40)
- data.push(107)
- data.push(3)
- data.push(0)
- data.push(49)
- data.push(69)
- data.push(n)
- }
- jpPrinter.setStoreQRCodeData = function(content) {
- console.log('content',content)
- var code = new encode.TextEncoder(
- 'utf-8', {
- NONSTANDARD_allowLegacyEncoding: true
- }).encode(content)
- data.push(29)
- data.push(40)
- data.push(107)
- data.push(parseInt((code.length + 3) % 256))
- data.push(parseInt((code.length + 3) / 256))
- data.push(49)
- data.push(80)
- data.push(48)
- for (var i = 0; i < code.length; ++i) {
- data.push(code[i])
- }
- }
- jpPrinter.setPrintQRCode = function() {
- data.push(29)
- data.push(40)
- data.push(107)
- data.push(3)
- data.push(0)
- data.push(49)
- data.push(81)
- data.push(48)
- }
- jpPrinter.setHorTab = function() {
- data.push(9)
- }
- jpPrinter.setAbsolutePrintPosition = function(where) {
- data.push(27)
- data.push(36)
- data.push(parseInt(where % 256))
- data.push(parseInt(where / 256))
- }
- jpPrinter.setRelativePrintPositon = function(where) {
- data.push(27)
- data.push(92)
- data.push(parseInt(where % 256))
- data.push(parseInt(where / 256))
- }
- jpPrinter.setSelectJustification = function(which) {
-
- data.push(27)
- data.push(97)
- data.push(which)
- }
- jpPrinter.space = function (n) {
- data.push(27)
- data.push(68)
- data.push(n)
- }
- jpPrinter.setLeftMargin = function(n) {
- data.push(29)
- data.push(76)
- data.push(parseInt(n % 256))
- data.push(parseInt(n / 256))
- }
- jpPrinter.textMarginRight = function (n) {
- data.push(27)
- data.push(32)
- data.push(n)
- }
- jpPrinter.rowSpace = function (n) {
- data.push(27)
- data.push(51)
- data.push(n)
- }
- jpPrinter.setPrintingAreaWidth = function(width) {
- data.push(29)
- data.push(87)
- data.push(parseInt(width % 256))
- data.push(parseInt(width / 256))
- }
- jpPrinter.setSound = function(n, t) {
- data.push(27)
- data.push(66)
- if (n < 0) {
- n = 1;
- } else if (n > 9) {
- n = 9;
- }
- if (t < 0) {
- t = 1;
- } else if (t > 9) {
- t = 9;
- }
- data.push(n)
- data.push(t)
- }
- jpPrinter.setBitmap = function(res) {
- console.log(res)
- var width = parseInt((res.width + 7) / 8 * 8 / 8)
- var height = res.height;
- var time = 1;
- var temp = res.data.length - width * 32;
- var point_list = []
- console.log(width + "--" + height)
- data.push(29)
- data.push(118)
- data.push(48)
- data.push(0)
- data.push((parseInt((res.width + 7) / 8) * 8) / 8)
- data.push(0)
- data.push(parseInt(res.height % 256))
- data.push(parseInt(res.height / 256))
- console.log(res.data.length)
- console.log("temp=" + temp)
- for (var i = 0; i < height; ++i) {
- for (var j = 0; j < width; ++j) {
- for (var k = 0; k < 32; k += 4) {
- var po = {}
- if (res.data[temp] == 0 && res.data[temp + 1] == 0 && res.data[temp + 2] == 0 && res.data[temp + 3] == 0) {
- po.point = 0;
- } else {
- po.point = 1;
- }
- point_list.push(po)
- temp += 4
- }
- }
- time++
- temp = res.data.length - width * 32 * time
- }
- for (var i = 0; i < point_list.length; i += 8) {
- var p = point_list[i].point * 128 + point_list[i + 1].point * 64 + point_list[i + 2].point * 32 + point_list[i + 3].point * 16 + point_list[i + 4].point * 8 + point_list[i + 5].point * 4 + point_list[i + 6].point * 2 + point_list[i + 7].point
- data.push(p)
- }
- }
- jpPrinter.setPrint = function() {
- data.push(10)
- }
- jpPrinter.setPrintAndFeed = function(feed) {
- data.push(27)
- data.push(74)
- data.push(feed)
- }
- jpPrinter.setPrintAndFeedRow = function(row) {
- data.push(27)
- data.push(100)
- data.push(row)
- }
- jpPrinter.getData = function() {
- return data;
- };
-
- return jpPrinter;
- },
- Query: function() {
- var queryStatus = {};
- var buf;
- var dateView;
- queryStatus.getRealtimeStatusTransmission = function(n) {
-
- buf = new ArrayBuffer(3)
- dateView = new DataView(buf)
- dateView.setUint8(0, 16)
- dateView.setUint8(1, 4)
- dateView.setUint8(2, n)
- queryStatus.query(buf)
- }
- queryStatus.query = function(buf) {
- wx.writeBLECharacteristicValue({
- deviceId: app.BLEInformation.deviceId,
- serviceId: app.BLEInformation.writeServiceId,
- characteristicId: app.BLEInformation.writeCharaterId,
- value: buf,
- success: function(res) {
- },
- complete: function(res) {
- console.log(res)
- buf = null
- dateView = null;
- }
- })
- }
- return queryStatus;
- }
- };
- module.exports.jpPrinter = jpPrinter;
|