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

Support printers? #67

Open
Artur- opened this issue Apr 5, 2021 · 4 comments
Open

Support printers? #67

Artur- opened this issue Apr 5, 2021 · 4 comments
Assignees

Comments

@Artur-
Copy link

Artur- commented Apr 5, 2021

Hi,

I was experimenting with web bluetooth with a thermal printer and tried using your nice lib instead of rewriting the same thing myself. This mostly worked out except for two things:

  1. You assume that the device supports notifications but this is not true for my test printer characteristic.properties.notify is false so any connect() attempt will fail
  2. You assume that I want to send a string encoded using a TextEncoder but the printer wants something encoded using a EscPosEncoder. As you have implemented send as public send(data: string): Promise<void> I had to rewrite that part including chunk splitting.

Would you be interesting in incorporating something for this or should i just keep it in a fork?

@loginov-rocks loginov-rocks self-assigned this Apr 5, 2021
@loginov-rocks
Copy link
Owner

Hi @Artur- ,

Thanks for commenting on your findings!

You assume that the device supports notifications but this is not true for my test printer characteristic.properties.notify is false so any connect() attempt will fail

The library purpose is to establish serial communication, and the basis for that is the notifications mechanism, so how would you implement it differently?

You assume that I want to send a string encoded using a TextEncoder but the printer wants something encoded using a EscPosEncoder. As you have implemented send as public send(data: string): Promise I had to rewrite that part including chunk splitting.

As I get it is that send() is an abstraction you'd like to avoid? Would exposing something like sendRaw() help?

@Artur-
Copy link
Author

Artur- commented Apr 5, 2021

The library purpose is to establish serial communication, and the basis for that is the notifications mechanism, so how would you implement it differently?

I know I am (ab)using the project for the wrong thing as a basic thermal printer does not use bidirectional communications thus there is no need to get notifications, you only need to send data to the printer. I was really looking for some kind of helper library for web bluetooth and this was the closest I found on https://www.npmjs.com/. What I did was this Artur-@24d36f9 i.e. just do not call startNotifications is the device does not support it.

As I get it is that send() is an abstraction you'd like to avoid? Would exposing something like sendRaw() help?

Yes, I actually implemented a sendRaw helper here Artur-@82e0817 but did not have time to even test it yet

@loginov-rocks
Copy link
Owner

Hi @Artur- ,

Now I get it! Well, do you mind if I leave this issue open? As soon as get back to the project (want to rewrite on TS) I think on how to include that & test.

@Artur-
Copy link
Author

Artur- commented Apr 6, 2021

Go ahead. I used the TS version and made some small fixes there also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants