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

buzzer integrated #525

Open
fabry84 opened this issue Jun 2, 2024 · 2 comments
Open

buzzer integrated #525

fabry84 opened this issue Jun 2, 2024 · 2 comments

Comments

@fabry84
Copy link

fabry84 commented Jun 2, 2024

Hi, congratulations, your project also works very well with Italian printers. Can I ask you if you have also planned to activate the buzzer integrated into the printers when cutting the paper? or is it possible to send escpos commands directly to the printer?

Thank you

@fabry84
Copy link
Author

fabry84 commented Jun 15, 2024

Hi Dantsu, could you give me some help? I found the code for the internal buzzer, but when I send it I get an error. I attach the code and error, what am I doing wrong?
Thank you
TcpConnection printerConnection = new TcpConnection("192.168.1.151",9100);
printerConnection.write(new byte[]{0x1b,0x42,0x02,0x01});
printerConnection.send(1);

The error is in the line printerConnection.send(1);

Caused by: com.dantsu.escposprinter.exceptions.EscPosConnectionException: Unable to send data to device.

@kelalaka153
Copy link

To send the commands, you need to make the printerConnection public, then you can send commands easily; For example, the below can be used to turn the printer into paging mode, and auto-feed to the next page on reset.

class HME300PrinterCommands(
    printerConnection : DeviceConnection,
    charsetEncoding : EscPosCharsetEncoding
) :
    EscPosPrinterCommands(
        printerConnection,
        charsetEncoding)
{
    /**
     * Reset printers parameters.
     */
    override fun reset(): EscPosPrinterCommands {
        if (printerConnection.isConnected) {
            return this
        }
        super.reset()
        // ACTIVE HERE PAGE MODE AND DIRECTION
        printerConnection.write(HME300PrinterCommands.ENABLE_PAGE_MODE)
        printerConnection.write(HME300PrinterCommands.PAGE_MODE_DIRECTION)
        printerConnection.send(100)
        return this
    }

    override fun disconnect() {
        newpage()
        super.disconnect()
    }

    override fun cutPaper(): EscPosPrinterCommands {
        return super.cutPaper()
    }

    private fun newpage() {
        printerConnection.write(HME300PrinterCommands.PRINT_AND_FEED)
        printerConnection.send(100)
    }

    companion object {
        val ENABLE_PAGE_MODE: ByteArray = byteArrayOf(0x1B, 0x4C)
        val PAGE_MODE_DIRECTION: ByteArray = byteArrayOf(0x1B, 0x54, 0x00)
        val PRINT_AND_FEED: ByteArray = byteArrayOf(0x0C)
    }
}

To use it, you need to construct the EscPosPrinter as

 val printer = EscPosPrinter(

                        HME300PrinterCommands(
                            printerIsFound as DeviceConnection,
                            EscPosCharsetEncoding("windows-1256", 16)),
                        203,
                        72f,
                        42,

                    )
``

Hope helps

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

No branches or pull requests

2 participants