NielsLeenheer / ThermalPrinterStatus

Get status information back from StarPrint and ESC/POS printers
MIT License
0 stars 0 forks source link

Cash Drawer Closed #1

Open jogibear9988 opened 1 week ago

jogibear9988 commented 1 week ago

As you can use pulse to open a Cash Drawer, I'm curious, is there normally a signal back from the cash drawer to the printer when it is closed? And if so, is there a way to read this back with your lib? (maybe this is the wrong repo and it is task of the WebBluetoothPrinter lib (or usb))

jogibear9988 commented 1 week ago

I programmed a simple cassier software and wanted to clear the bookings when the cash drawer is closed (https://github.com/jogibear9988/festKasse)

NielsLeenheer commented 1 week ago

Right now this is not possible with these libraries. WebBluetoothPrinter, WebSerialPrinter and WebUSBPrinter are currently one way. They can send data to the printer but not receive data. It would be interesting to add this though.

Adding support for getting the state of cash drawer would probably out of scope for this library as this is really focused on generating ESC/POS or StarPrint commands independently from how it is send to the printer. But perhaps a specific Cashdrawer library that can connect to WebBluetoothPrinter and others would be helpful.

jogibear9988 commented 1 week ago

I'm looking what I can add here...

found this: https://stackoverflow.com/questions/39771971/detect-if-is-cash-drawer-open-with-esc-command

jogibear9988 commented 1 week ago

from where did you get this info:

    const DeviceProfiles = [

        /* Zjiang ZJ-5805 */
        {
            filters: [
                { services: [ '000018f0-0000-1000-8000-00805f9b34fb' ] }
            ],

            service:            '000018f0-0000-1000-8000-00805f9b34fb',
            characteristic:     '00002af1-0000-1000-8000-00805f9b34fb',

            language:           'esc-pos',
            codepageMapping:    'zjiang'
        }
    ]

i think I need another characteristic's id for the status...

jogibear9988 commented 1 week ago

I tried device.getCharacteristics()...

got another one... but got no 'characteristicvaluechanged' event... still trying :-)

jogibear9988 commented 1 week ago

I'm not sure if my printer supports reading back of the cash drawer state at all...

I found the printer has only two characteristics (when i use getCharacteristics()) and both throw an exception when I use readValue(9 on them. And also if I changed your writeValue to writeValueWithResponse() it also always returns "undefined", so I'm not sure if I could read anything from the printer...

(But I think you should at least switch to writeValueWithoutResponse, as writeValue is deprecated, see: https://developer.mozilla.org/en-US/docs/Web/API/BluetoothRemoteGATTCharacteristic/writeValue)

NielsLeenheer commented 6 days ago

What model of printer are you using?

jogibear9988 commented 6 days ago

I've this one: https://www.kaufland.de/product/465105482/

NielsLeenheer commented 6 days ago

Ok, it looks it's a printer from China with pretty common firmware. I've got a similar one but it is not Bluetooth enabled. And the Bluetooth printer I have does not have support for cash drawers and uses different firmware. So I've ordered one so I do some tests.

In any case it could be a myriad of reasons why it does not work. It could be the wrong characteristic. It could be the printer does not support two way communication when using BT. Or not at all. Or maybe it does not support reporting back the printer status. Or it uses a different command to send back the status. I'll try to find out a bit more.

jogibear9988 commented 6 days ago

It also supports USB. Maybe I'll try this and look if it supported there.

Do you know a existing software wich supports such printers? Wich I could use to look if the status is supported there.

I tried both characteristics wich the printer reported in chrome. But I started WebBluetooth at first when I created this issue, so I could have done wrong everything.

NielsLeenheer commented 6 days ago

I did some tests with a USB printer that uses very similar firmware, and it does support polling for the printer status and the ASB feature for getting realtime status information from the printer. So for USB it should be possible - and once I get the same printer that you use, I could also check if it works with Bluetooth.

NielsLeenheer commented 3 days ago

Moved this issue to the new repository for ThermalPrinterStatus, a library specifically for detecting the status of receipt printers. For now it only works with printers connected using WebUSBReceiptPrinter. In time I will also add support for WebBluetoothReceiptPrinter and WebSerialReceiptPrinter.