2016-10-17 102 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) { 

}); 
相關問題