bluetooth-terminal icon indicating copy to clipboard operation
bluetooth-terminal copied to clipboard

Support printers?

Open Artur- opened this issue 3 years ago • 4 comments

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?

Artur- avatar Apr 05 '21 10:04 Artur-

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?

loginov-rocks avatar Apr 05 '21 16:04 loginov-rocks

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 https://github.com/Artur-/bluetooth-terminal/commit/24d36f967032cde937e5a7e160be45a1a038c887 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 https://github.com/Artur-/bluetooth-terminal/commit/82e0817e2e1ed96364b29977cfe5bd722c292e12 but did not have time to even test it yet

Artur- avatar Apr 05 '21 18:04 Artur-

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.

loginov-rocks avatar Apr 06 '21 11:04 loginov-rocks

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

Artur- avatar Apr 06 '21 13:04 Artur-