更新记录
1.0.6(2023-11-24)
兼容 Android 13 兼容 HarmonyOS 3.0
1.0.5(2021-04-12)
1、完善优化连接与打印 2、添加蓝牙相关方法 3、重构主要代码架构
1.0.3(2021-02-02)
完善功能
查看更多平台兼容性
Android | Android CPU类型 | iOS |
---|---|---|
适用版本区间:5.0 - 11.0 | armeabi-v7a:未测试,arm64-v8a:未测试,x86:未测试 | × |
原生插件通用使用流程:
- 购买插件,选择该插件绑定的项目。
- 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
- 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
- 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
- 开发完毕后正式云打包
付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios
注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择
蓝牙打印通用插件
一、使用说明
本插件支持便携式打印机常用指令格式打印,已经在汉印、佳博、富士通等等四五款打印机中正式使用。开发前,请咨询购买打印机客服要打印机指令文档,cpcl编码文档或ESC指令文档,打印机品牌不同,指令也有所差异,请不要直接使用示例中的命令。
二、性能调优
1、本插件已经做了优化,搜索、连接和打印速度很快
2、搜索蓝牙列表:是个比较耗时的操作,本插件采用搜索一个个设备会立即返回,最后搜索完成会返回整个蓝牙设备列表。因此,可以在搜索到自己的设备后,直接调用停止搜索方法。
3、更好的优化,需要优化编码与体验流程:
- 1、蓝牙在搜索时会搜索所有的设备,比较耗时:编码优化有两种,
-
- 1.1、设备与打印机直接使用系统配对完成,直接调用已配对蓝牙列表
- 1.2、调用搜索蓝牙列表方法,搜索到自己的设备后直接调用停止搜索方法。
三、注册打印插件
const print = uni.requireNativePlugin('Common-Print');
四、主要方法
-
判断设备是否支持蓝牙
print.isSupport(result => { //result数据:{"status":true} const msg = JSON.stringify(result); console.log(msg); console.log('是否支持蓝牙:' + result.status); modal.toast({ message: msg, duration: 1.5 }); });
-
判断蓝牙是否打开
print.isOpen(result => { //result数据:{"status":true} const msg = JSON.stringify(result); console.log(msg); console.log('蓝牙是否打开:' + result.status); modal.toast({ message: msg, duration: 1.5 }); });
-
打开蓝牙
print.openBT(result => { //result数据:{"status":true} const msg = JSON.stringify(result); console.log(msg); console.log('开启蓝牙是否成功:' + result.status); modal.toast({ message: msg, duration: 1.5 }); });
-
关闭蓝牙
print.closeBT(result => { //result数据:{"status":true} const msg = JSON.stringify(result); console.log(msg); console.log('蓝牙是否关闭:' + result.status); modal.toast({ message: msg, duration: 1.5 }); });
-
搜索蓝牙列表
print.bluetoothList({ }, result => { const msg = JSON.stringify(result); console.log(msg) modal.toast({ message: msg, duration: 1.5 }); });
-
停止搜索蓝牙
print.stopSearch(result => { //result数据:{"status":true} const msg = JSON.stringify(result); console.log(msg); modal.toast({ message: msg, duration: 1.5 }); });
-
获取已经配对列表
print.listBondedBT(result => { //result数据:{"msg":"搜索完成","list":[{"name":"蓝牙名称","address":"mac地址","status":"配对状态"}]} const msg = JSON.stringify(result); console.log(msg); console.log('已配对列表:' + result.list); modal.toast({ message: msg, duration: 1.5 }); });
-
判断蓝牙是否连接
print.bluetoothConnectState({ btAddress: 'FC:58:FA:A1:DD:93' },result => { //{"state":true} or {"state":false} const msg = JSON.stringify(result); console.log(msg) modal.toast({ message: msg, duration: 1.5 }); });
-
连接蓝牙
print.bluetoothConnect({ btAddress: 'FC:58:FA:A1:DD:93',//蓝牙地址 btName: 'HM-Z3-D8D0'//蓝牙名称 }, result => { const msg = JSON.stringify(result); console.log(msg) modal.toast({ message: msg, duration: 1.5 }); });
-
打印
print.bluetoothPrint({ content: '命令内容' //打印命令内容 }, result => { const msg = JSON.stringify(result); console.log(msg) modal.toast({ message: msg, duration: 1.5 }); });
-
断开连接
print.breakConnect(result => { //result数据:{"status":true} const msg = JSON.stringify(result); console.log(msg); modal.toast({ message: msg, duration: 1.5 }); });
五、命令示例
//打印命令
var path =
"! 0 200 200 1060 1\r\n" +
"EG 33 66 15 20\r\n" +
"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007FFFF000000FFFFFFFF01E1E003C0001FFFFF000FFFFFC00000000000000000001FFFFEFC0000FFFFFFFF01E1E003C0FE1FFFFF0FEFFFFFC00000000000000000003FFFF9FF00000003E00001E1E003C0FE1E00000FE0C00F800000000000000000003FFFF7FF80000003E00003E1F007C0001E00000001F03F000000000000000000007FFFEFFF80000003E0000FFFFFFFF8001E00000001FC7E00000000000000000000FFFFDFFFC0000007C0000FFFFFFFF8001E00000001FFFC00000000000000000001FFFFBFFFE0000007C00001E1E003C0001E0000000FFFFFC0000000000000000003FFFFBFFFE000FFFFFFFF01E1E003C0041E00000FEFFFFFC0000000000000000003FFFF3FFFF000FFFFFFFF01E1E003C0FE1E00000FEF8783C0000000000000000007FFFE1FFFF800F800000F01E1E003C0FE1E00000FEF87C3C0000000000000000007FFFC0FFFF800F000000F01E1E003C01E1E000001EF87C3C000000000000000000FFFFC07FFFC00F800000F01E1E003C01E1E000001EFFFFFC000000000000000001FFFF807FFFE00F800000F01E1E003C01E1E000001EFFFFFC000000000000000001FFFF003FFFE00F800000F01E1E003C01E1E000001EF87C3C000000000000000003FFFE001FFFF00F000000F01E1E003C01E1E000001EF8783C000000000000000003FFFE000FFFF00FFFFFFFF01E1E003C01E1E000001EFFFFFC000000000000000007FFFC000FFFF80FFFFFFFF01E1E007C01E1E000001EFFFFFC000000000000000007FFF80007FFF80FFFFFFFF01E1E00FC01E1E000001EF87C3C00000000000000000FFFF80003FFFC0F000000F01E1FFFF801E1E000001EF8783C00000000000000000FFFF00003FFFC0F000000F01E1FFFF001E1E000001EF87C3C00000000000000000FFFE00001FFFC0F800000F01E0FFFE001E1E000001EF87C7C00000000000000000FFFE00001FFFE0F800000F01E00000001E1E000001EF87C7800000000000000000FFFC00000FFFC0F000001F01E00000003E1E000003E000000000000000000000007FFC00000FFF80F800003F01E00000003C1E000003E000000000000000000000003FFC000007FF00FFFFFFFE01FFFFFFF87C1FFFFF03FFFFFFE000000000000000004FF8000007FE00FFFFFFFC01FFFFFFF87C1FFFFF07FFFFFFE0000000000000000033F8000003F18000000000000000000040000000040000000000000000000000003E300000000F0000000000000000000000000000000000000000000000000000001FF0000003FE0000000000000000000000000000000000000000000000000000000FFF80007FFE0000000000000000000000000000000000000000000000000000000FFFE000FFFC00000000000000000000000000000000000000000000000000000007FFF001FFF800000000000000000000000000000000000000000000000000000003FFF807FFF0006801281C0718007F08081807C027C0E00F00000000000000000001FFFC0FFFF000FF0FF87F0FFC00FF8C18FF8FF87FC3F83F80000000000000000001FFFE1FFFE000C18C006180C000C00630C18C0C60030C30C0000000000000000000FFFFBFFFC000C18C00C080C000C00370C0CC0C60060420400000000000000000007FFFBFFFC000C18C006000C000C003E0C0CC0C60030030000000000000000000007FFF1FFF8000FF0FF83E00C000FF01C0C18FFC7FC3F01F000000000000000000003FFE0FFF0000FF8FF80F80C000FF01C0FF0FF07FC07C07C00000000000000000001FFC07FF1800C18C0001C0C000C003E0C00C3060000E00E00000000000000000001FF803FE0940C0CC00C0C0C000C00770C00C1860060660600000000000000000000FF001FC09C0C18C00E0C0C000C00638C00C1C600706706000000000000000000003E000F80000FF8FFC7F80C000FF8C18C00C0E7FE3FC3FC00000000000000000000000000000007E07FC1F008000FF980CC004063FC1F80F8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\r\n" +
"PAGE - WIDTH 576\r\n" +
"SETMAG 2 2\r\n" +
"TEXT 8 0 380 8 快递包裹\r\n" +
"SETMAG 1 1\r\n" +
"TEXT 8 0 10 100 2020年9月21日11:09:49\r\n" +
"TEXT 8 0 270 100 第1/1个\r\n" +
//条形码
"BARCODE-TEXT 7 0 5\r\n" +
"BARCODE 128 1 3 100 130 130 1106745891514\r\n" +
"BARCODE-TEXT OFF\r\n" +
// 大方框
"BOX 1 270 580 830 2\r\n" +
"SETMAG 3 3\r\n" +
"TEXT 8 0 80 290 深圳123A45\r\n" +
"SETMAG 1 1\r\n" +
"LINE 1 380 580 380 2\r\n" +
// ---集字方框
"BOX 10 390 70 455 5\r\n" +
"SETMAG 2 2\r\n" +
"TEXT 8 0 17 400 集\r\n" +
"SETMAG 3 3\r\n" +
"TEXT 8 0 90 385 深圳\r\n" +
"SETMAG 1 1\r\n" +
"LINE 1 460 580 460 2\r\n" +
// 收字图标
"EG 9 79 10 505 00000003FFC00000000000007FFFFC000000000003FFFFFF80000000000FFFFFFFE0000000003FFFFFFFF800000000FFFFFFFFFE00000001FFFFFFFFFF80000007FFFFFFFFFFC000000FFFF8003FFFE000001FFFC00007FFF000003FFE000000FFF800007FFC0000003FFC0000FFF00000001FFE0001FFE0380E000FFF0001FFC0381E0003FF0003FF80381C0001FF8007FF00381C0000FFC007FE1838380000FFC007FC1C383800007FE00FF81C387FFFF83FE00FF81C387FFFF83FE01FF01C38FFFFF01FF01FF01C38F007001FF01FF01C39F007000FF01FE01C39F007000FF83FE01C3BF007000FF83FE01C3BB807000FF83FE01C3B380F000FF83FE01C38380E000FF83FE01C381C0E0007F83FE01C381C1E000FF83FE01C381E1C000FF83FE01C780E3C000FF81FE01FF80F38000FF81FE01FF807F8000FF01FF03F3803F0000FF01FF03C3801E0001FF00FF0183803F0001FE00FF8003807FC003FE007F800381F3F003FC007FC00387E1FC07FC003FE0039F807F87F8003FE003BF001F8FF8001FF003BC00071FF0001FF8011000003FF0000FFC000000007FE00007FF00000000FFE00007FF80000003FFC00003FFE0000007FF800001FFF800003FFF800001FFFF0000FFFF000000FFFFF01FFFFE0000007FFFFFFFFFFE0000007FFFFFFFFFFC0000003FFFFFFFFFF80000001FFFFFFFFFF00000000FFFFFFFFFF00000000FFFFFFFFFE000000007FFFFFFFFC000000003FFFFFFFF8000000001FFFFFFFF0000000000FFFFFFFF0000000000FFFFFFFE00000000007FFFFFFC00000000003FFFFFF800000000001FFFFFF000000000000FFFFFE0000000000007FFFFC0000000000003FFFFC0000000000003FFFF80000000000001FFFF00000000000000FFFE000000000000007FFC000000000000003FF8000000000000001FF0000000000000000FE00000000000000007C00000000000000003800000000000000001000000000\r\n" +
"TEXT 8 0 80 480 金xx 13800139000\r\n" +
"SETMAG 1 1\r\n" +
"TEXT 8 0 80 510 科技南十二路金蝶软件园A栋\r\n" +
"TEXT 8 0 80 540 软件(换行)\r\n" +
"TEXT 8 0 80 570 园A栋(换行)\r\n" +
"LINE 1 650 580 650 2\r\n" +
// 反转变黑
"SETMAG 2 2\r\n" +
"TEXT 8 0 20 670 寄\r\n" +
"SETMAG 1 1\r\n" +
"TEXT 8 0 20 730 白小递\r\n" +
"TEXT 8 0 20 760 138 0013 8000\r\n" +
"LINE 250 650 250 830 2\r\n" +
"LINE 405 680 405 830 2\r\n" +
"LINE 1 830 580 830 2\r\n" +
// 二维码
"BARCODE QR 255 675 M 2 U 7\r\n" +
"MA,1106745891514\r\n" +
"ENDQR\r\n" +
"LINE 405 740 580 740 2\r\n" +
"SETMAG 1 1\r\n" +
"TEXT 8 0 415 660 已验视\r\n" +
"TEXT 8 0 415 750 签字栏\r\n" +
"TEXT 8 0 10 840 文件一件\r\n" +
"TEXT 8 0 470 930 已验视\r\n" +
"PRINT\r\n";
六、定制服务
技术支持与定制插件:
-
QQ:690898091
-
QQ群:475527470
-
微信:qq690898091