Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow usb connections via auto-detection #7

Merged
merged 6 commits into from
Aug 26, 2024
Merged

Conversation

vicary
Copy link
Owner

@vicary vicary commented Aug 21, 2024

Fixes #6

@HatalDev Not sure if emulators can proxy through USB connections, but we are good with emulator tests without actual devices if USB works.

You may run the example app for test prints using the commands below, it would be really kind of you to also attach photos for test prints!

Installation

yarn

cd examples/PrinterTestApp

# Start metro server
yarn start

Android

# Test Android old arch
yarn and:old

# Clear previous builds to change arch
yarn and:clean

# Test Android new arch
yarn and:new

iOS

# Test iOS old arch
yarn ios:old

# Clear previous builds to change arch
yarn ios:clean

# Test iOS new arch
yarn ios:new

@HatalDev
Copy link

@vicary can you upgrade the Gradle to the latest version?
beside that there is any way to install the package with your latest changes to existing project using yarn/npm?

@vicary
Copy link
Owner Author

vicary commented Aug 21, 2024

Usually you don't need to upgrade the gradle version of the plugin, for the example app you may simply edit the line below to your desired version and rebuild.

distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip

The example app has workspace deps, it's the best way to install without publishing. You may try installing the locally built plugin via yarn link or npm link, but you are likely to hit an error saying that the linked version of react and react-native being different with those in your app. It's really a rabbit hole to dedupe symlink dependencies so I don't recommend this unless you do this a lot.

@HatalDev
Copy link

HatalDev commented Aug 22, 2024

@vicary Hi, when I run yarn and:old the application works but when I press search printers, I get an error "Attempt to invoke virtual method 'double java.lang.Double.doubleValue()' on a null object reference" (both on simulator and on physical device, connected to the printer). when running yarn and:new the build fails and I get an error

1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':react-native-citizen-escposprinter:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

and also

2: Task failed with an exception.
-----------
* What went wrong:
java.lang.StackOverflowError (no error message)

@vicary
Copy link
Owner Author

vicary commented Aug 22, 2024

@HatalDev USB shouldn't need to use the search function, you may have to change the code a bit and call connect() with the USB constant directly.

I'll take a look at the function bindings in the mean time, there maybe a mismatched argument type on the native layer.

@HatalDev
Copy link

HatalDev commented Aug 22, 2024

@vicary I tried setting just one Pressable to use the connect function.

<Pressable
  className="bg-gray-200 active:bg-gray-300 active:opacity-50 rounded-xl"
  onPress={async () => {
    try {
      await connect(ESCPOSConst.CMP_PORT_USB);
    } catch (err) { }
  }}>
</Pressable>

I get an error
Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter address

When I try to provide a string as an address, I get an error saying it's not supported for USB connection.

@vicary

This comment was marked as outdated.

@vicary
Copy link
Owner Author

vicary commented Aug 22, 2024

I can build both archs after fixing the optional parameter binding, I cannot reproduce the error when running printer search though.

A new button is added to the example app for easier USB tests.

Screen.Recording.2024-08-22.at.22.21.08.mov

@vicary vicary changed the title feat: allow usb connections via auto-detection (#6) feat: allow usb connections via auto-detection Aug 22, 2024
@HatalDev
Copy link

@vicary I've downloaded the latest version, when trying to build I'm getting the following error
`Execution failed for task ':react-native-citizen-escposprinter:compileDebugKotlin'.

A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction`

it's because of the connect function in the CitizenEscposprinterModule.kt file, when removing the question mark from the address string, the app builds, and when clicking on connect printer the same error of
Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter address
is still happening

@vicary
Copy link
Owner Author

vicary commented Aug 26, 2024

@HatalDev I should also update CitizenEscposprinterSpec.kt to match the function signature, pushed again to allow null addresses for USB.

@HatalDev
Copy link

@vicary I'm very happy to confirm that the usb printing is working perfectly now, do you need any further help in order to publish it to the main branch, and update the npm package?

@vicary
Copy link
Owner Author

vicary commented Aug 26, 2024

A verbal confirmation that you have tested all 4 environments would be enough, I would otherwise document the untested items. Then we are good to go!

@HatalDev
Copy link

@vicary I can confirm that both environments of android are working, currently I can't verify it on iOS, but I believe I could do this in couple of days, maybe we can continue with the android for now, as it working exactly as it should.

@vicary
Copy link
Owner Author

vicary commented Aug 26, 2024

I'll add a temporary warning section in the README and release it tomorrow.

You may continue commenting in this PR, I'll remove the section if it turns out working!

@vicary vicary merged commit 38b9d82 into main Aug 26, 2024
3 checks passed
@vicary vicary deleted the feat/usb-connect branch August 26, 2024 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

USB support
2 participants