更新记录

1.0.2(2025-04-12)

  1. 优化

1.0.1(2025-04-12)

  1. 优化demo

1.0.0(2025-04-07)

蓝牙、定位

查看更多

平台兼容性

Vue2 Vue3
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佳能打印机

开发文档

  1. 集成插件步骤请参考 https://www.cnblogs.com/wenrisheng/p/18323027

接口文档

如需更多接口请联系作者


import {
    UTSAutoreplyPrint
} from "@/uni_modules/wrs-uts-autoreplyprint"

连接打印机

  • usb连接

// 获取所有的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")
}
  • spp经典蓝牙连接

// address是设备的mac地址,可以使用插件https://ext.dcloud.net.cn/plugin?id=19951扫描得到
let address = "xxx"
let autoreplymode = 0
let suc = UTSAutoreplyPrint.CP_Port_OpenBtSpp(address, autoreplymode)
  • ble低功耗蓝牙连接

// address是设备的mac地址,可以使用插件https://ext.dcloud.net.cn/plugin?id=19951扫描得到
let address = "xxx"
let autoreplymode = 0
let suc = UTSAutoreplyPrint.CP_Port_OpenBtBle(address, autoreplymode)
  • Wi-Fi连接

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)

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不采集任何数据

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问