tr3v3r / react-native-esc-pos-printer

An unofficial React Native library for printing on an EPSON TM printer with the Epson ePOS SDK for iOS and Epson ePOS SDK for Android
MIT License
157 stars 72 forks source link

Cannot find any printer on Kiosk device!! #78

Closed nvdnvd00 closed 9 months ago

nvdnvd00 commented 1 year ago

Hi, I'm intergrating the library for a kiosk device with printer connected via USB port image My app working okay with my tablet but It couldn't find any printer on kiosk image

Didn't return any error, it's just discover forever.

I tried again with other app: TM Assistant and it can detect my printer normally image My printer is EU-m30

Do you know why? May I missed some configuration from android native ?

Kiosk found new USB device in android logcat:


11-18 09:38:50.218     0     0 I usb 5-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
11-18 09:38:50.218     0     0 I usb 5-1.2: Product: EU-m30
11-18 09:38:50.218     0     0 I usb 5-1.2: Manufacturer: EPSON
11-18 09:38:50.218     0     0 I usb 5-1.2: SerialNumber: <hidden>
11-18 09:38:50.223     0     0 I usblp 5-1.2: 1.0: usblp0: USB Bidirectional printer dev 4 if 0 alt 0 proto 2 vid 0x04B8 pid 0x0E2E```
tr3v3r commented 1 year ago

@nvdnvd00 Hello! Have you tried to run an example app? Could you please try to look at a logcat during "discovery"?

nvdnvd00 commented 1 year ago

@tr3v3r Yes, my app working perfectly on my tablet. But it discover forever on kiosk device

CleanShot 2022-11-21 at 18 04 21@2x

I'll put logcat file (of kiosk device) here if you need it https://www.dropbox.com/sh/q6310jkd50wecim/AADwrS7nuhw6JoEYh6jMJX6xa?dl=0&preview=2022.11.17_logcat.txt

The packageName is app.<XXX>.kiosk

tr3v3r commented 1 year ago

@nvdnvd00 Could you tell me a bit more info about your kiosk device? Android version And processor architecture? processor architecture

tr3v3r commented 1 year ago

@nvdnvd00 Btw how did you achieve such a layout? I mean text on the left and right?

image

asking because working right now on the way to do it

nvdnvd00 commented 1 year ago

@tr3v3r I repeat "space" between left side and right side. It still works for long line with wrap. I'm waiting for kiosk information and will send it to you soon. Everything I know is meridian kiosk and it run on android 11

const printLeftRight = (
    printing: Printing,
    left: string,
    right: string,
    maxChar: number,
    size: TScalingFactors = 1,
) => {
    const totaLeft: number = left.length * size;
    const totaRight: number = right.length * size;
    const totalChar: number = totaLeft + totaRight;
    let centerSpaceLength: number = 0;
    let numberOfLines = 1;

    while (numberOfLines * maxChar < totalChar) {
        numberOfLines++;
    }

    centerSpaceLength = numberOfLines * maxChar - totalChar;

    printing
        .size(size)
        .text(left)
        .size(1)
        .text(' '.repeat(centerSpaceLength))
        .size(size)
        .text(right)
        .newline();
};
tr3v3r commented 1 year ago

@nvdnvd00 and for maxChar you're using this method, right?

image
nvdnvd00 commented 1 year ago

@tr3v3r Correct!

nvdnvd00 commented 1 year ago

@tr3v3r Here's kiosk device specs (highlight part)

CleanShot 2022-11-21 at 22 40 45@2x
tr3v3r commented 1 year ago

@nvdnvd00 sorry but I need also processor architecture.

nvdnvd00 commented 1 year ago

@tr3v3r Does it help? My printer is EU-m30

ip-192-168-1-98:platform-tools kentk$ ./adb -s 192.168.100.2:46005 shell cat /proc/cpu/info
cat: /proc/cpu/info: No such file or directory
ip-192-168-1-98:platform-tools kentk$ ./adb -s 192.168.100.2:46005 shell getprop ro.product.cpu.abi
arm64-v8a
ip-192-168-1-98:platform-tools kentk$ ./adb -s 192.168.100.2:46005 shell getprop | grep abi
[ro.odm.product.cpu.abilist]: [arm64-v8a,armeabi-v7a,armeabi]
[ro.odm.product.cpu.abilist32]: [armeabi-v7a,armeabi]
[ro.odm.product.cpu.abilist64]: [arm64-v8a]
[ro.product.cpu.abi]: [arm64-v8a]
[ro.product.cpu.abilist]: [arm64-v8a,armeabi-v7a,armeabi]
[ro.product.cpu.abilist32]: [armeabi-v7a,armeabi]
[ro.product.cpu.abilist64]: [arm64-v8a]
[ro.vendor.product.cpu.abilist]: [arm64-v8a,armeabi-v7a,armeabi]
[ro.vendor.product.cpu.abilist32]: [armeabi-v7a,armeabi]
[ro.vendor.product.cpu.abilist64]: [arm64-v8a]
ip-192-168-1-98:platform-tools kentk$ ./adb -s 192.168.100.2:46005 shell getprop ro.product.cpu.abilist
arm64-v8a,armeabi-v7a,armeabi
ip-192-168-1-98:platform-tools kentk$ ./adb -s 192.168.100.2:46005 shell getprop | grep ro.product.cpu.abi
[ro.product.cpu.abi]: [arm64-v8a]
[ro.product.cpu.abilist]: [arm64-v8a,armeabi-v7a,armeabi]
[ro.product.cpu.abilist32]: [armeabi-v7a,armeabi]
[ro.product.cpu.abilist64]: [arm64-v8a]
ip-192-168-1-98:platform-tools kentk$ 
tr3v3r commented 1 year ago

@nvdnvd00 Ok! Since your application works on tablets I suppose this is not a problem with the library for USB connections. What I can do: I'll add support for x86_64 arch for Android (which is missed right now) in an upcoming release ( I'll try to do it today ).

From your side: Please try to find what exactly happens when you try to discover on the Android side. Any errors/logs why you can not see the device. Also, double-check if all permissions are added according to the docs.

Also if its possible try to connect the printer with another connection type (Bluetooth, LAN )

jankoJelic commented 1 year ago

Hello, I can also not discover serial printer with "discover" on kiosk. I get empty array back as a response. Do you have any tips for those?

tr3v3r commented 1 year ago

@jankoJelic just released 2.3.0. Add support of x86_64 arch please try if it helps.

jankoJelic commented 1 year ago

Nah, still an empty array Code:

 useEffect(() => {
    const test = async () => {
      const printers = await EscPosPrinter.discover();
      console.log(printers);
    };

    test();
  }, []);

Logs: LOG requestAndroidPermissions true LOG enableLocationSetting true LOG []

jankoJelic commented 1 year ago

I may have solved mine and maybe someone else's problem. I could find and print with this library in this case: https://github.com/melihyarikkaya/react-native-serialport/

It might help you with improving your project.

I will try using serialport's port opening and your API for printing (which is great btw, nice job!) and let you know how it works

tr3v3r commented 1 year ago

Nah, still an empty array Code:

 useEffect(() => {
    const test = async () => {
      const printers = await EscPosPrinter.discover();
      console.log(printers);
    };

    test();
  }, []);

Logs: LOG requestAndroidPermissions true LOG enableLocationSetting true LOG []

Can I ask you to send me a logs from Android Studio logcat when you run discover method?

Rehankhalil462 commented 1 year ago

@tr3v3r after executing the following code , try { const printers = await EscPosPrinter.discover(); console.log("printers", printers); } catch (error) { console.log("Error:", error); }

getting the following console errors

requestAndroidPermissions false Error: No permissions granted

I am using Expo React Native in Dev Client. and added these "permissions": [ "android.permission.BLUETOOTH", "android.permission.BLUETOOTH_ADMIN", "android.permission.BLUETOOTH_CONNECT", "android.permission.BLUETOOTH_SCAN", "android.permission.INTERNET", "android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.READ_EXTERNAL_STORAGE", "android.permission.ACCESS_COARSE_LOCATION" ],

in app.json file.

Even if I request BLUETOOTH_CONNECT and BLUETOOTH_SCAN permissions using PermissionsAndroid from react native it is giving this response {"android.permission.BLUETOOTH_CONNECT": "never_ask_again", "android.permission.BLUETOOTH_SCAN": "never_ask_again"}.

can you please check what is the issue ?

tolypash commented 9 months ago

@tr3v3r I got the same issue where discover method does not resolve ever, on a special Android device, which has CPU: Quad-core Coretex-A53 1.8Ghz and ABI: armeabi-v7a

Apparently that CPU implements the Armv8-A architecture. How can we add support for it?

tr3v3r commented 9 months ago

According to official docs of the Android SDK:

image

You can also try to take a look at this manual https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/android_v2.27.0.pdf

Probably we missed something

tolypash commented 9 months ago

@tr3v3r What should I look for in adb logcat? Shall I share it with you?

tr3v3r commented 9 months ago

@tolypash you can try at least

tolypash commented 9 months ago

test.log

Here it is, any help is much appreciated. I also tried your new version, with the class based approach but it seems like it it’s the same, it just gets stuck and doesn’t resolve the promise at all of discovering

tr3v3r commented 9 months ago

@tolypash I can't see any info related to printer SDK in these logs.

Have you checked if the app has all the necessary permissions?

What type of connection you're using ? Bluetooth, WiFi, Lan Usb ?

btw with new discovery API there is no more promise. Instead you have event listener that will be listen for discovery updates during 5 sec (default). You can try to search it longer if needed by increasing timeout or desabling autoStop propery.

tolypash commented 9 months ago

We’re trying to get Bluetooth working.

Yes, I realised that about the new discovery API, but then again it still awaits on it and it doesn’t fire the event listener (meanwhile it does on iOS)

For Android I have Bluetooth permission on, we pair the printer in settings and then turn on the app. Also access location we have. Anything else I might be missing?

Also, this issue is specific on a special Android device for payments which doesn’t have Google play on it. Could this be an issue with location services? 🤔

tr3v3r commented 9 months ago

@tolypash it could be the reason yes Have you tried to log what this function returns for your case? https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/src/core/utils/permissions.ts

They both should give -> true

as I can see the second one (enableLocationAccessAndroid10) uses google services.

image

try manually to get rid of it in the node_modules/react-native-esc-pos-printer. ( just remove enableLocationAccessAndroid10 from the start discovery function on JS side )

tolypash commented 9 months ago

Okay thank you I will try those and get back to you 🙏

tolypash commented 9 months ago

@tr3v3r Thank you so much!! 🙏 That was the issue, the google services! I assume @nvdnvd00 had the same issue :)

tr3v3r commented 9 months ago

@tolypash happy to hear that!

If you're using version 3.0.1 I can create a fix for you, to make this permission check optional

tolypash commented 9 months ago

@tr3v3r Currently I have it patched for now, but if that will be possible will great, so I can also change it for devices that won't have Google services on them, by parameter 🙏

tr3v3r commented 9 months ago

ok anyway... I added a code to the Android side to skip enabling location settings if Google services are unavailable.

Here it is: https://github.com/tr3v3r/react-native-esc-pos-printer/releases/tag/vv3.0.2