2016-10-17 12 views
0

Rongta RRP-200モバイルプリンタを使用してテキストを印刷するアプリがあり、携帯電話とblueetothで接続しています。このため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

まあ、私は同じプリンタを持っていると私のために少しのプラグインの作業awsomeさんを書いた:誰もが(そのイオンアプリのコントローラで)それを必要とする場合にはこれは、何かを印刷する機能です。私は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) { 

});