插件地址:WUP-MY-POS-PRINTER 旻佑热敏打印机票据打印安卓库
简介
- 本插件主要用于旻佑热敏打印机打印票据,不支持标签打印。
- 适用于旻佑的各型支持票据打印的热敏打印机。
- 本插件开发时使用的打印机型号为MY-805嵌入式面板打印机,其他型号请先试用测试。
- 使用本插件需要在Android 5.0以上设备使用。
- 插件支持uniapp的vue2 和 vue3 版本;uniapp x没做支持,可自行测试。
- 初始化流程:获取设备-打开设备-设置多字节模式及编码。
方法
方法引入
import { sayHi, 需引入的其他方法 } from "@/uni_modules/WUP-MY-POS-PRINTER";
插件测试方法
sayHi("wup-my-pos-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)
})
全切纸
打印时推荐使用posFeedAndHalfCutPaper,不推荐打印后再单独调用,可能出现切纸位置不准确问题。
fullCutPaper((res) => {
console.log("fullCutPaper", res)
})
半切纸
打印时推荐使用posFeedAndHalfCutPaper,不推荐打印后再单独调用,可能出现切纸位置不准确问题。
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)
})
获取开发包版本字符串
getLibraryVersion((res) => {
console.log("getLibraryVersion", res)
})
查询打印机实时状态
- timeout:查询等待超时时间(毫秒)
posQueryRTStatus(timeout, function (res) {
console.log("posQueryRTStatus", res)
})
蜂鸣器鸣叫
- nBeepCount:鸣叫次数
- nBeepMs:蜂鸣毫秒时间,取值范围[100,900]。取整到百毫秒。
posBeep(nBeepCount, nBeepMs, function (res) {
that.msg = JSON.stringify(res)
console.log("posQueryRTStatus", res)
})
走纸到切刀位置并半切纸
posFeedAndHalfCutPaper(function (res) {
console.log("posFeedAndHalfCutPaper", res)
})
打印机进纸指定行数
- numLines:要进的行数
posFeedLine(numLines, function (res) {
console.log("posFeedLine", res)
})
打印机进纸指定点数
- numDots:要进的点数
posFeedDot(numDots, function (res) {
console.log("posFeedDot", res)
})
打印机打印自检页
posPrintSelfTestPage(function (res) {
console.log("posPrintSelfTestPage", res)
})
打印文本
- str:要打印的字符串
posPrintText(str, function (res) {
console.log("posPrintText", res)
})
打印一维条码
- nBarcodeType:标识条码类型 65,UPCA;66,UPCE;67,EAN13;68,EAN8;69,CODE39;70,ITF;71,CODEBAR;72,CODE93;73,CODE128;
- str:一维条码内容
posPrintBarcode(nBarcodeType, str, function (res) {
console.log("posPrintBarcode", res)
})
打印 CODE128 条码(该函数自动切换编码,以便节省空间)
- str:一维条码内容
posPrintBarcodeCode128Auto(str, function (res) {
console.log("posPrintBarcodeCode128Auto", res)
})
打印二维码
- nVersion:(不知道用途默认0就好)指定字符版本。取值范围:[0,16],当 version 为 0 时,打印机根据字符串长度自动计算版本号。
- nECCLevel:ECC纠错等级 1,L:7%,低纠错,数据多;2,M:15%,中纠错;3,Q:优化纠错;4,H:30%,最高纠错,数据少。
- str:要打印的二维码
posPrintQRCode(nVersion, nECCLevel, str, function (res) {
console.log("posPrintQRCode", res)
})
打印二维码(Epson指令)
- nQRCodeUnitWidth:QRCode 码码块宽度,取值范围:[1, 16]
- nECCLevel:ECC纠错等级 1,L:7%,低纠错,数据多;2,M:15%,中纠错;3,Q:优化纠错;4,H:30%,最高纠错,数据少。
- str:要打印的二维码
posPrintQRCode(nVersion, nECCLevel, str, function (res) {
console.log("posPrintQRCode", res)
})
打印二位码(Image指令)
- nVersion:(不知道用途默认0就好)指定字符版本。取值范围:[0,16],当 version 为 0 时,打印机根据字符串长度自动计算版本号。
- nQRCodeUnitWidth:QRCode 码码块宽度,取值范围:[1, 16]
- nECCLevel:ECC纠错等级 1,L:7%,低纠错,数据多;2,M:15%,中纠错;3,Q:优化纠错;4,H:30%,最高纠错,数据少。
- compression_method:最终打印数据的压缩方式 0,不压缩;1,一级压缩;2,二级压缩。
- str:要打印的二维码
posPrintQRCodeUseImageCmd(nVersion, nQRCodeUnitWidth, nECCLevel, compression_method, str, function (res) {
console.log("posPrintQRCodeUseImageCmd", res)
})
打印 PDF417 条码
- columnCount:列数,取值范围[0,30]
- rowCount:行数,取值范围 0,[3,90]
- unitWidth:模块单元宽度,取值范围[2,8]
- rowHeight:行高,取值范围[2,8]
- nECCLevel:指定纠错等级。取值范围:[0,8]
- dataProcessingMode:数据处理模式。0,选择标准 PDF417;1,选择截断 PDF417
- str:要打印的 PDF417 码
posPrintPDF417BarcodeUseEpsonCmd(columnCount, rowCount, unitWidth, rowHeight, nECCLevel, dataProcessingMode, str, function (res) {
console.log("posPrintPDF417BarcodeUseEpsonCmd", res)
})
- dstw:要打印的宽度
- dsth:要打印的高度
- binaryzation_method:图片二值化算法。0 表示抖动算法,1 表示阀值算法,2 表示误差扩散法。具体效果请测试查看。
- compression_method:最终打印数据的压缩方式,各值定义如下 0,不压缩;1,一级压缩;2,二级压缩
- pszFile:图片的路径,插件assets目录下路径,不需含assets
posPrintRasterImageFromFile(dstw, dsth, binaryzation_method, compression_method, pszFile, function (res) {
console.log("posPrintRasterImageFromFile", res)
})
打印一条水平线
- nLineStartPosition:线段起点位置
- nLineEndPosition:线段终点位置
posPrintHorizontalLine(nLineStartPosition, nLineEndPosition, function (res) {
console.log("posPrintHorizontalLine", res)
})
打印一条水平线(可设置粗细)
- nLineStartPosition:线段起点位置
- nLineEndPosition:线段终点位置
- nLineThickness:线段粗细
posPrintHorizontalLineSpecifyThickness(nLineStartPosition, nLineEndPosition, nLineThickness, function (res) {
console.log("posPrintHorizontalLineSpecifyThickness", res)
})
打印机复位
posResetPrinter(function (res) {
console.log("posResetPrinter", res)
})
设置打印速度(部分机型支持)
- nSpeed:打印速度,单位毫米每秒
posSetPrintSpeed(nSpeed, function (res) {
console.log("posSetPrintSpeed", res)
})
设置打印浓度(部分机型支持)
- nDensity:设置打印浓度[0,15]
posSetPrintDensity(nDensity, function (res) {
console.log("posSetPrintDensity", res)
})
- 设置打印机为单字节编码(正常情况下不推荐使用)
posSetSingleByteMode(function (res) {
console.log("posSetSingleByteMode", res)
})
设置打印机字符集
- nCharacterSet:打印机字符集,范围[0,15]
posSetCharacterSet(nCharacterSet, function (res) {
console.log("posSetCharacterSet", res)
})
设置字符代码页
- nCharacterCodepage:字符代码页,范围[0,255]
posSetCharacterCodepage(nCharacterCodepage, function (res) {
console.log("posSetCharacterCodepage", res)
})
设置打印移动单位
- nHorizontalMovementUnit:水平移动单位
- nVerticalMovementUnit:垂直移动单位
- 移动单位设置为 200,则 1mm=8 点。
posSetMovementUnit(nHorizontalMovementUnit, nVerticalMovementUnit, function (res) {
console.log("posSetMovementUnit", res)
})
设置打印区域左边空白
- nLeftMargin:左边空白
posSetPrintAreaLeftMargin(nLeftMargin, function (res) {
console.log("posSetPrintAreaLeftMargin", res)
})
设置打印区域宽度
- nWidth:打印区域宽度
posSetPrintAreaWidth(nWidth, function (res) {
console.log("posSetPrintAreaWidth", res)
})
设置横向绝对打印位置
- nPosition:打印位置
posSetHorizontalAbsolutePrintPosition(nPosition, function (res) {
console.log("posSetHorizontalAbsolutePrintPosition", res)
})
设置横向相对打印位置
- nPosition:打印位置
posSetHorizontalRelativePrintPosition(nPosition, function (res) {
console.log("posSetHorizontalRelativePrintPosition", res)
})
设置打印对齐方式
- nAlignment:打印对齐方式 0,左对齐;1,中对齐;2,右对齐
posSetAlignment(nAlignment, function (res) {
console.log("posSetAlignment", res)
})
设置文本放大倍数
- nWidthScale:宽度放大倍数
- nHeightScale:高度放大倍数
posSetTextScale(nWidthScale, nHeightScale, function (res) {
console.log("posSetTextScale", res)
})
设置英文字符字体类型
- nFontType:英文字符字体类型 0,字型 A(12x24);1,字型 B(9x17)
posSetAsciiTextFontType(1, function (res) {
console.log("posSetAsciiTextFontType", res)
})
设置文本加粗打印
- nBold:0,不加粗;1,加粗
posSetTextBold(nBold, function (res) {
console.log("posSetTextBold", res)
})
设置文本下划线
- nUnderline:文本下划线 0,无下划线;1,1点下划线;2,2点下划线;
posSetTextUnderline(nUnderline, function (res) {
console.log("posSetTextUnderline", res)
})
设置文本倒置打印
- nUpsideDown:0,不倒置;1,倒置
posSetTextUpsideDown(nUpsideDown, function (res) {
console.log("posSetTextUpsideDown", res)
})
设置黑白反显
- nWhiteOnBlack:黑白反显 0,不黑白反显;1,黑白反显
posSetTextWhiteOnBlack(nWhiteOnBlack, function (res) {
console.log("posSetTextWhiteOnBlack", res)
})
设置文本旋转 90 度打印
- nRotate:设旋转打印 0,不旋转打印;1,旋转90°打印
posSetTextRotate(nRotate, function (res) {
console.log("posSetTextRotate", res)
})
设置行高
- nLineHeight:行高,范围[1,255]
posSetTextLineHeight(nLineHeight, function (res) {
console.log("posSetTextLineHeight", res)
})
设置 ASCII 字符右边空白
- nSpacing:右边空白,范围[1,255]
posSetAsciiTextCharRightSpacing(nSpacing, function (res) {
console.log("posSetAsciiTextCharRightSpacing", res)
})
设置汉字文本字符左边空白和右边空白
- nLeftSpacing:左边空白,范围[1,255]
- nRightSpacing:右边空白,范围[1,255]
posSetKanjiTextCharSpacing(nLeftSpacing, nRightSpacing, function (res) {
console.log("posSetKanjiTextCharSpacing", res)
})
设置条码和二维码单元宽度
- nBarcodeUnitWidth:条码单元宽度,取值范围:[1,6]
posSetBarcodeUnitWidth(nBarcodeUnitWidth, function (res) {
console.log("posSetBarcodeUnitWidth", res)
})
设置条码高度
- nBarcodeHeight:定义条码高度。取值范围:[1,255]
posSetBarcodeHeight(nBarcodeHeight, function (res) {
console.log("posSetBarcodeHeight", res)
})
设置条码可读字符打印位置
- nTextPosition:条码可读字符位置 0,不显示可读字符;1,在条码下方显示可读字符;2,在条码上方显示可读字符;3,在条码上方和条码下方显示可读字符;
posSetBarcodeReadableTextPosition(nTextPosition, function (res) {
that.msg = JSON.stringify(res)
console.log("posSetBarcodeReadableTextPosition", res)
})
设置条码可读字符字体类型
- nFontType:指定可读字符的字体类型 0,标准 ASCII;1,压缩 ASCII
posSetBarcodeReadableTextFontType(nFontType, function (res) {
console.log("posSetBarcodeReadableTextFontType", 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="posQueryRTStatus" type="primary" style="margin-bottom: 15px;">查询打印机实时状态</button>
<button @click="posBeep" type="primary" style="margin-bottom: 15px;">蜂蜜器鸣叫</button>
<button @click="posResetPrinter" type="primary" style="margin-bottom: 15px;">打印机复位</button>
<view style="margin: 50px 0 15px 0;font-size: 2rem;font-weight: bold;">打印</view>
<button @click="print" type="primary" style="margin-bottom: 15px;">打印测试</button>
<button @click="posFeedAndHalfCutPaper" type="primary" style="margin-bottom: 15px;">走纸到切刀位置并半切纸</button>
<button @click="posFeedLine" type="primary" style="margin-bottom: 15px;">打印机进纸指定行数</button>
<button @click="posFeedDot" type="primary" style="margin-bottom: 15px;">打印机进纸指定点数</button>
<button @click="posPrintSelfTestPage" type="primary" style="margin-bottom: 15px;">打印机打印自检页</button>
<button @click="posPrintText" type="primary" style="margin-bottom: 15px;">打印文本</button>
<button @click="posPrintText1" type="primary" style="margin-bottom: 15px;">打印文本1</button>
<button @click="posPrintBarcode" type="primary" style="margin-bottom: 15px;">打印一维条形码</button>
<button @click="posPrintBarcodeCode128Auto" type="primary" style="margin-bottom: 15px;">打印一维条形码Code128Auto</button>
<button @click="posPrintQRCode" type="primary" style="margin-bottom: 15px;">打印二维码</button>
<button @click="posPrintQRCodeUseEpsonCmd" type="primary" style="margin-bottom: 15px;">打印二维码(Epson指令)</button>
<button @click="posPrintQRCodeUseImageCmd" type="primary" style="margin-bottom: 15px;">打印二维码(Image指令)</button>
<button @click="posPrintPDF417BarcodeUseEpsonCmd" type="primary" style="margin-bottom: 15px;">打印 PDF417 条码</button>
<button @click="posPrintRasterImageFromFile" type="primary" style="margin-bottom: 15px;">打印图片</button>
<button @click="posPrintHorizontalLine" type="primary" style="margin-bottom: 15px;">打印水平线</button>
<button @click="posPrintHorizontalLineSpecifyThickness" type="primary" style="margin-bottom: 15px;">打印水平线(粗细)</button>
</view>
<view style="padding: 15px 30px;">
{{msg}}
</view>
</view>
</template>
<script>
import { posBeep, posQueryRTStatus, fullCutPaper, halfCutPaper, openUsb, sayHi, setMultiByteEncoding, enumUsb, getLibraryVersion, posFeedAndHalfCutPaper, posFeedLine, posFeedDot, posPrintSelfTestPage, posPrintText, posPrintBarcode, posPrintBarcodeCode128Auto, posPrintQRCode, posPrintQRCodeUseEpsonCmd, posPrintQRCodeUseImageCmd, posPrintPDF417BarcodeUseEpsonCmd, posPrintRasterImageFromFile, posPrintHorizontalLine, posPrintHorizontalLineSpecifyThickness, posResetPrinter, posSetPrintSpeed, posSetPrintDensity, posSetSingleByteMode, posSetCharacterSet, posSetCharacterCodepage, posSetMovementUnit, posSetPrintAreaLeftMargin, posSetPrintAreaWidth, posSetHorizontalAbsolutePrintPosition, posSetHorizontalRelativePrintPosition, posSetAlignment, posSetTextScale, posSetAsciiTextFontType, posSetTextBold, posSetTextUnderline, posSetTextUpsideDown, posSetTextWhiteOnBlack, posSetTextRotate, posSetTextLineHeight, posSetAsciiTextCharRightSpacing, posSetKanjiTextCharSpacing, posSetBarcodeUnitWidth, posSetBarcodeHeight, posSetBarcodeReadableTextFontType, posSetBarcodeReadableTextPosition } from "@/uni_modules/WUP-MY-POS-PRINTER";
export default {
data() {
return {
msg: "",
deviceInx: 0,
}
},
onLoad() {
let that = this
sayHi("wup-my-pos-printer", function (res) {
console.log("sayHi", res)
})
},
methods: {
print () {
let that = this
posPrintText("欢迎使用\r\n", function (res) {
console.log("posPrintText", res)
})
posPrintText("WUP-MY-POS-PRINTER(¥99.8)\r\n", function (res) {
console.log("posPrintText", res)
})
posFeedLine(2, function (res) {
console.log("posFeedLine", res)
})
posPrintText("静夜思\r\n", function (res) {
console.log("posPrintText", res)
})
posPrintText("床前明月光\r\n", function (res) {
console.log("posPrintText", res)
})
posPrintText("疑是地上霜\r\n", function (res) {
console.log("posPrintText", res)
})
posPrintText("举头望明月\r\n", function (res) {
console.log("posPrintText", res)
})
posPrintText("低头思故乡\r\n", function (res) {
console.log("posPrintText", res)
})
posPrintQRCode(0, 1, 'https://blog.csdn.net/Douz_lungfish', function (res) {
console.log("posPrintQRCode", res)
})
posFeedLine(1, function (res) {
console.log("posFeedLine", res)
})
posSetBarcodeReadableTextPosition(1, function (res) {
console.log("posSetBarcodeReadableTextPosition", res)
})
posSetBarcodeReadableTextFontType(1, function (res) {
console.log("posSetBarcodeReadableTextFontType", res)
})
posPrintBarcode(65, "202012260123", function (res) {
console.log("posPrintBarcode", res)
})
posFeedLine(1, function (res) {
console.log("posFeedLine", res)
})
posPrintPDF417BarcodeUseEpsonCmd(0, 0, 3, 3, 0, 3, 'hello world', function (res) {
console.log("posPrintPDF417BarcodeUseEpsonCmd", res)
})
posFeedLine(1, function (res) {
console.log("posFeedLine", res)
})
posPrintRasterImageFromFile(100, 100, 0, 0, 'logo.png', function (res) {
console.log("posPrintRasterImageFromFile", res)
})
posFeedAndHalfCutPaper(function (res) {
console.log("posFeedAndHalfCutPaper", res)
})
},
posResetPrinter () {
let that = this
posResetPrinter(function (res) {
that.msg = JSON.stringify(res)
console.log("posResetPrinter", res)
})
},
posPrintHorizontalLineSpecifyThickness () {
let that = this
posPrintHorizontalLineSpecifyThickness(50, 200, 3, function (res) {
that.msg = JSON.stringify(res)
console.log("posPrintHorizontalLineSpecifyThickness", res)
})
},
posPrintHorizontalLine () {
let that = this
posPrintHorizontalLine(50, 200, function (res) {
that.msg = JSON.stringify(res)
console.log("posPrintHorizontalLine", res)
})
},
posPrintRasterImageFromFile () {
let that = this
posPrintRasterImageFromFile(100, 100, 0, 0, 'logo.png', function (res) {
that.msg = JSON.stringify(res)
console.log("posPrintRasterImageFromFile", res)
})
},
posPrintPDF417BarcodeUseEpsonCmd () {
let that = this
posPrintPDF417BarcodeUseEpsonCmd(0, 0, 3, 3, 0, 3, 'hello world', function (res) {
that.msg = JSON.stringify(res)
console.log("posPrintPDF417BarcodeUseEpsonCmd", res)
})
},
posPrintQRCodeUseImageCmd () {
let that = this
posPrintQRCodeUseImageCmd(0, 8, 1, 0, 'https://blog.csdn.net/Douz_lungfish', function (res) {
that.msg = JSON.stringify(res)
console.log("posPrintQRCodeUseImageCmd", res)
})
},
posPrintQRCodeUseEpsonCmd () {
let that = this
posPrintQRCodeUseEpsonCmd(5, 1, 'https://blog.csdn.net/Douz_lungfish', function (res) {
that.msg = JSON.stringify(res)
console.log("posPrintQRCodeUseEpsonCmd", res)
})
},
posPrintQRCode () {
let that = this
posPrintQRCode(0, 1, 'https://blog.csdn.net/Douz_lungfish', function (res) {
that.msg = JSON.stringify(res)
console.log("posPrintQRCode", res)
})
},
posPrintBarcodeCode128Auto () {
let that = this
posPrintBarcodeCode128Auto("202012260123", function (res) {
that.msg = JSON.stringify(res)
console.log("posPrintBarcodeCode128Auto", res)
})
},
posPrintBarcode () {
let that = this
posPrintBarcode(65, "202012260123", function (res) {
that.msg = JSON.stringify(res)
console.log("posPrintBarcode", res)
})
},
posPrintText () {
let that = this
posPrintText("哈哈哈哈哈哈哈哈哈\r\n", function (res) {
that.msg = JSON.stringify(res)
console.log("posPrintText", res)
})
},
posPrintText1 () {
let that = this
posPrintText("啊啊啊啊啊啊\r\n", function (res) {
that.msg = JSON.stringify(res)
console.log("posPrintText", res)
})
},
posPrintSelfTestPage () {
let that = this
posPrintSelfTestPage(function (res) {
that.msg = JSON.stringify(res)
console.log("posPrintSelfTestPage", res)
})
},
posFeedDot () {
let that = this
posFeedDot(2, function (res) {
that.msg = JSON.stringify(res)
console.log("posFeedDot", res)
})
},
posFeedLine () {
let that = this
posFeedLine(2, function (res) {
that.msg = JSON.stringify(res)
console.log("posFeedLine", res)
})
},
posFeedAndHalfCutPaper () {
let that = this
posFeedAndHalfCutPaper(function (res) {
that.msg = JSON.stringify(res)
console.log("posFeedAndHalfCutPaper", res)
})
},
posBeep () {
let that = this
posBeep(2, 600, function (res) {
that.msg = JSON.stringify(res)
console.log("posQueryRTStatus", res)
})
},
posQueryRTStatus() {
let that = this
posQueryRTStatus(500, function (res) {
that.msg = JSON.stringify(res)
console.log("posQueryRTStatus", res)
})
},
getLibraryVersion () {
let that = this
getLibraryVersion((res) => {
that.msg = JSON.stringify(res)
console.log("getLibraryVersion", res)
})
},
enumUsb () {
let that = this
enumUsb((res) => {
that.msg = JSON.stringify(res)
console.log("enumUsb", res)
})
},
openUsb () {
let that = this
openUsb('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 = this
halfCutPaper((res) => {
that.msg = JSON.stringify(res)
console.log("halfCutPaper", res)
})
},
fullCutPaper () {
let that = this
fullCutPaper((res) => {
that.msg = JSON.stringify(res)
console.log("fullCutPaper", res)
})
},
}
}
</script>
<style>
</style>