Open yogesh9059 opened 6 years ago
Any one solve this problem read failed, socket might closed or timeout, read ret: -1 Still iam getting same error.
Can anyone provide sample code for angular ionic capacitor printer integration? I am stuck in BTPrinter.list itself..
Hi, Not sure if this is still necessary but try Cordova-Bluetooth-Printer-Plugin by TruewindIT.
{
"version": "1.0.0",
"name": "Cordova-Bluetooth-Printer-Plugin",
"cordova_name": "Cordova Bluetooth Printer Plugin",
"license": "MIT License",
"author": "Truewind IT",
"platforms": [ "android"],
"repository": {
"type": "git",
"url": "git+https://github.com/TruewindIT/Cordova-Bluetooth-Printer-Plugin.git"
}
}
Listing connected devices:
BTPrinter.list(function(success){
$("#console").append("Success");
$("#console").append("::"+JSON.stringify(success, null, 2)+"::");
success.forEach((e) => {
$("#deviceList").append(`<li value="${e}">${e}</li>`)
});
},function(err){
$("#console").append("Error\n");
$("#console").append(JSON.stringify(err, null, 2))
})
Connect and Print
NOTE: BTPrinter.print is the correct method not BTPrinter.printText based on the BluetoothPrinter.java
$('#deviceList').on('click', 'li', function () {
var deviceId = $(this).val();
var deviceName = $(this).text();
BTPrinter.connect(function(data){
$("#console").append("Connect Success\n");
$("#console").append(JSON.stringify(data, null, 2)+"\n")
BTPrinter.print(function(data){
$("#console").append("Printing Success:\n");
$("#console").append(JSON.stringify(data, null, 2)+"\n");
BTPrinter.disconnect(function(){
$("#console").append("Disconnect Success:\n");
},function(err){
$("#console").append("Disconnect Error");
}, deviceName)
},function(err){
$("#console").append("Failed in Printing:\n")
$("#console").append(JSON.stringify(err, null, 2)+"\n")
}, "Hello world text.\n\n\n\n")
},function(err){
$("#console").append("Connect Error\n");
$("#console").append(JSON.stringify(err, null, 2)+"\n")
}, deviceName)
// Attempt to connect to the selected device
});
cordova-bluetooth-printer-plugin/src/android/BluetoothPrinter.java
line 121
else if( action.equals("print") )
{
try
{
String msg = args.getString(0);
print(callbackContext, msg);
}
catch( IOException e )
{
Log.e(LOG_TAG, e.getMessage());
e.printStackTrace();
}
return true;
}
I am using this plugin in ionic1. BTPrinter.list gives me list of bluetooth devices paired with my android device. But when i try to connect any bluetooth device it gives error
I try with adding $timeout but it still gives same error. For connecting to bluettoth device below is code
If any one solve this issue please help me to solve it.