背景
在项目中用到小票打印功能,鉴于打印机支持pos命令由此而开发。 支持安卓4.0.4+ 测试设备htc(androi4.0.4),小米(androi4.4.4),华为畅享5s(androi5.1),华为mate8(androi6.0)
支持
插件接口
初始化蓝牙并搜索附近的蓝牙设备
scan({}, callback(ret,err))
ret:
{
    status: true   //扫描开始
}
err:
{
    msg: //错误信息
}
var BluetoothPrinter = api.require('djyPrinter');
BluetoothPrinter.scan({}, function (ret, err) {
    
})
Android系统
可提供的1.0.0及更高版本
取消搜索附近的蓝牙设备
cancelScan({}, callback(ret,err))
ret:
{
    status: true   //扫描开始
}
err:
{
    msg: //错误信息
}
var BluetoothPrinter = api.require('djyPrinter');
BluetoothPrinter.cancelScan({}, function (ret, err) {
    
})
Android系统
可提供的1.0.0及更高版本
列出所有搜索到的蓝牙设备
listBT({}, callback(ret,err))
ret:
{
     [
        address://地址
        state://状态
        name: //名称(用于连接设备)
     ]
}
err:
{
    msg: //错误信息
}
var BluetoothPrinter = api.require('djyPrinter');
BluetoothPrinter.listBT({}, function (ret, err) {
    
})
Android系统
可提供的1.0.0及更高版本
连接(配对)蓝牙设备。
connect({params}, callback(ret,err))
name
ret:
{
    status: true   //已经连接
}
err
{
    msg:    //错误信息
}
var BluetoothPrinter = api.require('djyPrinter');
BluetoothPrinter.connect({
          name: 'Gprinter_C20B'
    },function (ret, err) {
      
});
Android系统
可提供的1.0.0及更高版本
断开设备
disconnectBT({}, callback(ret,err))
ret:
{
    status: true   //已经连接
}
err
{
    msg:    //错误信息
}
var BluetoothPrinter = api.require('djyPrinter');
BluetoothPrinter.disconnectBT({
      },function (ret, err) {
});
Android系统
可提供的1.0.0及更高版本
获取当前扫描到的所有外围设备信息
printPOSCommand({params}, callback(ret,err))
{ msg: "" //pos命令以及需要打印的内容连接的字符串 支持中文 }
ret:
{
    status: true   //成功
}
err:
{
    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及更高版本
