labibramadhan / cordova-sunmi-inner-printer

29 stars 32 forks source link

CapacitorJS Sunmi v2Pro #28

Open RichyFennell opened 3 years ago

RichyFennell commented 3 years ago

Hi there, Trying to use this in my Capacitor project, seems to build fine but does not talk to printer.

npm i cordova-plugin-sunmi-inner-printer

//(Have not imported the package, should??? // import * as sunmi from 'cordova-plugin-sunmi-inner-printer'???

//have following after my angular imports:

declare var sunmiInnerPrinter: any;

//below in a function on a button

  ```
     try {
    console.log('trying to print');

    if (JSON.stringify(sunmiInnerPrinter) !== "{}") {
      //theres a problem
      console.log('Printer output',JSON.stringify(sunmiInnerPrinter));
    return;
    }
    // it is safe to use sunmiInnerPrinter here
    sunmiInnerPrinter.printerInit();

    console.log('status',JSON.stringify(sunmiInnerPrinter.getPrinterVersion()));
    sunmiInnerPrinter.printOriginalText("Hello Printer");
    } catch(err) {
    console.log("error: "+ JSON.stringify(err));
    }


> ng build
> npx cap sync

----
Copying capacitor.config.json in 1.34ms
⠼ copy  Found 1 Cordova plugin for android
    cordova-plugin-sunmi-inner-printer (1.1.0)
✔ copy in 389.04ms
✔ Updating Android plugins in 49.87ms
  Found 1 Capacitor plugin for android:
    @capacitor-community/fcm (1.0.8)
  Found 1 Cordova plugin for android
    cordova-plugin-sunmi-inner-printer (1.1.0)
✔ update android in 394.63ms
----

Run the Android project on my Sumni device I get the following message:
D/SunmiInnerPrinter: Service connected

But when I print nothing happens and I get the following logs:
I/Capacitor/Console: File: http://localhost/vendor.js - Line 86038 - Msg: trying to print
I/Capacitor/Console: File: http://localhost/vendor.js - Line 86038 - Msg: error: {}

Thank you in advance for your help. I've got a few of these devices now so keen to get it working if I can

Rich

Capacitor version 6.14.11
Angular 7.3.1
Ionic 5.4.16
RichyFennell commented 3 years ago

Upon further investigation I am not sure the Sunmi V2 and V1 are compatible. Can anyone confirm?

pilz97 commented 1 year ago

@RichyFennell i have the same issue I have a P2Pro where it works perfectly. But on my V2s i noticed that InnerPrinterManager.getInstance().bindService(applicationContext, innerPrinterCallback);

returns false