-
APICloud开发-djyPrinter>djyPrinter
djyPrinter
背景
在项目中用到小票打印功能,鉴于打印机支持pos命令由此而开发。 支持安卓4.0.4+ 测试设备htc(androi4.0.4),小米(androi4.4.4),华为畅享5s(androi5.1),华为mate8(androi6.0)
支持
- 打开蓝牙搜索打印设备
- 通过连接指定
- 打印POS命令
模块接口
scan
初始化蓝牙并搜索附近的蓝牙设备
scan({}, callback(ret,err))
callback(ret,err)
ret:
- 类型:JSON对象
- 内部字段:
{ status: true //扫描开始 }err:
var BluetoothPrinter = api.require('djyPrinter'); BluetoothPrinter.scan({}, function (ret, err) { })可用性
Android系统
可提供的1.0.0及更高版本
cancelScan
取消搜索附近的蓝牙设备
cancelScan({}, callback(ret,err))
callback(ret,err)
ret:
- 类型:JSON对象
- 内部字段:
{ status: true //扫描开始 }err:
var BluetoothPrinter = api.require('djyPrinter'); BluetoothPrinter.cancelScan({}, function (ret, err) { })可用性
Android系统
可提供的1.0.0及更高版本
listBT
列出所有搜索到的蓝牙设备
listBT({}, callback(ret,err))
callback(ret,err)
ret:
- 类型:JSON对象
- 内部字段:
{ [ address://地址 state://状态 name: //名称(用于连接设备) ] }err:
var BluetoothPrinter = api.require('djyPrinter'); BluetoothPrinter.listBT({}, function (ret, err) { })可用性
Android系统
可提供的1.0.0及更高版本
connect
连接(配对)蓝牙设备。
connect({params}, callback(ret,err))
params
name
- 类型:字符串
- 描述:设备名称 listBT 返回的设备名称
callback(ret,err)
ret:
- 类型:JSON对象
- 内部字段:
{ status: true //已经连接 }err
示例代码
var BluetoothPrinter = api.require('djyPrinter'); BluetoothPrinter.connect({ name: 'Gprinter_C20B' },function (ret, err) { });可用性
Android系统
可提供的1.0.0及更高版本
disconnectBT
断开设备
disconnectBT({}, callback(ret,err))
callback(ret,err)
ret:
- 类型:JSON对象
- 内部字段:
{ status: true //已经连接 }err
示例代码
var BluetoothPrinter = api.require('djyPrinter'); BluetoothPrinter.disconnectBT({ },function (ret, err) { });可用性
Android系统
可提供的1.0.0及更高版本
printPOSCommand
获取当前扫描到的所有外围设备信息
printPOSCommand({params}, callback(ret,err))
params
{ msg: "" //pos命令以及需要打印的内容连接的字符串 支持中文 }
callback(ret,err)
ret:
- 类型:JSON对象
- 内部字段:
{ status: true //成功 }err:
- 类型:JSON对象
- 内部字段:
{ msg: //错误信息 }示例代码
var BluetoothPrinter = api.require('djyPrinter'); BluetoothPrinter.printPOSCommand({ msg: String.fromCharCode(29) + String.fromCharCode(33) + String.fromCharCode(17) + //字体放大 String.fromCharCode(27) + String.fromCharCode(97) + String.fromCharCode(1) + //居中 String.fromCharCode(10) + String.fromCharCode(10) + "零点美食城\n" + String.fromCharCode(29) + String.fromCharCode(33) + String.fromCharCode(0) + //字体放大 String.fromCharCode(27) + String.fromCharCode(97) + String.fromCharCode(0) + "西红柿鸡蛋面" + "12元" + "\n" + String.fromCharCode(27) + String.fromCharCode(97) + String.fromCharCode(0) + String.fromCharCode(10) + "总计12元" + "\n" // + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" }, function (ret, err) { });可用性
Android系统
可提供的1.0.0及更高版本
回顶部