更新记录
1.0.2(2025-04-12)
- 优化
1.0.1(2025-04-12)
- 优化demo
1.0.0(2025-04-07)
蓝牙、定位
查看更多
平台兼容性
App |
快应用 |
微信小程序 |
支付宝小程序 |
百度小程序 |
字节小程序 |
QQ小程序 |
HBuilderX 3.6.8,Android:4.4,iOS:不支持,HarmonyNext:不支持 |
× |
× |
× |
× |
× |
× |
钉钉小程序 |
快手小程序 |
飞书小程序 |
京东小程序 |
鸿蒙元服务 |
× |
× |
× |
× |
× |
H5-Safari |
Android Browser |
微信浏览器(Android) |
QQ浏览器(Android) |
Chrome |
IE |
Edge |
Firefox |
PC-Safari |
× |
× |
× |
× |
× |
× |
× |
× |
× |
Caysn佳能打印机
开发文档
- 集成插件步骤请参考 https://www.cnblogs.com/wenrisheng/p/18323027
接口文档
如需更多接口请联系作者
import {
UTSAutoreplyPrint
} from "@/uni_modules/wrs-uts-autoreplyprint"
连接打印机
// 获取所有的usb设备
let resp = UTSAutoreplyPrint.EnumUsb()
let usbs = resp.usbs
if (usbs) {
let usb = ""
for (let i = 0; i < usbs.length; i++) {
let str = usbs[i]
// 筛选出打印机的usb
if (str.include("0x4B43") || str.include("0x0FE6")) {
usb = str
break
}
}
let name = usb
// 0 不开启自动回传模式
// 1 开启自动回传模式
// 注意:
// 仅部分机型支持自动回传模式,是否支持请询问卖家
// 启动自动回传模式之后,打印机会自动回传状态
// 不启动则无法自动获取打印机状态
let autoreplymode = 0
let suc = UTSAutoreplyPrint.CP_Port_OpenUsb(name, autoreplymode)
if (suc) {
this.showMsg("连接成功")
} else {
this.showMsg("连接失败")
}
} else {
this.showMsg("没有发现usb")
}
// address是设备的mac地址,可以使用插件https://ext.dcloud.net.cn/plugin?id=19951扫描得到
let address = "xxx"
let autoreplymode = 0
let suc = UTSAutoreplyPrint.CP_Port_OpenBtSpp(address, autoreplymode)
// address是设备的mac地址,可以使用插件https://ext.dcloud.net.cn/plugin?id=19951扫描得到
let address = "xxx"
let autoreplymode = 0
let suc = UTSAutoreplyPrint.CP_Port_OpenBtBle(address, autoreplymode)
let localIp = null
// 打印机IP
let ip = "192.168.0.132"
let port = 9100
let timeout = 5000
let autoreplymode = 0
let suc = UTSAutoreplyPrint.CP_Port_OpenTcp(localIp, ip, port, timeout, autoreplymode)
let name = "/dev/ttyS4"
let baund = 115200
let databits = 8
let parity = 0
let stopbits = 0
let flowcontrol = 0
let autoreplymode = 0
let suc = UTSAutoreplyPrint.CP_Port_OpenCom(name, baund, databits, parity, stopbits, flowcontrol, autoreplymode)
let suc = UTSAutoreplyPrint.CP_Port_Close()
let suc = UTSAutoreplyPrint.CP_Pos_FeedAndHalfCutPaper()
let numLines = 5
let suc = UTSAutoreplyPrint.CP_Pos_FeedLine(numLines)
let suc = UTSAutoreplyPrint.CP_Pos_ResetPrinter()
let suc = UTSAutoreplyPrint.CP_Pos_SetMultiByteMode()
// int CP_MultiByteEncoding_GBK = 0;
// int CP_MultiByteEncoding_UTF8 = 1;
// int CP_MultiByteEncoding_BIG5 = 3;
// int CP_MultiByteEncoding_ShiftJIS = 4;
// int CP_MultiByteEncoding_EUCKR = 5;
let encode = 0
let suc = UTSAutoreplyPrint.CP_Pos_SetMultiByteEncoding(encode)
let str = "00000"
let suc = UTSAutoreplyPrint.CP_Pos_PrintText(str)
// utf8打印
let suc = UTSAutoreplyPrint.CP_Pos_PrintTextInUTF8(str)
// 0 左对齐
// 1 中对齐
// 2 右对齐
let align = 0
let suc = UTSAutoreplyPrint.CP_Pos_SetAlignment(align)
let position = 0
let suc = UTSAutoreplyPrint.CP_Pos_SetHorizontalAbsolutePrintPosition(position)
// 0 无下划线
// 1 1 点下划线
// 2 2 点下划线
let underLine = 0
let suc = UTSAutoreplyPrint.CP_Pos_SetTextUnderline(underLine)
let widthScale = 2
let heightScale = 3
let suc = UTSAutoreplyPrint.CP_Pos_SetTextScale(widthScale, heightScale)
// 设置条码高度
let height = 60
let suc = UTSAutoreplyPrint.CP_Pos_SetBarcodeHeight(height)
// 设置条码和二维码单元宽度
let width = 3
let suc = UTSAutoreplyPrint.CP_Pos_SetBarcodeUnitWidth(width)
// 设置条码可读字符打印位置
// int CP_Pos_BarcodeTextPrintPosition_None = 0;
// int CP_Pos_BarcodeTextPrintPosition_AboveBarcode = 1;
// int CP_Pos_BarcodeTextPrintPosition_BelowBarcode = 2;
// int CP_Pos_BarcodeTextPrintPosition_AboveAndBelowBarcode = 3;
let position = 3
let suc = UTSAutoreplyPrint.CP_Pos_SetBarcodeReadableTextPosition(position)
// 0x41 UPC-A
// 0x42 UPC-E
// 0x43 EAN13
// 0x44 EAN8
// 0x45 CODE39
// 0x46 ITF
// 0x47 CODABAR
// 0x48 CODE93
// 0x49 CODE128
let barcodeType = 65
let str = "xxxx"
let suc = UTSAutoreplyPrint.CP_Pos_PrintBarcode(barcodeType, str)
let beepCount = 2
let beepMs = 500
let suc = UTSAutoreplyPrint.CP_Pos_Beep(beepCount, beepMs)
let timeout = 3000
let suc = UTSAutoreplyPrint.CP_Pos_QueryPrintResult(timeout)
let suc = UTSAutoreplyPrint.CP_Printer_ClearPrinterBuffer()
// 0 不加粗
// 1 加粗
let bold = 3000
let suc = UTSAutoreplyPrint.CP_Pos_SetTextBold(bold)
let start = 0
let end = 575
let suc = UTSAutoreplyPrint.CP_Pos_PrintHorizontalLine(start, end)
let suc = UTSAutoreplyPrint.CP_Pos_FullCutPaper()
let filePath = "/aaaaa/aaa/bb.png" // 本地图片文件绝对路径
// 图片二值化算法。0 表示抖动算法,1 表示阀值算法,2 表示误差扩散法。具体效果请测试查看。
let binaryzation_method = 0
// 0 不压缩
// 1 一级压缩
// 2 二级压缩
let compression_method = 0
let suc = UTSAutoreplyPrint.PrintRasterImageFromBitmap(filePath, binaryzation_method, compression_method)