当前位置: 首页 > news >正文

WUP-MY-LABEL-PRINTER 旻佑热敏打印机标签打印uniapp插件使用说明

插件地址:WUP-MY-LABEL-PRINTER 旻佑热敏打印机标签打印安卓库

简介

  1. 本插件主要用于旻佑热敏打印机打印标签,不支持票据打印。
  2. 适用于旻佑的各型支持标签打印的热敏打印机。
  3. 本插件开发时使用的打印机型号为MY-805嵌入式面板打印机,其他型号请先试用测试。
  4. 使用本插件需要在Android 5.0以上设备使用。
  5. 插件支持uniapp的vue2 和 vue3 版本;uniapp x没做支持,可自行测试。
  6. 初始化流程:获取设备-打开设备-设置多字节模式及编码。
  7. 打印流程:标签页开始-绘制内容-打印,打印每一页标签都是这个流程。
    在这里插入图片描述
    在这里插入图片描述

方法

方法引入

import { sayHi, 需引入的其他方法 } from "@/uni_modules/WUP-MY-LABEL-PRINTER";

插件测试方法

sayHi("wup-my-label-printer", function (res) {console.log("sayHi", res)
})

枚举本地USB打印设备

enumUsb((res) => {console.log("enumUsb", res)
})

打开USB设备

  • usbDeviceStr:枚举的USB列表的中USB设备名
  • autoReplyMode:自动回传模式 0,不开启;1,开启
openUsb(usbDeviceStr, autoReplyMode, (res) => {console.log("openUsb", res)
})

启用标签模式

labelEnableLabelMode((res) => {console.log("labelEnableLabelMode", res)
})

关闭标签模式

labelDisableLabelMode((res) => {console.log("labelEnableLabelMode", res)
})

全切纸

打印时全切纸推荐使用labelPagePrintAndFullCutPaper,不推荐打印后再单独调用,可能出现切纸位置不准确问题。

fullCutPaper((res) => {console.log("fullCutPaper", res)
})

半切纸

打印时半切纸推荐使用labelPagePrintAndHalfCutPaper,不推荐打印后再单独调用,可能出现切纸位置不准确问题。

halfCutPaper((res) => {console.log("halfCutPaper", res)
})

设置打印机为多字节模式及编码

  • encoding:编码 0,GBK;1,UTF8;3,BIG5;4,ShiftJIS;5,EUCKR
setMultiByteEncoding(encoding, (res) => {that.msg = JSON.stringify(res)console.log("setMultiByteEncoding", res)
})

校准标签纸(更换不同规格标签纸,需要校准)

labelCalibrateLabel((res) => {console.log("labelCalibrateLabel", res)
})

走纸到标签缝隙处

labelFeedLabel((res) => {console.log("labelFeedLabel", res)
})

打印机退纸到打印位置(适用于标签打印开头定位)

labelBackPaperToPrintPosition((res) => {console.log("labelBackPaperToPrintPosition", res)
})

打印机进纸到撕纸位置(适用于标签打印结束定位)

labelFeedPaperToTearPosition((res) => {console.log("labelFeedPaperToTearPosition", res)
})

指示一个标签页面的开始,并设置标签页的大小,参考点坐标和页面旋转角度

  • x:页面起始点X轴坐标
  • y:页面起始点Y轴坐标
  • width:页面宽度
  • height:页面高度
  • rotation:页面旋转 0,页面不旋转;1,页面旋转90° 标签打印不支持旋转属性,默认0就好。
labelPageBegin(x, y, width, height, rotation, (res) => {console.log("labelPageBegin", res)
})

将标签页上的内容打印到标签纸上

  • copies:打印分数[1 - 255]
labelPagePrint(copies, (res) => {console.log("labelPagePrint", res)
})

将标签页上的内容打印到标签纸上,并半切纸

  • copies:打印分数[1 - 255]
labelPagePrintAndHalfCutPaper(copies, (res) => {console.log("labelPagePrintAndHalfCutPaper", res)
})

将标签页上的内容打印到标签纸上,并全切纸

  • copies:打印分数[1 - 255]
labelPagePrintAndFullCutPaper(copies, (res) => {console.log("labelPagePrintAndFullCutPaper", res)
})

获取文本字符风格值(异步)

  • bold:是否加粗 false,否;true,是
  • underline:是否下划线 false,否;true,是
  • highlight:是否反白(黑底白字) false,否;true,是
  • strikethrough:是否删除线 false,否;true,是(MY805测试无效
  • rotation:旋转 0,不旋转;1,90°;2,180°;3,270°
  • widthscale:字体宽度放大倍数
  • heightscale:字体高度放大倍数
getLabelTextStyle(bold, underline, highlight, strikethrough, rotation, widthscale, heightscale, (res) => {console.log("getLabelTextStyle", res)
})

获取文本字符风格值(同步)

  • bold:是否加粗 false,否;true,是
  • underline:是否下划线 false,否;true,是
  • highlight:是否反白(黑底白字) false,否;true,是
  • strikethrough:是否删除线 false,否;true,是(MY805测试无效
  • rotation:旋转 0,不旋转;1,90°;2,180°;3,270°
  • widthscale:字体宽度放大倍数
  • heightscale:字体高度放大倍数
const res = getLabelTextStyleSync(bold, underline, highlight, strikethrough, rotation, widthscale, heightscale)
console.log("getLabelTextStyleSync", res)

在标签页面上指定位置绘制文本(只能单行打印)。

labelDrawText(x, y, font, style, str, (res) => {that.msg = JSON.stringify(res)console.log("labelDrawText", res)
})

在标签页指定位置绘制一维条码

  • x:页面起始点X轴坐标
  • y:页面起始点Y轴坐标
  • nBarcodeType:标识条码类型 0,UPCA;1,UPCE;2,EAN13;3,EAN8;4,CODE39;5,ITF;6,CODEBAR;7,CODE93;8,CODE128;9,CODE11;10,MSI;11,128M;12,EAN128;13,25C;14,39C;15,39;16,EAN13PLUS2;17,EAN13PLUS5;18,EAN8+2;19,EAN8PLUS5;20,POST;21,UPCAPLUS2;22,UPCAPLUS5;23,UPCEPLUS2;24,UPCEPLUS5;25,CPOST;26,MSIC;27,PLESSEY;28,ITF14;29,EAN14;
  • nBarcodeTextPrintPosition:条码可读字符位置 0,不显示可读字符;1,下方显示;2,上方显示;3,上方和下方显示
  • height:条码高度
  • unitwidth:码块单元宽度
  • rotation:旋转 0,不旋转;1,90°;2,180°;3,270°
  • str:要打印的条码
labelDrawBarcode(x, y, nBarcodeType, nBarcodeTextPrintPosition, height, unitwidth,  rotation, str, (res) => {console.log("labelDrawBarcode", res)
})

在标签页指定位置绘制二维码

  • x:页面起始点X轴坐标
  • y:页面起始点Y轴坐标
  • nVersion:字符版本(不知道用处,默认0就好)
  • nECCLevel:ECC纠错等级 1,L:7%,低纠错,数据多;2,M:15%,中纠错;3,Q:优化纠错;4,H:30%,最高纠错,数据少
  • unitwidth:码块单元宽度(MY-805实测最大可为8,超过8会出现打印无反应,可以根据实际调整)
  • rotation:旋转 0,不旋转;1,90°;2,180°;3,270°
  • str:要打印的二维码
labelDrawQRCode(x, y, nVersion, nECCLevel, unitwidth,  rotation, str, (res) => {console.log("labelDrawQRCode", res)
})

在标签页指定位置绘制 PDF417 条码

  • x:页面起始点X轴坐标
  • y:页面起始点Y轴坐标
  • column:列数,表述每行容纳多少码字。一个码字为 17*UnitWidth 个点。行数由打印机自动产生,行数范围限定为 3~90。ColNum 的取值范围:[1,30]。
  • nAspectRatio:条码模块的高宽比
  • nECCLevel:ECC纠错等级,取值范围[0, 8]
    纠错等级取值纠错码数可存资料量(字节)
    021108
    141106
    281101
    3161092
    4321072
    5641024
    6128957
    7256804
    8512496
  • unitwidth:码块单元宽度,取值范围[1, 3]
  • rotation:旋转 0,不旋转;1,90°;2,180°;3,270°
  • str:要打印的PDF417条码
labelDrawPDF417Code(x, y, column, nAspectRatio, nECCLevel, unitwidth,  rotation, str, (res) => {console.log("labelDrawPDF417Code", res)
})

在标签页指定位置绘制位图

  • x:页面起始点X轴坐标
  • y:页面起始点Y轴坐标
  • dstw:要打印的宽度
  • dsth:要打印的高度
  • pszFile:图片路径,插件assets目录下路径,不需含assets
  • binaryzation_method:图片二值化算法 0,表示抖动算法;1,表示阀值算法;2,表示误差扩散法。具体效果请测试查看。
  • compression_method:最终打印数据的压缩方式 0,不压缩;1,一级压缩;2,二级压缩
labelDrawImageFromFile(x, y, dstw, dsth, pszFile, binaryzation_method, compression_method, (res) => {console.log("labelDrawImageFromFile", res)
})

在标签页指定位置绘制线段

  • startx:直线段起始点 x 坐标值,取值范围:[0, Page_Width-1]。
  • starty:直线段起始点 y 坐标值,取值范围:[0,Page_Height-1]。
  • endx:直线段终止点 x 坐标值,取值范围:[0, Page_Width-1]。
  • endy:直线段终止点 y 坐标值,取值范围:[0,Page_Height-1]。
  • linewidth:直线段线宽,取值范围:[1,Page_Height-1]。
  • linecolor:直线段颜色线条颜色,0,白色;1,是黑色
labelDrawLine(startx, starty, endx, endy, linewidth, linecolor, (res) => {console.log("labelDrawLine", res)
})

在标签页指定位置绘制矩形

  • x:页面起始点X轴坐标
  • y:页面起始点Y轴坐标
  • width:矩形宽度
  • height:矩形高度
  • color:矩形颜色 0,白色;1,是黑色
labelDrawRect(x, y, width, height, color, (res) => {console.log("labelDrawRect", res)
})

在标签页指定位置绘制矩形框

  • x:页面起始点X轴坐标
  • y:页面起始点Y轴坐标
  • width:矩形宽度
  • height:矩形高度
  • borderwidth:矩形框边框宽度
  • bordercolor:矩形框边框颜色 0,白色;1,是黑色
labelDrawBox(x, y, width, height, borderwidth, bordercolor, (res) => {console.log("labelDrawBox", res)
})

获取开发包版本字符串

getLibraryVersion((res) => {console.log("getLibraryVersion", res)
})

示例代码

<template><view><view style="margin-top: 50px;padding: 0 15px;"><button @click="enumUsb" type="primary" style="margin-bottom: 15px;">usb设备列表</button><button @click="openUsb" type="primary" style="margin-bottom: 15px;">打开usb设备</button><button @click="halfCutPaper" type="primary" style="margin-bottom: 15px;">半切纸</button><button @click="fullCutPaper" type="primary" style="margin-bottom: 15px;">全切纸</button><button @click="getLibraryVersion" type="primary" style="margin-bottom: 15px;">获取开发包版本字符串</button><button @click="labelEnableLabelMode" type="primary" style="margin-bottom: 15px;">开启标签打印</button><button @click="labelDisableLabelMode" type="primary" style="margin-bottom: 15px;">关闭标签打印</button><button @click="labelCalibrateLabel" type="primary" style="margin-bottom: 15px;">校准标签纸</button><button @click="labelFeedLabel" type="primary" style="margin-bottom: 15px;">走纸到标签缝隙处</button><button @click="labelBackPaperToPrintPosition" type="primary" style="margin-bottom: 15px;">退纸到打印位置</button><button @click="labelFeedPaperToTearPosition" type="primary" style="margin-bottom: 15px;">进纸到撕纸位置</button><view style="margin: 50px 0 15px 0;font-size: 2rem;font-weight: bold;">打印</view><button @click="labelPageBegin" type="primary" style="margin-bottom: 15px;">标签页开始</button><!-- <button @click="getLabelTextStyle" type="primary" style="margin-bottom: 15px;">获取文本样式</button> --><button @click="labelDrawText" type="primary" style="margin-bottom: 15px;">绘制文本</button><button @click="labelDrawBarcode" type="primary" style="margin-bottom: 15px;">绘制条形码</button><button @click="labelDrawQRCode" type="primary" style="margin-bottom: 15px;">绘制二维码</button><button @click="labelDrawPDF417Code" type="primary" style="margin-bottom: 15px;">绘制PDF417</button><button @click="labelDrawImageFromFile" type="primary" style="margin-bottom: 15px;">绘制本地图片</button><button @click="labelDrawLine" type="primary" style="margin-bottom: 15px;">绘制线段</button><button @click="labelDrawRect" type="primary" style="margin-bottom: 15px;">绘制矩形</button><button @click="labelDrawBox" type="primary" style="margin-bottom: 15px;">绘制矩形框</button><button @click="labelPagePrint" type="primary" style="margin-bottom: 15px;">打印</button><button @click="labelPagePrintAndHalfCutPaper" type="primary" style="margin-bottom: 15px;">半切打印</button><button @click="labelPagePrintAndFullCutPaper" type="primary" style="margin-bottom: 15px;">全切打印</button><button @click="print" type="primary" style="margin-bottom: 15px;">完整打印示例</button></view><view style="padding: 15px 30px;">{{msg}}</view></view>
</template><script>import { fullCutPaper, halfCutPaper, openUsb, sayHi, setMultiByteEncoding, enumUsb, getLibraryVersion, labelEnableLabelMode, labelDisableLabelMode, labelCalibrateLabel, labelFeedLabel, labelBackPaperToPrintPosition, labelFeedPaperToTearPosition, labelPageBegin, labelDrawText, labelPagePrint, getLabelTextStyle, getLabelTextStyleSync, labelDrawBarcode, labelDrawQRCode, labelDrawPDF417Code, labelDrawImageFromFile, labelDrawLine, labelDrawRect, labelDrawBox, labelPagePrintAndFullCutPaper, labelPagePrintAndHalfCutPaper } from "@/uni_modules/WUP-MY-LABEL-PRINTER";export default {data() {return {msg: "",deviceInx: 0,}},onLoad() {let that = thissayHi("wup-my-label-printer", function (res) {console.log("sayHi", res)})},methods: {print () {let that = thislabelPageBegin(0, 0, 530, 390, 0, (res) => {that.msg = JSON.stringify(res)console.log("labelPageBegin", res)})labelDrawText(10, 10, 24, getLabelTextStyleSync(true, false, false, true, 0, 1, 1), "Hello World!", (res) => {that.msg = JSON.stringify(res)console.log("labelDrawText", res)})labelDrawQRCode(10, 40, 0, 1, 4, 0, "https://blog.csdn.net/Douz_lungfish", (res) => {that.msg = JSON.stringify(res)console.log("labelDrawQRCode", res)})labelDrawImageFromFile(200, 30, 125, 125, "logo.png", 0, 0, (res) => {that.msg = JSON.stringify(res)console.log("labelDrawImageFromFile", res)})labelDrawLine(10, 180, 300, 180, 5, 1, (res) => {that.msg = JSON.stringify(res)console.log("labelDrawLine", res)})labelDrawBox(0, 10, 530, 380, 2, 1, (res) => {that.msg = JSON.stringify(res)console.log("labelDrawBox", res)})labelPagePrintAndFullCutPaper(1, (res) => {that.msg = JSON.stringify(res)console.log("labelPagePrintAndFullCutPaper", res)})},getLabelTextStyle () {let that = this// bold, underline, highlight, strikethrough, rotation, widthscale, heightscalegetLabelTextStyle(true, true, false, false, 1, 1, 1, (res) => {that.msg = JSON.stringify(res)console.log("getLabelTextStyle", res)})const res1 = getLabelTextStyleSync(true, true, false, false, 1, 1, 1)console.log("getLabelTextStyleSync", res1)},labelPagePrint () {let that = thislabelPagePrint(1, (res) => {that.msg = JSON.stringify(res)console.log("labelPagePrint", res)})},labelPagePrintAndHalfCutPaper () {let that = thislabelPagePrintAndHalfCutPaper(1, (res) => {that.msg = JSON.stringify(res)console.log("labelPagePrintAndHalfCutPaper", res)})},labelPagePrintAndFullCutPaper () {let that = thislabelPagePrintAndFullCutPaper(1, (res) => {that.msg = JSON.stringify(res)console.log("labelPagePrintAndFullCutPaper", res)})},labelDrawText () {let that = thislabelDrawText(10, 10, 24, getLabelTextStyleSync(true, false, false, true, 0, 1, 1), "Hello World!", (res) => {that.msg = JSON.stringify(res)console.log("labelDrawText", res)})},labelDrawBarcode () {let that = thislabelDrawBarcode(10, 70, 0, 1, 60, 2, 0, "02031344565", (res) => {that.msg = JSON.stringify(res)console.log("labelDrawBarcode", res)})},labelDrawQRCode () {let that = this// x, y, nVersion, nECCLevel, unitwidth,  rotation, strlabelDrawQRCode(10, 10, 0, 1, 8, 0, "https://blog.csdn.net/Douz_lungfish", (res) => {that.msg = JSON.stringify(res)console.log("labelDrawQRCode", res)})},labelDrawPDF417Code () {let that = this// x, y, column, nAspectRatio, nECCLevel, unitwidth,  rotation, strlabelDrawPDF417Code(10, 10, 5, 5, 0, 3, 0, "Hello World!", (res) => {that.msg = JSON.stringify(res)console.log("labelDrawPDF417Code", res)})},labelDrawImageFromFile () {let that = this// x, y, dstw, dsth, pszFile,  binaryzation_method, compression_methodlabelDrawImageFromFile(10, 30, 200, 200, "la/logo.png", 0, 0, (res) => {that.msg = JSON.stringify(res)console.log("labelDrawImageFromFile", res)})},labelDrawLine () {let that = this// startx, starty, endx, endy, linewidth, linecolorlabelDrawLine(10, 10, 100, 20, 30, 1, (res) => {that.msg = JSON.stringify(res)console.log("labelDrawLine", res)})},labelDrawRect () {let that = this// x, y, width, height, colorlabelDrawRect(10, 10, 100, 80, 1, (res) => {that.msg = JSON.stringify(res)console.log("labelDrawRect", res)})},labelDrawBox () {let that = this// x, y, width, height, borderwidth, bordercolorlabelDrawBox(10, 10, 100, 80, 2, 1, (res) => {that.msg = JSON.stringify(res)console.log("labelDrawBox", res)})},labelPageBegin () {let that = thislabelPageBegin(0, 0, 576, 240, 0, (res) => {that.msg = JSON.stringify(res)console.log("labelPageBegin", res)})},labelFeedPaperToTearPosition () {let that = thislabelFeedPaperToTearPosition((res) => {that.msg = JSON.stringify(res)console.log("labelFeedPaperToTearPosition", res)})},labelBackPaperToPrintPosition () {let that = thislabelBackPaperToPrintPosition((res) => {that.msg = JSON.stringify(res)console.log("labelBackPaperToPrintPosition", res)})},labelFeedLabel () {let that = thislabelFeedLabel((res) => {that.msg = JSON.stringify(res)console.log("labelFeedLabel", res)})},labelCalibrateLabel () {let that = thislabelCalibrateLabel((res) => {that.msg = JSON.stringify(res)console.log("labelCalibrateLabel", res)})},labelDisableLabelMode () {let that = thislabelDisableLabelMode((res) => {that.msg = JSON.stringify(res)console.log("labelEnableLabelMode", res)})},labelEnableLabelMode () {let that = thislabelEnableLabelMode((res) => {that.msg = JSON.stringify(res)console.log("labelEnableLabelMode", res)})},getLibraryVersion () {let that = thisgetLibraryVersion((res) => {that.msg = JSON.stringify(res)console.log("getLibraryVersion", res)})},enumUsb () {let that = thisenumUsb((res) => {that.msg = JSON.stringify(res)console.log("enumUsb", res)})},openUsb () {let that = thisopenUsb('KCEC_USB in FS Mode/0E08F5C2050601006415000055080172', 1, (res) => {that.msg = JSON.stringify(res)if (res.code === 0) {setMultiByteEncoding(1, (res) => {that.msg = JSON.stringify(res)console.log("setMultiByteEncoding", res)})}console.log("openUsb", res)})},halfCutPaper () {let that = thishalfCutPaper((res) => {that.msg = JSON.stringify(res)console.log("halfCutPaper", res)})},fullCutPaper () {let that = thisfullCutPaper((res) => {that.msg = JSON.stringify(res)console.log("fullCutPaper", res)})},}}
</script>

在这里插入图片描述

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 革新测试管理:集远程、协同、自动化于一身的统一测试管理平台
  • Depth Anything: Unleashing the Power of Large-Scale Unlabeled Data精读
  • Prometheus+Grafana保姆笔记(2)——监控Spring Boot微服务程序
  • 基于VS2022+Qt5+C++的串口助手开发
  • MySQL:复杂查询(二)——联合查询02
  • C语言之指针高级--指针操作二维整型、字符型数组、函数指针
  • vscode远程开发
  • C++:std::memory_order_relaxed(宽松内存序)
  • [Vue3] 9 其它API
  • Elasticsearch 搜索高亮功能及示例
  • 谷粒商城实战笔记-179~183-商城业务-检索服务-SearchRequest和SearchResponse构建
  • js中的promise、async/await 用法,详解async、await 语法糖,js中的宏任务和微任务(保姆级教程二)
  • vscode的C/C++环境配置和调试技巧
  • 基于Transformer机制的AI现阶段可能已达峰值
  • xss复现
  • IE9 : DOM Exception: INVALID_CHARACTER_ERR (5)
  • .pyc 想到的一些问题
  • 2017前端实习生面试总结
  • C++类中的特殊成员函数
  • co模块的前端实现
  • iOS 系统授权开发
  • Java 实战开发之spring、logback配置及chrome开发神器(六)
  • Making An Indicator With Pure CSS
  • Sequelize 中文文档 v4 - Getting started - 入门
  • vue-cli在webpack的配置文件探究
  • 大型网站性能监测、分析与优化常见问题QA
  • 力扣(LeetCode)357
  • 说说动画卡顿的解决方案
  • 在Docker Swarm上部署Apache Storm:第1部分
  • 如何正确理解,内页权重高于首页?
  • 曾刷新两项世界纪录,腾讯优图人脸检测算法 DSFD 正式开源 ...
  • ​zookeeper集群配置与启动
  • ###51单片机学习(1)-----单片机烧录软件的使用,以及如何建立一个工程项目
  • #基础#使用Jupyter进行Notebook的转换 .ipynb文件导出为.md文件
  • #我与Java虚拟机的故事#连载10: 如何在阿里、腾讯、百度、及字节跳动等公司面试中脱颖而出...
  • (4) PIVOT 和 UPIVOT 的使用
  • (Mac上)使用Python进行matplotlib 画图时,中文显示不出来
  • (备份) esp32 GPIO
  • (附源码)spring boot北京冬奥会志愿者报名系统 毕业设计 150947
  • (接口自动化)Python3操作MySQL数据库
  • (经验分享)作为一名普通本科计算机专业学生,我大学四年到底走了多少弯路
  • (免费领源码)Python#MySQL图书馆管理系统071718-计算机毕业设计项目选题推荐
  • (转)全文检索技术学习(三)——Lucene支持中文分词
  • *p++,*(p++),*++p,(*p)++区别?
  • .net core使用RPC方式进行高效的HTTP服务访问
  • .NET Standard 支持的 .NET Framework 和 .NET Core
  • .NET 表达式计算:Expression Evaluator
  • .net后端程序发布到nignx上,通过nginx访问
  • .NET中的十进制浮点类型,徐汇区网站设计
  • .net专家(张羿专栏)
  • [ C++ ] STL---string类的模拟实现
  • [ IO.File ] FileSystemWatcher
  • [ vulhub漏洞复现篇 ] Apache APISIX 默认密钥漏洞 CVE-2020-13945
  • []我的函数库
  • [8481302]博弈论 斯坦福game theory stanford week 1