mirror of
https://github.com/python-escpos/python-escpos
synced 2025-08-24 09:03:34 +00:00
Feature(escpos) Add buzzer function (#535)
* Add buzzer function * Add `buzzer(time, duration)` function to control the buzzer on supported printers. * Add unit tests for buzzer function. * Update test_function_buzzer.py to pass black * Run black in tests files --------- Co-authored-by: Patrick Kanzler <dev@pkanzler.de>
This commit is contained in:
@@ -63,6 +63,9 @@ PAPER_PART_CUT = _CUT_PAPER(b"\x01") #: Partial cut paper
|
||||
# Beep (please note that the actual beep sequence may differ between devices)
|
||||
BEEP = b"\x07"
|
||||
|
||||
# Internal buzzer (only supported printers)
|
||||
BUZZER = ESC + b"\x42"
|
||||
|
||||
# Panel buttons (e.g. the FEED button)
|
||||
_PANEL_BUTTON = lambda n: ESC + b"c5" + six.int2byte(n)
|
||||
PANEL_BUTTON_ON = _PANEL_BUTTON(0) # enable all panel buttons
|
||||
|
@@ -58,6 +58,7 @@ from .constants import (
|
||||
CD_KICK_2,
|
||||
PAPER_FULL_CUT,
|
||||
PAPER_PART_CUT,
|
||||
BUZZER,
|
||||
)
|
||||
from .constants import HW_RESET, HW_SELECT, HW_INIT
|
||||
from .constants import (
|
||||
@@ -1243,6 +1244,24 @@ class Escpos(object):
|
||||
"""
|
||||
self._raw(SLIP_SELECT)
|
||||
|
||||
def buzzer(self, times=2, duration=4):
|
||||
"""Activate the internal printer buzzer (only supported printers).
|
||||
|
||||
The 'times' parameter refers to the 'n' escpos command parameter,
|
||||
which means how many times the buzzer will be 'beeped'.
|
||||
|
||||
:param times: Integer between 1 and 9, indicates the buzzer beeps.
|
||||
:param duration: Integer between 1 and 9, indicates the beep duration.
|
||||
:returns: None
|
||||
"""
|
||||
|
||||
if not 1 <= times <= 9:
|
||||
raise ValueError("times must be between 1 and 9")
|
||||
if not 1 <= duration <= 9:
|
||||
raise ValueError("duration must be between 1 and 9")
|
||||
|
||||
self._raw(BUZZER + six.int2byte(times) + six.int2byte(duration))
|
||||
|
||||
|
||||
class EscposIO(object):
|
||||
"""ESC/POS Printer IO object
|
||||
|
Reference in New Issue
Block a user