New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bluetooth_cpcl

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bluetooth_cpcl - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

lib/base64gb2312.js

2

index.js

@@ -1,1 +0,1 @@

module.exports = require('./lib/bluetooth');
module.exports = require('./lib/print');

@@ -1,1239 +0,189 @@

const gbk = require('./gbk.js');
var serviceId1 = "E7810A71-73AE-499D-8C15-FAA9AEF0C3F2"
var characteristicId1 = "BEF8D6C9-9C21-4C9E-B632-BD58C1009F9F"
//POS Function
function setBarcode(str, x, nBarcodeUnitWidth, nBarcodeHeight, nHriFontType, nHriFontPosition, nBarcodeType) {
// nBarcodeUnitWidth 一维条码宽度 参数范围1~6
// nBarcodeHeight 一维条码高度 参数范围1~255
// nHriFontType 选择HRI字符字型
// 0,48 字体A(12x24)
// 1,49 字体B(9x17)
// nHriFontPosition 设置一维条码可读字符(HRI)打印位置
// n 打印位置
// 0,48 不打印
// 1,49 条码的上方
// 2,50 条码的下方
// 3,51 条码的上方和下方
// nBarcodeType 编码方式 A方式0~6 B方式65~74
// n 编码系统
// 0,65 UPC-A
// 1,66 UPC-E
// 2,67 JAN13(EAN13)
// 3,68 JAN8(EAN8)
// 4,69 CODE39
// 5,70 ITF(Interleaved 2 of 5)
// 6,71 CODABAR(NW-7)
// 72 CODE93
// 73 CODE128
// 74 UCC/EAN128
// alignment
var ESC_a_n = new Uint8Array([0x1b, 0x61, 0x00]);
// x position
var ESC_dollors_nL_nH = new Uint8Array([0x1b, 0x24, 0x00, 0x00]);
if (x == -1) {
ESC_a_n[2] = 0x00;
ESC_dollors_nL_nH[2] = 0;
ESC_dollors_nL_nH[3] = 0;
} else if (x == -2) {
ESC_a_n[2] = 0x01;
ESC_dollors_nL_nH[2] = 0;
ESC_dollors_nL_nH[3] = 0;
} else if (x == -3) {
ESC_a_n[2] = 0x02;
ESC_dollors_nL_nH[2] = 0;
ESC_dollors_nL_nH[3] = 0;
} else {
ESC_a_n[2] = 0x00;
ESC_dollors_nL_nH[2] = (x % 0x100);
ESC_dollors_nL_nH[3] = (x / 0x100);
const base = require('./base64gb2312');
class PrintUtil{
/**
* 初始化纸张
* 0 整个标签的横向偏移量
* 200 横向分辨率
* 200 纵向分辨率
* @param height 150 标签的高度
* @param number 1 要打印的标签数量
*/
constructor(height,number){
var h = 150;
var n = 1;
if(height){
h = height;
}
if(number){
n = number
}
this.str = "! 0 200 200 "+ h + " " + n + "\r\n";
}
var GS_w_n = new Uint8Array([0x1d, 0x77, nBarcodeUnitWidth]);
var GS_h_n = new Uint8Array([0x1d, 0x68, nBarcodeHeight]);
var GS_f_n = new Uint8Array([0x1d, 0x66, (nHriFontType & 0x01)]);
var GS_H_n = new Uint8Array([0x1d, 0x48, (nHriFontPosition & 0x03)]);
var STR_UTF8_array = STR2UTF8(str);
var GS_k_m_n_ = new Uint8Array([0x1d, 0x6b, nBarcodeType, STR_UTF8_array.length]);
var data = Uint8ArraysToUint8Array(new Array(
ESC_a_n,
ESC_dollors_nL_nH,
GS_w_n,
GS_h_n,
GS_f_n,
GS_H_n,
GS_k_m_n_,
STR_UTF8_array
));
return data
}
function setQRcode(str, x, nUnitWidth, nVersion, nECCLevel) {
// nUnitWidth 单元宽度 1~6
// nVersion 二维码规格 参数范围0~17 0表示自动选择
// nECCLevel 纠错等级 参数范围1~4
// alignment
var ESC_a_n = new Uint8Array([0x1b, 0x61, 0x00]);
// x position
var ESC_dollors_nL_nH = new Uint8Array([0x1b, 0x24, 0x00, 0x00]);
if (x == -1) {
ESC_a_n[2] = 0x00;
ESC_dollors_nL_nH[2] = 0;
ESC_dollors_nL_nH[3] = 0;
} else if (x == -2) {
ESC_a_n[2] = 0x01;
ESC_dollors_nL_nH[2] = 0;
ESC_dollors_nL_nH[3] = 0;
} else if (x == -3) {
ESC_a_n[2] = 0x02;
ESC_dollors_nL_nH[2] = 0;
ESC_dollors_nL_nH[3] = 0;
} else {
ESC_a_n[2] = 0x00;
ESC_dollors_nL_nH[2] = (x % 0x100);
ESC_dollors_nL_nH[3] = (x / 0x100);
/**
* 设置字体放大背数
* @param w : 1~10倍
* @param h : 1~10倍
*/
setFontWidthAndHeight(w,h){
return this.str = this.str.concat('SETMAG '+ w + ' ' + h +'\r\n');
}
var GS_w_n = new Uint8Array([0x1d, 0x77, nUnitWidth]);
var STR_UTF8_array = STR2UTF8(str);
var GS_k_m_v_r_nL_nH = new Uint8Array([0x1d, 0x6b, 0x61, nVersion, nECCLevel, STR_UTF8_array.length, (STR_UTF8_array.length >> 8)]);
var data = Uint8ArraysToUint8Array(new Array(
ESC_a_n,
ESC_dollors_nL_nH,
GS_w_n,
GS_k_m_v_r_nL_nH,
STR_UTF8_array
));
return data;
}
function setString(str, x, nWidthScale, nHeightScale, nFontType, nFontStyle) {
// let arr1 = print.setString("PrintTest打印测试\r\n", 0, 0, 0, 0, 0x08);//粗体
// let arr2 = print.setString("PrintTest打印测试\r\n", 0, 0, 0, 0, 0x80);//下划线细
// let arr3 = print.setString("PrintTest打印测试\r\n", 0, 0, 0, 0, 0x100);//下划线粗
// let arr4 = print.setString("PrintTest打印测试\r\n", 0, 0, 0, 0, 0x200);//上下颠倒
// let arr5 = print.setString("PrintTest打印测试\r\n", 0, 0, 0, 0, 0x400);//反白
// let arr6 = print.setString("PrintTest打印测试\r\n", 0, 0, 0, 0, 0x1000);//顺时针90
// let arr7 = print.setString("PrintTest打印测试\r\n", 0, 0, 0, 0, 0x100 + 0x08);//下划线粗+粗体
// let arr8 = print.setString("PrintTest打印测试\r\n", 0, 0, 1, 0, 0);//倍高
// let arr9 = print.setString("PrintTest打印测试\r\n", 0, 1, 0, 0, 0);//倍宽
// let arr10 = print.setString("PrintTest打印测试\r\n", 0, 1, 1, 0, 0);//倍宽高
// alignment
var ESC_a_n = new Uint8Array([0x1b, 0x61, 0x00]);
// x position
var ESC_dollors_nL_nH = new Uint8Array([0x1b, 0x24, 0x00, 0x00]);
if (x == -1) {
ESC_a_n[2] = 0x00;
ESC_dollors_nL_nH[2] = 0;
ESC_dollors_nL_nH[3] = 0;
} else if (x == -2) {
ESC_a_n[2] = 0x01;
ESC_dollors_nL_nH[2] = 0;
ESC_dollors_nL_nH[3] = 0;
} else if (x == -3) {
ESC_a_n[2] = 0x02;
ESC_dollors_nL_nH[2] = 0;
ESC_dollors_nL_nH[3] = 0;
} else {
ESC_a_n[2] = 0x00;
ESC_dollors_nL_nH[2] = (x % 0x100);
ESC_dollors_nL_nH[3] = (x / 0x100);
}
// scale
var GS_exclamationmark_n = new Uint8Array([0x1d, 0x21, (nHeightScale | (nWidthScale << 4))]);
// fonttype
var ESC_M_n = new Uint8Array([0x1b, 0x4d, nFontType]);
// bold
var ESC_E_n = new Uint8Array([0x1b, 0x45, ((nFontStyle >> 3) & 0x01)]);
// underline
var ESC_line_n = new Uint8Array([0x1b, 0x2d, ((nFontStyle >> 7) & 0x03)]);
var FS_line_n = new Uint8Array([0x1c, 0x2d, ((nFontStyle >> 7) & 0x03)]);
// upside down
var ESC_lbracket_n = new Uint8Array([0x1b, 0x7b, ((nFontStyle >> 9) & 0x01)]);
// black white reverse display
var GS_B_n = new Uint8Array([0x1d, 0x42, ((nFontStyle >> 10) & 0x01)]);
// rotate 90
var ESC_V_n = new Uint8Array([0x1b, 0x56, ((nFontStyle >> 12) & 0x01)]);
//var CMD_UTF8 = new Uint8Array([0x1c, 0x26, 0x1b, 0x39, 0x01]);
var CMD_GBK = new Uint8Array([0x1c, 0x26, 0x1b, 0x39, 0x00]);
//var STR_UTF8_array = STR2UTF8(str);
var STR_GBK_array = STR2GBK(str);
var data = Uint8ArraysToUint8Array(new Array(
ESC_a_n,
ESC_dollors_nL_nH,
GS_exclamationmark_n,
ESC_M_n,
ESC_E_n,
ESC_line_n,
FS_line_n,
ESC_lbracket_n,
GS_B_n,
ESC_V_n,
//CMD_UTF8,
CMD_GBK,
//STR_UTF8_array
STR_GBK_array
));
return data
}
function print_FeedLine() {
//0d 回车
//0a 打印并进纸一行
var data = new Uint8Array([0x0d, 0x0a]);
return data
}
function Uint8ArraysToUint8Array(arrs) {
//Uint8Array数组合并
var new_len = 0;
for (var i = 0; i < arrs.length; ++i) {
var arr = arrs[i];
new_len += arr.length;
}
var new_arr = new Uint8Array(new_len);
var new_idx = 0;
for (var i = 0; i < arrs.length; ++i) {
var arr = arrs[i];
for (var j = 0; j < arr.length; ++j) {
new_arr[new_idx++] = arr[j];
/**
* 打印文本且换行
* @param {*} fontSize 字体大小 取值 1 : 8*12大小 ; 55 : 16*16大小 ; 4 : 32*32大小 其他默认 24*24大小
* @param {*} x 横向起始位置
* @param {*} y 纵向起始位置
* @param {*} text 要打印的文本
*/
printlnText(fontSize,style,x,y,text){
var t = 8;
if(t){
t = fontSize;
}
// return this.str = this.str.concat('TEXT ' + t + ' 1 ' + x + ' ' + y +' ' + text+'\r\n');
return this.str = this.str.concat('TEXT ' + t + ' ' + style + ' ' + x + ' ' + y +' ' + text+'\r\n');
}
return new_arr;
}
function STR2GBK(str) {
var bytes = new Array();
var len, c;
len = str.length;
var u = utcp.str2gbk()
for (var i = 0; i < len; i++) {
c = str.charCodeAt(i);
if (c < 0x80) {
bytes.push(c & 0xFF)
continue
/**
* 打印文本且换行 逆时针旋转270度,纵向打印文本
* @param {*} fontSize 字体大小 取值 1 : 8*12大小 ; 55 : 16*16大小 ; 4 : 32*32大小 其他默认 24*24大小
* @param {*} x 横向起始位置
* @param {*} y 纵向起始位置
* @param {*} text 要打印的文本
*/
printlnText270(fontSize,x,y,text){
var t = 8;
if(t){
t = fontSize;
}
// Uint8 ch0 = u[i * 2];
// Uint8 ch1 = u[i * 2 + 1];
// console.log(u[c * 2])
// console.log(u[c * 2 + 1])
if ((u[c * 2] == 0) && (u[c * 2 + 1] == 0))
continue
if (u[c * 2] == 0)
continue
if (u[c * 2] < 0x80)
continue
if ((u[c * 2] == 0xff) || (u[c * 2 + 1] < 0x40))
continue
bytes.push(u[c * 2] & 0xFF)
bytes.push(u[c * 2 + 1] & 0xFF)
return this.str = this.str.concat('TEXT270 ' + t + ' 0 ' + x + ' ' + y +' ' + text+'\r\n');
}
return new Uint8Array(bytes);
}
function STR2UTF8(str) {
var bytes = new Array();
var len, c;
len = str.length;
for (var i = 0; i < len; i++) {
c = str.charCodeAt(i);
if (c >= 0x010000 && c <= 0x10FFFF) {
bytes.push(((c >> 18) & 0x07) | 0xF0);
bytes.push(((c >> 12) & 0x3F) | 0x80);
bytes.push(((c >> 6) & 0x3F) | 0x80);
bytes.push((c & 0x3F) | 0x80);
} else if (c >= 0x000800 && c <= 0x00FFFF) {
bytes.push(((c >> 12) & 0x0F) | 0xE0);
bytes.push(((c >> 6) & 0x3F) | 0x80);
bytes.push((c & 0x3F) | 0x80);
} else if (c >= 0x000080 && c <= 0x0007FF) {
bytes.push(((c >> 6) & 0x1F) | 0xC0);
bytes.push((c & 0x3F) | 0x80);
} else {
bytes.push(c & 0xFF);
}
/**
*
* @param {} x0 起点的x坐标
* @param {} y0 起点的y坐标
* @param {} x1 终点的x坐标
* @param {} y1 终点的y坐标
* @param {} width 线宽
*/
printLine(x0,y0,x1,y1,width){
return this.str = this.str.concat('LINE ' + x0 + ' ' + y0 + ' ' + x1 + ' ' + y1 + ' ' + width + '\r\n');
}
return new Uint8Array(bytes);
}
function setImageRGBA(img, w, h, x, nBinaryAlgorithm) {
//w 宽度
//h 高度
//x 定位 -1居左 -2居中 -3居右
//nBinaryAlgorithm 图片转换算法 0抖动算法 1阀值算法
if ((w <= 0) || (h <= 0))
return false;
var imggray = new Uint8Array(w * h);
ImageRGBAToImageGray(w, h, img, imggray);
var img1 = new Uint8Array(w * h);
switch (nBinaryAlgorithm) {
case 0:
ImageGrayToImage1_Dithering(w, h, imggray, img1);
break;
case 1:
default:
ImageGrayToImage1_Threshold(w, h, imggray, img1);
break;
/**
* 打印横向条码和文字
* @param {} x 横向起始位置
* @param {} y 纵向起始位置
* @param {} height 条码的高度
* @param {} data 条码数据
*/
printSweepCodeAndText(x,y,height,data){
this.setSweepCodeText();
this.str = this.str.concat('BARCODE 128 3 1 '+ height + ' ' + x + ' ' + y + ' ' + data +'\r\n');
this.setSweepCodeTextEnd();
return this.str;
}
return setImage(img1, w, h, x);
}
function setImage(img, w, h, x) {
// alignment
var ESC_a_n = new Uint8Array([0x1b, 0x61, 0x00]);
// x position
var ESC_dollors_nL_nH = new Uint8Array([0x1b, 0x24, 0x00, 0x00]);
if (x == -1) {
ESC_a_n[2] = 0x00;
ESC_dollors_nL_nH[2] = 0;
ESC_dollors_nL_nH[3] = 0;
} else if (x == -2) {
ESC_a_n[2] = 0x01;
ESC_dollors_nL_nH[2] = 0;
ESC_dollors_nL_nH[3] = 0;
} else if (x == -3) {
ESC_a_n[2] = 0x02;
ESC_dollors_nL_nH[2] = 0;
ESC_dollors_nL_nH[3] = 0;
} else {
ESC_a_n[2] = 0x00;
ESC_dollors_nL_nH[2] = (x % 0x100);
ESC_dollors_nL_nH[3] = (x / 0x100);
/**
* 打印横向条码
* @param {} x 横向起始位置
* @param {} y 纵向起始位置
* @param {} height 条码的高度
* @param {} data 条码数据
*/
printSweepCode(x,y,height,data){
return this.str = this.str.concat('BARCODE 128 3 1 '+ height + ' ' + x + ' ' + y + ' ' + data +'\r\n');
}
var IMG_Array = Image1ToRasterCmd(w, h, img);
var BR = new Uint8Array([0x0d, 0x0a]);
var data = Uint8ArraysToUint8Array(new Array(
ESC_a_n,
ESC_dollors_nL_nH,
IMG_Array,
BR,
BR,
BR
));
return data
}
function setImageCompressRGBA(img, w, h, x, nBinaryAlgorithm) {
//nBinaryAlgorithm 图片转换算法 0抖动算法 1阀值算法
if ((w <= 0) || (h <= 0))
return false;
var imggray = new Uint8Array(w * h);
ImageRGBAToImageGray(w, h, img, imggray);
var img1 = new Uint8Array(w * h);
switch (nBinaryAlgorithm) {
case 0:
ImageGrayToImage1_Dithering(w, h, imggray, img1);
break;
case 1:
default:
ImageGrayToImage1_Threshold(w, h, imggray, img1);
break;
/**
* 设置横向条码文本起始
*/
setSweepCodeText(){
return this.str = this.str.concat('BARCODE-TEXT 7 0 5\r\n');
}
return setImageCompress(img1, w, h, x);
}
function setImageCompress(img, w, h, x) {
// alignment
var ESC_a_n = new Uint8Array([0x1b, 0x61, 0x00]);
// x position
var ESC_dollors_nL_nH = new Uint8Array([0x1b, 0x24, 0x00, 0x00]);
if (x == -1) {
ESC_a_n[2] = 0x00;
ESC_dollors_nL_nH[2] = 0;
ESC_dollors_nL_nH[3] = 0;
} else if (x == -2) {
ESC_a_n[2] = 0x01;
ESC_dollors_nL_nH[2] = 0;
ESC_dollors_nL_nH[3] = 0;
} else if (x == -3) {
ESC_a_n[2] = 0x02;
ESC_dollors_nL_nH[2] = 0;
ESC_dollors_nL_nH[3] = 0;
} else {
ESC_a_n[2] = 0x00;
ESC_dollors_nL_nH[2] = (x % 0x100);
ESC_dollors_nL_nH[3] = (x / 0x100);
/**
* 设置横向条码文本结束
*/
setSweepCodeTextEnd(){
return this.str = this.str.concat('BARCODE-TEXT OFF\r\n');
}
var IMG_DATA = Image1ToRasterData(w, h, img);
var IMG_Array = RasterDataToCompressCmd(w, h, IMG_DATA);
var BR = new Uint8Array([0x0d, 0x0a]);
var data = Uint8ArraysToUint8Array(new Array(
ESC_a_n,
ESC_dollors_nL_nH,
IMG_Array,
BR,
BR,
BR
));
return data
}
// Label Function
function LABEL_PageBegin(startx, starty, width, height, rotate) {
// x
// Page页面参考原点相对标签纸当前位置左上角的x轴偏移量。
// y
// Page页面参考原点相对标签纸当前位置左上角的y轴偏移量。
// Width
// Page页面页宽, x + Width的取值范围为:[1, 576]。
// Height
// Page页面页高,Heigth的取值范围为:[1, 1200]。
// Rotate
// Page页面旋转角度,Rotate的取值范围为:{ 0, 1 } 。当Rotate为0时,页面不旋转。当Rotate为1时,页面旋转90°打印。
// Set Codepage To UTF8
// var CMD_UTF8 = new Uint8Array([0x1c, 0x26, 0x1b, 0x39, 0x01]);
var CMD_GBK = new Uint8Array([0x1c, 0x26, 0x1b, 0x39, 0x00]);
var data = new Uint8Array(12);
data[0] = 0x1A;
data[1] = 0x5B;
data[2] = 0x01;
data[3] = (startx & 0xFF);
data[4] = ((startx >> 8) & 0xFF);
data[5] = (starty & 0xFF);
data[6] = ((starty >> 8) & 0xFF);
data[7] = (width & 0xFF);
data[8] = ((width >> 8) & 0xFF);
data[9] = (height & 0xFF);
data[10] = ((height >> 8) & 0xFF);
data[11] = (rotate & 0xFF);
data = Uint8ArraysToUint8Array(new Array(
CMD_GBK,
data
));
return data;
}
function LABEL_PageEnd() {
var data = new Uint8Array([0x1A, 0x5D, 0x00]);
return data;
}
function LABEL_PagePrint(num) {
// PrintNum
// Page页面内容将打印PrintNum次。
var data = new Uint8Array([0x1A, 0x4F, 0x01, num]);
return data;
}
function LABEL_PageFeed() {
//走纸
var data = new Uint8Array([0x1A, 0x0C, 0x00]);
return data;
}
function LABEL_PageCalibrate() {
//校准
var data = new Uint8Array([0x1f, 0x63]);
return data;
}
function LABEL_DrawLine(startx, starty, endx, endy, width, color) {
// StartX
// 直线段起始点x坐标值,取值范围:[0, Page_Width - 1]。
// StartY
// 直线段起始点y坐标值,取值范围:[0,Page_Height - 1]。
// EndX
// 直线段终止点x坐标值,取值范围:[0, Page_Width - 1]。
// EndY
// 直线段终止点y坐标值,取值范围:[0, Page_Height - 1]。
// Width
// 直线段线宽,取值范围:[1,Page_Height - 1]。
// Color
// 直线段颜色,取值范围:{ 0, 1 ,2} 。当Color为1时,线段为黑色。当Color为0时,线段为白色。当Color为2时,线段为虚线。
var data = new Uint8Array(14);
data[0] = 0x1A;
data[1] = 0x5C;
data[2] = 0x01;
data[3] = (startx & 0xFF);
data[4] = ((startx >> 8) & 0xFF);
data[5] = (starty & 0xFF);
data[6] = ((starty >> 8) & 0xFF);
data[7] = (endx & 0xFF);
data[8] = ((endx >> 8) & 0xFF);
data[9] = (endy & 0xFF);
data[10] = ((endy >> 8) & 0xFF);
data[11] = (width & 0xFF);
data[12] = ((width >> 8) & 0xFF);
data[13] = (color & 0xFF);
return data;
}
function LABEL_DrawBox(left, top, right, bottom, borderwidth, bordercolor) {
// Left
// 矩形框左上角x 坐标值,取值范围:[0, Page_Width - 1]。
// Top
// 矩形框左上角y坐标值。取值范围:[0, Page_Height - 1]。
// Right
// 矩形框右下角x坐标值。取值范围:[0, Page_Width - 1]。
// Bottom
// 矩形框右下角y坐标值。取值范围:[0, Page_Height - 1]。
// Width
// 矩形框线宽。
// Color
// 矩形框线颜色,曲直范围{ 0, 1 ,2} 。当Color = 1时,绘制黑色矩形宽,Color = 0 时,绘制白色矩形框。绘制白色矩形框。Color = 2 时,绘制虚线矩形框。
var data = new Uint8Array(14);
data[0] = 0x1A;
data[1] = 0x26;
data[2] = 0x01;
data[3] = (left & 0xFF);
data[4] = ((left >> 8) & 0xFF);
data[5] = (top & 0xFF);
data[6] = ((top >> 8) & 0xFF);
data[7] = (right & 0xFF);
data[8] = ((right >> 8) & 0xFF);
data[9] = (bottom & 0xFF);
data[10] = ((bottom >> 8) & 0xFF);
data[11] = (borderwidth & 0xFF);
data[12] = ((borderwidth >> 8) & 0xFF);
data[13] = (bordercolor & 0xFF);
return data;
}
function LABEL_DrawRectangel(left, top, right, bottom, color) {
// Left
// 矩形块左上角x 坐标值,取值范围:[0, Page_Width - 1]。
// Top
// 矩形块左上角y坐标值。取值范围:[0, Page_Height - 1]。
// Right
// 矩形块右下角x坐标值。取值范围:[0, Page_Width - 1]。
// Bottom
// 矩形块右下角y坐标值。取值范围:[0, Page_Height - 1]。
// Color
// 矩形块颜色,取值范围:{ 0, 1 } 。当Color为1时,矩形块为黑色。当Color为0
// 时,矩形块为白色
var data = new Uint8Array(12);
data[0] = 0x1A;
data[1] = 0x2A;
data[2] = 0x00;
data[3] = (left & 0xFF);
data[4] = ((left >> 8) & 0xFF);
data[5] = (top & 0xFF);
data[6] = ((top >> 8) & 0xFF);
data[7] = (right & 0xFF);
data[8] = ((right >> 8) & 0xFF);
data[9] = (bottom & 0xFF);
data[10] = ((bottom >> 8) & 0xFF);
data[11] = (color & 0xFF);
return data;
}
function LABEL_DrawPlainText(startx, starty, font, style, str) {
// X
// 定义文本起始位置x坐标,取值范围:[0, Page_Width - 1];
// y
// 定义文本起始位置y坐标,取值范围:[0, Page_Height - 1];
// FontHeight
// 文本字符字体高度,有效值范围为{ 16, 24, 32, 48, 64, 80, 96 } (个别机型为{ 16, 17, 18, 24 }) 。
// FontType
// 文本字符特效,各位定义如下:
// 数据位 定义
// 0 加粗标志位:置 1 字体加粗,清零则字体不加粗。
// 1 下划线标志位:置 1 文本带下划线,清零则无下划线。
// 2 反白标志位:置 1 文本反白(黑底白字) ,清零不反白。
// 3 删除线标志位:置 1 文本带删除线,清零则无删除线。
// [5, 4] 旋转标志位:00 旋转 0° ; 01 旋转 90°; 10 旋转 180°; 11 旋转 270°。 (当需要旋转是需要注意起始点坐标)
// [11, 8] 字体宽度放大倍数;
// [15, 12] 字体高度放大倍数;
var CMD_HEAD = new Uint8Array(11);
CMD_HEAD[0] = 0x1A;
CMD_HEAD[1] = 0x54;
CMD_HEAD[2] = 0x01;
CMD_HEAD[3] = (startx & 0xFF);
CMD_HEAD[4] = ((startx >> 8) & 0xFF);
CMD_HEAD[5] = (starty & 0xFF);
CMD_HEAD[6] = ((starty >> 8) & 0xFF);
CMD_HEAD[7] = (font & 0xFF);
CMD_HEAD[8] = ((font >> 8) & 0xFF);
CMD_HEAD[9] = (style & 0xFF);
CMD_HEAD[10] = ((style >> 8) & 0xFF);
//var STR_UTF8_array = STR2UTF8(str);
// var STR_UTF8_array = STR2GBK(str);
// var STR_GBK_array = STR2GBK(str);
var u8 = hexStringToBuff(str);
var STR_GBK_array = new Uint8Array(u8);
var STR_TAIL = new Uint8Array([0]);
var data = Uint8ArraysToUint8Array(new Array(
CMD_HEAD,
STR_GBK_array,
STR_TAIL
));
return data;
}
function sumStrLength(str) {
var length = 0;
var data = str.toString();
for (var i = 0; i < data.length; i++) {
if (isCN(data[i])) { //是中文
length += 2;
} else {
length += 1;
}
}
return length;
}
function isCN(str) {
if (/^[\u3220-\uFA29]+$/.test(str)) {
return true;
} else {
return false;
}
}
const hexStringToBuff = str => { //str='中国:WXHSH'
const buffer = new ArrayBuffer((sumStrLength(str)) * 4)
const dataView = new DataView(buffer)
var data = str.toString();
var p = 0; //ArrayBuffer 偏移量
for (var i = 0; i < data.length; i++) {
if (isCN(data[i]) || data[i] == "√") { //是中文
//调用GBK 转码
var t = gbk.encode(data[i]);
for (var j = 0; j < 2; j++) {
//var code = t[j * 2] + t[j * 2 + 1];
var code = t[j * 3 + 1] + t[j * 3 + 2];
var temp = parseInt(code, 16)
//var temp = strToHexCharCode(code);
dataView.setUint8(p++, temp)
}
} else {
var temp = data.charCodeAt(i);
dataView.setUint8(p++, temp)
}
}
return buffer;
}
function LABEL_DrawBarcode(startx, starty, type, height, unitwidth, rotate, str) {
// x
// 条码左上角x坐标值,取值范围:[0, Page_Width - 1]。
// y
// 条码左上角y坐标值,取值范围:[0, Page_Height - 1]。
// BarcodeType
// 标识条码类型,取值范围:[0, 29]。各值定义如下:
// 值 类型 长度 条码值范围 备注
// 0 UPC - A 11 48 - 57
// 1 UPC - E 6 48 - 57
// 2 EAN13 12 48 - 57
// 3 EAN8 7 48 - 57
// 4 CODE39 1- 48 - 57, 65 - 90, 32, 36, 37, 43, 45, 46, 47
// 5 I25 1- 偶数 48 - 57
// 6 CODABAR 1- 48 - 57, 65 - 68, 36, 43, 45, 46, 47, 58
// 7 CODE93 1-255 0 - 127
// 8 CODE128 2-255 0 - 127
// 9 CODE11
// 10 MSI
// 11 128M 可以根据数据切换编码模式 -> !096 - !105
// 12 EAN128 自动切换编码模式
// 13 25C 25C Check use mod 10 -> 奇数先在前面补0, 10的倍数 - [(奇数位的数字之和 < 从左至右) + (偶数位数字之和) * 3]
// 14 39C 39码的检查码必须搭配「检查码相对值对照表」,如表所示,将查出的相对值累加后再除以43,得到的余数再查出相对的编码字元,即为检查码字元。
// 15 39 Full ASCII 39 Code, 特殊字符用两个可表示的字来表示, 39C 同样是包含Full ASCII, 注意宽窄比处理
// 16 EAN13 + 2 附加码与主码间隔 7 - 12 单位,起始为 1011 间隔为 01 ,(_0 * 10 + _1) Mod 4 -> 0--AA 1--AB 2--BA 3--BB
// 17 EAN13 + 5 附加码部分同上,模式((_0 + _2 + _4) * 3 + (_1 + _3) * 9) mod 10 -> "bbaaa", "babaa", "baaba", "baaab", "abbaa", "aabba", "aaabb", "ababa", "abaab", "aabab
// 18 EAN8 + 2 同 EAN13 + 2
// 19 EAN8 + 5 同 EAN13 + 5
// 20 POST 详见规格说明,是高低条码,不是宽窄条码
// 21 UPCA + 2 附加码见 EAN
// 22 UPCA + 5 附加码见 EAN
// 23 UPCE + 2 附加码见 EAN
// 24 UPCE + 5 附加码见 EAN
// 25 CPOST
// 26 MSIC 将检查码作为数据再计算一次检查码
// 27 PLESSEY
// 28 ITF14 25C 变种, 第一个数前补0,检查码计算时需扣除最后一个数,但仍填充为最尾端
// 29 EAN14
// BarcodeHeight:
// 定义条码高度。
// UnitWidth:
// 定义条码码宽。取值范围:[1, 4]。各值定义如下:
// Width取值 多级条码单位宽度(mm) 二进制条码窄线条宽度 二进制条码宽线条宽度
// 1 0.125 0.125 0.25
// 2 0.25 0.25 0.50
// 3 0.375 0.375 0.75
// 4 0.50 0.50 1.0
// Rotate:
// 表示条码旋转角度。取值范围:[0, 3]。各值定义如下:
// Rotate取值 定义
// 0 条码不旋转绘制。
// 1 条码旋转 90°绘制。
// 2 条码旋转 180°绘制。
// 3 条码旋转 270°绘制。
var CMD_HEAD = new Uint8Array(11);
CMD_HEAD[0] = 0x1A;
CMD_HEAD[1] = 0x30;
CMD_HEAD[2] = 0x00;
CMD_HEAD[3] = (startx & 0xFF);
CMD_HEAD[4] = ((startx >> 8) & 0xFF);
CMD_HEAD[5] = (starty & 0xFF);
CMD_HEAD[6] = ((starty >> 8) & 0xFF);
CMD_HEAD[7] = (type & 0xFF);
CMD_HEAD[8] = (height & 0xFF);
CMD_HEAD[9] = (unitwidth & 0xFF);
CMD_HEAD[10] = (rotate & 0xFF);
var STR_UTF8_array = STR2UTF8(str);
var STR_TAIL = new Uint8Array([0]);
var data = Uint8ArraysToUint8Array(new Array(
CMD_HEAD,
STR_UTF8_array,
STR_TAIL
));
return data;
}
function LABEL_DrawQRCode(startx, starty, version, ecc, unitwidth, rotate, str) {
// version
// 指定字符版本。取值范围:[0, 20]。当version为0时,打印机根据字符串长度自动计算版本号。
// ECC
// 指定纠错等级。取值范围:[1, 4]。各值定义如下:
// ECC 纠错等级
// 1 L:7 %,低纠错,数据多。
// 2 M:15 %,中纠错
// 3 Q:优化纠错
// 4 H:30 %,最高纠错,数据少。
// x
// QRCode码左上角x坐标值,取值范围:[0,Page_Width - 1]。
// y
// QRCode码左上角y坐标值,取值范围:[0, Page_Height - 1]。
// UnitWidth
// QRCode码码块,取值范围:[1, 4]。各值定义与指令输入参数UniWidth相同。
// Rotate
// QRCode码旋转角度,取值范围:[0, 3]。各值定义与指令输入参数Rotate相同。
var CMD_HEAD = new Uint8Array(11);
CMD_HEAD[0] = 0x1A;
CMD_HEAD[1] = 0x31;
CMD_HEAD[2] = 0x00;
CMD_HEAD[3] = (version & 0xFF);
CMD_HEAD[4] = (ecc & 0xFF);
CMD_HEAD[5] = (startx & 0xFF);
CMD_HEAD[6] = ((startx >> 8) & 0xFF);
CMD_HEAD[7] = (starty & 0xFF);
CMD_HEAD[8] = ((starty >> 8) & 0xFF);
CMD_HEAD[9] = (unitwidth & 0xFF);
CMD_HEAD[10] = (rotate & 0xFF);
var STR_UTF8_array = STR2UTF8(str);
var STR_TAIL = new Uint8Array([0]);
var data = Uint8ArraysToUint8Array(new Array(
CMD_HEAD,
STR_UTF8_array,
STR_TAIL
));
return data;
}
function LABEL_DrawPDF417(startx, starty, colnum, lwratio, ecc, unitwidth, rotate, str) {
// ColNum
// ColNum为列数,表述每行容纳多少码字。一个码字为17 * UnitWidth个点。
// 行数由打印机自动产生,行数范围限定为3~90。ColNum的取值范围:[1, 30];
// lwratio
// [长度/高度]
// ECC
// 纠错等级,取值范围:[0. 8]。
// x PDF417码左上角x坐标值,取值范围:[0,Page_Width - 1]。
// y PDF417码左上角y坐标值,取值范围:[0, Page_Height - 1]。
// UnitWidth
// PDF417码码宽,取值范围:[1, 3]。各值定义与指令输入参数UniWidth相同。
// Rotate
// PDF417码旋转角度,取值范围:[0, 3]。各值定义与指令输入参数Rotate相同。
var CMD_HEAD = new Uint8Array(12);
CMD_HEAD[0] = 0x1A;
CMD_HEAD[1] = 0x31;
CMD_HEAD[2] = 0x01;
CMD_HEAD[3] = (colnum & 0xFF);
CMD_HEAD[4] = (ecc & 0xFF);
CMD_HEAD[5] = (lwratio & 0xFF);
CMD_HEAD[6] = (startx & 0xFF);
CMD_HEAD[7] = ((startx >> 8) & 0xFF);
CMD_HEAD[8] = (starty & 0xFF);
CMD_HEAD[9] = ((starty >> 8) & 0xFF);
CMD_HEAD[10] = (unitwidth & 0xFF);
CMD_HEAD[11] = (rotate & 0xFF);
var STR_UTF8_array = STR2UTF8(str);
var STR_TAIL = new Uint8Array([0]);
var data = Uint8ArraysToUint8Array(new Array(
CMD_HEAD,
STR_UTF8_array,
STR_TAIL
));
return data;
}
function LABEL_DrawImage1(startx, starty, width, height, style, img) {
// x
// 位图左上角x坐标值,取值范围:[0, Page_Width]。
// y
// 位图左上角y坐标值,取值范围:[0, Page_Height]。
// Width
// 位图的像素宽度。
// Height
// 位图的像素高度。
// style
// 位图打印特效,style 值各位定义如下:
// 位 定义
// 0 反白标志位,置 1 位图反白打印,清零正常打印。
// [2: 1] 旋转标志位: 00 旋转 0° ; 01 旋转 90°; 10 旋转 180°; 11 旋转 270°
// [7: 3] 保留。
// [11: 8] 位图宽度放大倍数。
// [15: 16] 位图高度放大倍数。
var CMD_HEAD = new Uint8Array(13);
CMD_HEAD[0] = 0x1A;
CMD_HEAD[1] = 0x21;
CMD_HEAD[2] = 0x01;
CMD_HEAD[3] = (startx & 0xFF);
CMD_HEAD[4] = ((startx >> 8) & 0xFF);
CMD_HEAD[5] = (starty & 0xFF);
CMD_HEAD[6] = ((starty >> 8) & 0xFF);
CMD_HEAD[7] = (width & 0xFF);
CMD_HEAD[8] = ((width >> 8) & 0xFF);
CMD_HEAD[9] = (height & 0xFF);
CMD_HEAD[10] = ((height >> 8) & 0xFF);
CMD_HEAD[11] = (style & 0xFF);
CMD_HEAD[12] = ((style >> 8) & 0xFF);
var IMG_DATA = Image1ToRasterData(width, height, img);
var data = Uint8ArraysToUint8Array(new Array(
CMD_HEAD,
IMG_DATA
));
console.log(width)
console.log(height)
console.log(data.length)
return data;
}
function LABEL_DrawImageRGBA(startx, starty, width, height, style, img, nBinaryAlgorithm) {
// x
// 位图左上角x坐标值,取值范围:[0, Page_Width]。
// y
// 位图左上角y坐标值,取值范围:[0, Page_Height]。
// Width
// 位图的像素宽度。
// Height
// 位图的像素高度。
// style
// 位图打印特效,style 值各位定义如下:
// 位 定义
// 0 反白标志位,置 1 位图反白打印,清零正常打印。
// [2: 1] 旋转标志位: 00 旋转 0° ; 01 旋转 90°; 10 旋转 180°; 11 旋转 270°
// [7: 3] 保留。
// [11: 8] 位图宽度放大倍数。
// [15: 16] 位图高度放大倍数
//nBinaryAlgorithm 图片转换算法 0抖动算法 1阀值算法
if ((width <= 0) || (height <= 0))
return false;
var imggray = new Uint8Array(width * height);
ImageRGBAToImageGray(width, height, img, imggray);
var img1 = new Uint8Array(width * height);
switch (nBinaryAlgorithm) {
case 0:
ImageGrayToImage1_Dithering(width, height, imggray, img1);
break;
case 1:
default:
ImageGrayToImage1_Threshold(width, height, imggray, img1);
break;
/**
* 设置纵向条码文本起始
*/
setSweepCodeTextVertical(){
return this.str = this.str.concat('VBARCODE-TEXT 7 0 5\r\n');
}
return LABEL_DrawImage1(startx, starty, width, height, style, img1);
}
function ImageGrayToImage1_Threshold(width, height, src, dst) {
var pixel_count = width * height;
var graytotal = 0;
for (var pixel_index = 0; pixel_index < pixel_count; ++pixel_index) {
graytotal += src[pixel_index];
/**
* 设置纵向条码文本结束
*/
setSweepCodeTextEndVertical(){
return this.str = this.str.concat('VBARCODE-TEXT OFF\r\n');
}
var grayave = graytotal / pixel_count;
/* 二值化 */
for (var pixel_index = 0; pixel_index < pixel_count; ++pixel_index) {
dst[pixel_index] = src[pixel_index] > grayave ? 0 : 1;
/**
* 纵向打印条码和文字
* @param {} x 横向起始位置
* @param {} y 纵向终点位置
* @param {} height 条码的高度
* @param {} data 条码数据
*/
printSweepCodeAndTextVertical(x,y,height,data){
this.setSweepCodeTextVertical();
this.str = this.str.concat('VBARCODE 128 3 1 '+ height + ' ' + x + ' ' + y + ' ' + data +'\r\n');
this.setSweepCodeTextEndVertical();
return this.str;
}
}
function ImageGrayToImage1_Dithering(width, height, src, dst) {
var pixel_index = 0;
var Floyd16x16 = [
[0, 128, 32, 160, 8, 136, 40, 168, 2, 130, 34, 162, 10, 138, 42, 170],
[192, 64, 224, 96, 200, 72, 232, 104, 194, 66, 226, 98, 202, 74, 234, 106],
[48, 176, 16, 144, 56, 184, 24, 152, 50, 178, 18, 146, 58, 186, 26, 154],
[240, 112, 208, 80, 248, 120, 216, 88, 242, 114, 210, 82, 250, 122, 218, 90],
[12, 140, 44, 172, 4, 132, 36, 164, 14, 142, 46, 174, 6, 134, 38, 166],
[204, 76, 236, 108, 196, 68, 228, 100, 206, 78, 238, 110, 198, 70, 230, 102],
[60, 188, 28, 156, 52, 180, 20, 148, 62, 190, 30, 158, 54, 182, 22, 150],
[252, 124, 220, 92, 244, 116, 212, 84, 254, 126, 222, 94, 246, 118, 214, 86],
[3, 131, 35, 163, 11, 139, 43, 171, 1, 129, 33, 161, 9, 137, 41, 169],
[195, 67, 227, 99, 203, 75, 235, 107, 193, 65, 225, 97, 201, 73, 233, 105],
[51, 179, 19, 147, 59, 187, 27, 155, 49, 177, 17, 145, 57, 185, 25, 153],
[243, 115, 211, 83, 251, 123, 219, 91, 241, 113, 209, 81, 249, 121, 217, 89],
[15, 143, 47, 175, 7, 135, 39, 167, 13, 141, 45, 173, 5, 133, 37, 165],
[207, 79, 239, 111, 199, 71, 231, 103, 205, 77, 237, 109, 197, 69, 229, 101],
[63, 191, 31, 159, 55, 183, 23, 151, 61, 189, 29, 157, 53, 181, 21, 149],
[254, 127, 223, 95, 247, 119, 215, 87, 253, 125, 221, 93, 245, 117, 213, 85]
];
for (var y = 0; y < height; ++y) {
for (var x = 0; x < width; ++x) {
dst[pixel_index++] = src[pixel_index] > Floyd16x16[x & 15][y & 15] ? 0 : 1;
}
/**
* 纵向打印条码
* @param {} x 横向起始位置
* @param {} y 纵向终点位置
* @param {} height 条码的高度
* @param {} data 条码数据
*/
printSweepCodeVertical(x,y,height,data){
return this.str = this.str.concat('VBARCODE 128 3 1 '+ height + ' ' + x + ' ' + y + ' ' + data +'\r\n');
}
}
function ImageRGBAToImageGray(width, height, src, dst) {
var pixel_count = width * height;
var src_index = 0;
var dst_index = 0;
for (var pixel_index = 0; pixel_index < pixel_count; ++pixel_index) {
var r = src[src_index + 0];
var g = src[src_index + 1];
var b = src[src_index + 2];
var a = src[src_index + 3];
if (a == 0)
dst[dst_index] = 255;
else
dst[dst_index] = parseInt((r * 0.299 + g * 0.587 + b * 0.114));
src_index += 4;
dst_index += 1;
/**
*
* @param {} x 横向起始位置
* @param {} y 纵向起始位置
* @param {} WAndH 二维码宽高,范围:1~32
* @param {} data 填入二维码的数据
*/
printQRCode(x,y,wAndH,data){
return this.str = this.str.concat('BARCODE QR ' + x + ' ' + y + ' M 2 U '+ wAndH +'\r\nMA,' + data + '\r\nENDQR\r\n');
}
}
function CompressDataBuf(src, index, width) {
var samedata = 1
var dst = []
var idx = 0
for (let i = index; i < index + width; i++) {
if (src[i] == src[i + 1]) {
if (i == index + width - 1) {
dst[idx] = src[i]
dst[idx + 1] = samedata
samedata = 1
idx += 2
} else {
samedata++
continue
}
} else {
dst[idx] = src[i]
dst[idx + 1] = samedata
samedata = 1
idx += 2
}
/**
* 对齐方式 center right left
* @param {*} alignMethod
*/
setAlign(alignMethod){
return this.str = this.str.concat(alignMethod.toUpperCase()+'\r\n');
}
console.log(dst)
return dst
}
function RasterDataToCompressCmd(width, height, src) {
var x = parseInt(width / 8);
var dst = []
var dst_offset = 0
for (let y = 0; y < height; y++) {
let dst_buffer = CompressDataBuf(src, y * x, x)
dst[dst_offset + 0] = 0x1f;
dst[dst_offset + 1] = 0x28;
dst[dst_offset + 2] = 0x50;
if (dst_buffer.length > x) {
dst[dst_offset + 3] = (x & 0xff) + 1
dst[dst_offset + 4] = x >> 8
dst[dst_offset + 5] = 0x00
dst_offset += 6 + x
dst.push.apply(dst, src.slice(y * x, (y + 1) * x))
} else {
dst[dst_offset + 3] = (dst_buffer.length & 0xff) + 1
dst[dst_offset + 4] = dst_buffer.length >> 8
dst[dst_offset + 5] = dst_buffer.length
dst_offset += 6 + dst_buffer.length
dst.push.apply(dst, dst_buffer);
}
}
console.log(new Uint8Array(dst))
return new Uint8Array(dst)
}
// RasterDataToCompressCmd(32, 2, [0xfa, 0xfb, 0xfc, 0xfd, 0x00, 0x00, 0x00, 0x00])
function Image1ToRasterCmd(width, height, src) {
var x = parseInt((width + 7) / 8);
var y = parseInt(height);
var dstlen = 8 + x * y;
var dst = new Uint8Array(dstlen);
dst[0] = 0x1d;
dst[1] = 0x76;
dst[2] = 0x30;
dst[3] = 0x00;
dst[4] = (x % 256);
dst[5] = (x / 256);
dst[6] = (y % 256);
dst[7] = (y / 256);
var dst_idx = 8;
var d = 0;
for (var j = 0; j < height; ++j) {
for (var i = 0; i < width; ++i) {
var offset = Image1PixOffset(width, i, j);
if (i % 8 == 0) {
d = ((src[offset] ? 0x01 : 0x00) << (7 - (i % 8)));
} else {
d |= ((src[offset] ? 0x01 : 0x00) << (7 - (i % 8)));
}
if ((i % 8 == 7) || (i == width - 1)) {
dst[dst_idx++] = d;
}
}
/**
* 打印矩形框
* @param {} x0 左上角x坐标
* @param {*} y0 左上角y坐标
* @param {*} x1 右下角X坐标
* @param {*} y1 右下角y坐标
*/
printBox(x0,y0,x1,y1){
return this.str = this.str.concat('BOX ' + x0 + ' ' + y0 + ' '+ x1 + ' ' + y1 + ' 2' + '\r\n');
}
return dst;
}
function Image1ToRasterData(width, height, src) {
var x = parseInt((width + 7) / 8);
var y = parseInt(height);
var dstlen = x * y;
var dst = new Uint8Array(dstlen);
var dst_idx = 0;
var d = 0;
for (var j = 0; j < height; ++j) {
for (var i = 0; i < width; ++i) {
var offset = Image1PixOffset(width, i, j);
if (i % 8 == 0) {
d = ((src[offset] ? 0x01 : 0x00) << (7 - (i % 8)));
} else {
d |= ((src[offset] ? 0x01 : 0x00) << (7 - (i % 8)));
}
if ((i % 8 == 7) || (i == width - 1)) {
dst[dst_idx++] = d;
}
/**
* 获取数据数组
*/
getData(){
this.str = this.str.concat('FORM\r\nPRINT\r\n');
var t = this.str;
var a = [] , n = 0;
for (; n < Math.ceil(t.length / 10); n++) {
a[n] = wx.base64ToArrayBuffer(base.encode64gb2312(t.substr(n * 10, 10)));
}
return a;
}
return dst;
}
function Image1PixOffset(w, x, y) {
return y * w + x;
}
function FeedAndCutPaper() {
//切刀
var data = new Uint8Array([0x1d, 0x56, 0x42, 0x00]);
return data
}
function FullCutPaper() {
var data = new Uint8Array([0x1b, 0x69]);
return data
}
function HalfCutPaper() {
var data = new Uint8Array([0x1b, 0x6d]);
return data
}
function sleep(delay) {
var start = (new Date()).getTime();
while ((new Date()).getTime() - start < delay) {
continue;
}
}
function writeData(cmd, deviceId) {
let mtu = 20
var startDate = new Date()
wx.getBLEDeviceServices({
// 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
deviceId: deviceId,
success(res) {
console.log('device services:', res.services)
wx.getBLEDeviceCharacteristics({
deviceId: deviceId,
serviceId: serviceId1,
success: function (res) {
for (var i = 0; i < cmd.length; i += mtu) {
var endLength = 0
if (i + mtu < cmd.length) {
var senddata = cmd
let buffer = new ArrayBuffer(mtu)
let dataView = new DataView(buffer)
let dataSend = []
for (var j = i; j < i + mtu; j++) {
dataView.setUint8(j - i, senddata[j])
dataSend.push(dataView.getUint8(j - i))
}
console.log('多包发送的包数据:' + dataSend)
wx.writeBLECharacteristicValue({
deviceId: deviceId,
serviceId: serviceId1,
characteristicId: characteristicId1,
value: buffer,
success: function (res) {
},
fail: function (res) {
console.log('发送失败', res)
}
})
sleep(10)
} else {
var senddata = cmd
if (mtu < cmd.length) {
endLength = senddata.length - i
} else {
endLength = senddata.length
}
let buffer = new ArrayBuffer(endLength)
let dataView = new DataView(buffer)
let dataSend = []
for (var j = i; j < senddata.length; j++) {
dataView.setUint8(j - i, senddata[j])
dataSend.push(dataView.getUint8(j - i))
}
wx.writeBLECharacteristicValue({
deviceId: deviceId,
serviceId: serviceId1,
characteristicId: characteristicId1,
value: buffer,
success: function (res) {
},
fail: function (res) {
console.log('发送失败', res)
}
})
var endDate = new Date()
sleep(10)
}
}
},
fail: function (res) {
console.log(res)
}
})
},
fail: function (res) {
console.log(res)
}
})
}
module.exports = {
setBarcode: setBarcode,
setQRcode: setQRcode,
setString: setString,
setImageRGBA: setImageRGBA,
setImageCompressRGBA: setImageCompressRGBA,
writeData: writeData,
print_FeedLine: print_FeedLine,
LABEL_PageBegin: LABEL_PageBegin,
LABEL_PageEnd: LABEL_PageEnd,
LABEL_PagePrint: LABEL_PagePrint,
LABEL_PageFeed: LABEL_PageFeed,
LABEL_PageCalibrate: LABEL_PageCalibrate,
LABEL_DrawLine: LABEL_DrawLine,
LABEL_DrawBox: LABEL_DrawBox,
LABEL_DrawRectangel: LABEL_DrawRectangel,
LABEL_DrawPlainText: LABEL_DrawPlainText,
LABEL_DrawBarcode: LABEL_DrawBarcode,
LABEL_DrawQRCode: LABEL_DrawQRCode,
LABEL_DrawPDF417: LABEL_DrawPDF417,
LABEL_DrawImage1: LABEL_DrawImage1,
LABEL_DrawImageRGBA: LABEL_DrawImageRGBA,
Uint8ArraysToUint8Array: Uint8ArraysToUint8Array,
FeedAndCutPaper: FeedAndCutPaper,
FullCutPaper: FullCutPaper,
HalfCutPaper: HalfCutPaper
}
export default PrintUtil
{
"name": "bluetooth_cpcl",
"version": "1.0.0",
"description": "",
"version": "1.0.1",
"description": "蓝牙打印机下发cpcl模式",
"main": "index.js",

@@ -6,0 +6,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc