2016-10-17 158 views
0

我有一个应用程序,它使用Rongta RRP-200移动打印机打印一些文本,通过蓝牙与我的手机连接。Android - 从移动打印机上的应用程序打印

对于这一点,我使用这个插件:https://github.com/srehanuddin/Cordova-Plugin-Bluetooth-Printer

我能到我的设备连接到打印机,甚至从我的应用程序,这使我回了一个短信跑打印功能通知我数据寄了,送了。但是,打印机什么也不做(除了打开灯)。

这是试图打印我的文字的功能(从插件):

boolean printText(CallbackContext callbackContext, String msg) throws IOException { 
    try { 
     mmOutputStream.write(msg.getBytes()); 

     // tell the user data were sent 
     //Log.d(LOG_TAG, "Data Sent"); 
     callbackContext.success("Data Sent"); 
     return true; 

    } catch (Exception e) { 
     String errMsg = e.getMessage(); 
     Log.e(LOG_TAG, errMsg); 
     e.printStackTrace(); 
     callbackContext.error(errMsg); 
    } 
    return false; 
} 

什么可能出问题会在这里?

回答

0

发现插件工作正常,但您必须给打印机一个完整的行以使其打印出某些内容。因此,请在字符串末尾添加\n。这是打印的东西的功能,万一有人需要它(其在离子应用控制器):

$scope.print = function(text) { 
    BTPrinter.connect(function(data){ 
     BTPrinter.printText(function(data){ 
      BTPrinter.disconnect(function(){},function(err){ 
       console.log("Error"); 
       console.log(err) 
      }, "Your Printer device") 
     }, function(err){ 
      console.log("Error"); 
      console.log(err) 
     }, text + "\n") 
    }, function(err){ 
      console.log("Error"); 
      console.log(err) 
    }, "Your Printer device"); 
} 
0

那么我有同样的打印机,并写了一个小插件,它的工作棒极了我。我在RPP200和RPP300中进行了测试。

https://github.com/CXRom/cordova-plugin-rpp

Rpp.Connect("00:0E:0E:0B:7B:93", // <-- MAC Address of the printer 
    function(print) { 
    //At this point we send the action but we need to wait until the connection 
    console.log(`connect ok ${JSON.stringify(print)}`); 
    }, 
    function (err){ 
    console.log(`connect err ${JSON.stringify(err)}`); 
    }); 

//Ask is device is connected 
Rpp.IsConnected(function(conn) { 
    //Send to print 
    Rpp.Print({ 
    marginTop: 10, //Margin before print 
    marginBottom: 10, //Margin after print 
    lineSpacing: 50, //Size of line 
    lines: [ //Lines to print 
     { text: "Title", align: 1, bold: true, underline: true, size: 17 }, //long name properties 
     { text: "Subtitle", a: 1, b: true, u: true, s: 17 }, //short name properties 
     { text: "normal line" }, 
     { text: ":)", h: true } 
    ] 
    }, function(res) { 
    console.log(`print ok ${JSON.stringify(res)}`); 
    }, function(err){ 
    console.log(`print err ${JSON.stringify(err)}`); 
    }); 
}, function(err) { 

}); 
相关问题