bluetooth-terminal
bluetooth-terminal copied to clipboard
Support printers?
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:
- You assume that the device supports notifications but this is not true for my test printer
characteristic.properties.notify
isfalse
so anyconnect()
attempt will fail - You assume that I want to send a
string
encoded using aTextEncoder
but the printer wants something encoded using aEscPosEncoder
. As you have implementedsend
aspublic 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?
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?
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
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.
Go ahead. I used the TS version and made some small fixes there also