januslo / react-native-bluetooth-escpos-printer

React-Native plugin for the bluetooth ESC/POS & TSC printers.
MIT License
359 stars 416 forks source link

Error: COMMAND_NOT_SEND #129

Open soadtechdev opened 3 years ago

soadtechdev commented 3 years ago

I can't get it to print, it worked only once, then it didn't work again, can you help me?

useEffect(()=>{
  BluetoothManager.isBluetoothEnabled().then((enabled)=> {
    setEnableBlue(enabled);
    if(enabled){
      BluetoothManager.enableBluetooth().then((r)=>{
        var paired = [];
        if(r && r.length>0){
            for(var i=0;i<r.length;i++){
                try{
                  let obj=JSON.parse(r[i]);
                 if(obj.address==="34:81:F4:36:52:BD"){

                  BluetoothManager.connect(obj.address).then(async(s)=>{
                  console.log("S====",s)
                    setEstadoBlue("CONECTADO AL DISPOSITIVO :"+obj.name);
                  await BluetoothEscposPrinter.printText("ESTA IMPRIMIENDO sera que necesita mas texto\n\r",{})
                  },
                  (err)=>{
                    setEstadoBlue("SIN CONEXION AL DISPOSITIVO :"+obj.name)
                  })

                 }
                }catch(e){
                    //ignore
                }
            }
        }
        console.log(JSON.stringify(paired))

    },(err)=>{
       alert(err)
   });

    }
}, (err)=> {
  setEnableBlue(false)
    alert(err)
}); 
},[])
ssjuma commented 3 years ago

At the end of your document, add this line and it will print: await BluetoothEscposPrinter.printText("\n\r\n\r\n\r",{}); Hope this helps :)

ombogdan commented 3 years ago

same error with printPic on IOS. How to fix it?

mohamedsalehamin commented 2 years ago

i have the same issue on IOS , Did any one Solve it ?

Benjamin1-pro commented 1 year ago

this worked for me BluetoothManager.enableBluetooth().then( (r) => { var paired = []; if (r && r.length > 0) { for (var i = 0; i < r.length; i++) { try { paired.push(JSON.parse(r[i])); let obj=JSON.parse(r[i]); if (obj.address === "20:18:05:22:03:06") { BluetoothManager.connect(obj.address) .then((s)=>{ console.log("S====",s) BluetoothEscposPrinter.printerAlign(BluetoothEscposPrinter.ALIGN.CENTER); BluetoothEscposPrinter.setBlob(0); BluetoothEscposPrinter.printText("EazyFlow\n\r", { encoding: "GBK", codepage: 0, widthtimes: 1, heigthtimes: 1, fonttype: 0, }); BluetoothEscposPrinter.setBlob(0); BluetoothEscposPrinter.printText("Facture\n\r", { encoding: "GBK", codepage: 0, widthtimes: 0, heigthtimes: 0, fonttype: 0, }); BluetoothEscposPrinter.printerAlign(BluetoothEscposPrinter.ALIGN.LEFT); BluetoothEscposPrinter.printText("Label:Vente des marchandise\n\r", {}); BluetoothEscposPrinter.printText("Code:xsd201909210000001\n\r", {}); BluetoothEscposPrinter.printText( "Date:" +new Date().getDate()+"-"+(new Date().getMonth()+1)+"-"+new Date().getFullYear() + "\n\r", {} ); BluetoothEscposPrinter.printText("Number:18664896621\n\r", {}); BluetoothEscposPrinter.printText( "--------------------------------\n\r", {} ); BluetoothEscposPrinter.printText("Amount:64000.00\n\r", {}); BluetoothEscposPrinter.printText("Tax:0.00\n\r", {}); BluetoothEscposPrinter.printText("Total:64000.00\n\r", {}); BluetoothEscposPrinter.printText( "--------------------------------\n\r", {} ); BluetoothEscposPrinter.printerAlign(BluetoothEscposPrinter.ALIGN.CENTER); BluetoothEscposPrinter.printText("Thanks for payment\n\r\n\r\n\r\n\r", {}); BluetoothEscposPrinter.printerAlign(BluetoothEscposPrinter.ALIGN.LEFT); }) } } catch (e) { //ignore } } } console.log(JSON.stringify(paired)); }, (err) => { alert(err); } );

OhFarhan commented 11 months ago

this worked for me BluetoothManager.enableBluetooth().then( (r) => { var paired = []; if (r && r.length > 0) { for (var i = 0; i < r.length; i++) { try { paired.push(JSON.parse(r[i])); let obj=JSON.parse(r[i]); if (obj.address === "20:18:05:22:03:06") { BluetoothManager.connect(obj.address) .then((s)=>{ console.log("S====",s) BluetoothEscposPrinter.printerAlign(BluetoothEscposPrinter.ALIGN.CENTER); BluetoothEscposPrinter.setBlob(0); BluetoothEscposPrinter.printText("EazyFlow\n\r", { encoding: "GBK", codepage: 0, widthtimes: 1, heigthtimes: 1, fonttype: 0, }); BluetoothEscposPrinter.setBlob(0); BluetoothEscposPrinter.printText("Facture\n\r", { encoding: "GBK", codepage: 0, widthtimes: 0, heigthtimes: 0, fonttype: 0, }); BluetoothEscposPrinter.printerAlign(BluetoothEscposPrinter.ALIGN.LEFT); BluetoothEscposPrinter.printText("Label:Vente des marchandise\n\r", {}); BluetoothEscposPrinter.printText("Code:xsd201909210000001\n\r", {}); BluetoothEscposPrinter.printText( "Date:" +new Date().getDate()+"-"+(new Date().getMonth()+1)+"-"+new Date().getFullYear() + "\n\r", {} ); BluetoothEscposPrinter.printText("Number:18664896621\n\r", {}); BluetoothEscposPrinter.printText( "--------------------------------\n\r", {} ); BluetoothEscposPrinter.printText("Amount:64000.00\n\r", {}); BluetoothEscposPrinter.printText("Tax:0.00\n\r", {}); BluetoothEscposPrinter.printText("Total:64000.00\n\r", {}); BluetoothEscposPrinter.printText( "--------------------------------\n\r", {} ); BluetoothEscposPrinter.printerAlign(BluetoothEscposPrinter.ALIGN.CENTER); BluetoothEscposPrinter.printText("Thanks for payment\n\r\n\r\n\r\n\r", {}); BluetoothEscposPrinter.printerAlign(BluetoothEscposPrinter.ALIGN.LEFT); }) } } catch (e) { //ignore } } } console.log(JSON.stringify(paired)); }, (err) => { alert(err); } );

this works as expected thanks @Benjamin1-pro