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

Added cut and eject for printer with eject #1241

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Mike42/Escpos/PrintConnectors/CupsPrintConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function __construct($dest)
public function __destruct()
{
if ($this->buffer !== null) {
trigger_error("Print connector was not finalized. Did you forget to close the printer?", E_USER_NOTICE);
throw new Exception("Print connector was not finalized. Did you forget to close the printer?");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Mike42/Escpos/PrintConnectors/DummyPrintConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function clear()
public function __destruct()
{
if ($this -> buffer !== null) {
trigger_error("Print connector was not finalized. Did you forget to close the printer?", E_USER_NOTICE);
throw new Exception("Print connector was not finalized. Did you forget to close the printer?");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Mike42/Escpos/PrintConnectors/FilePrintConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct($filename)
public function __destruct()
{
if ($this -> fp !== false) {
trigger_error("Print connector was not finalized. Did you forget to close the printer?", E_USER_NOTICE);
throw new Exception("Print connector was not finalized. Did you forget to close the printer?");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Mike42/Escpos/PrintConnectors/RawbtPrintConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function clear()
public function __destruct()
{
if ($this->buffer !== null) {
trigger_error("Print connector was not finalized. Did you forget to close the printer?", E_USER_NOTICE);
throw new Exception("Print connector was not finalized. Did you forget to close the printer?");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function __construct($dest)
public function __destruct()
{
if ($this -> buffer !== null) {
trigger_error("Print connector was not finalized. Did you forget to close the printer?", E_USER_NOTICE);
throw new Exception("Print connector was not finalized. Did you forget to close the printer?");
}
}

Expand Down
49 changes: 45 additions & 4 deletions src/Mike42/Escpos/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ class Printer
*/
const EOT = "\x04";

/**
* ASCII Enquiry control character
*/
const ENQ = "\x05";

/**
* ASCII end of text control character
*/
const ETX = "\x03";

/**
* Indicates UPC-A barcode when used with Printer::barcode
*/
Expand Down Expand Up @@ -146,6 +156,16 @@ class Printer
*/
const CUT_PARTIAL = 66;

/**
* Make a total cut and completely eject sheet (eg. on VKP80III Custom printer), when used with Printer::cut
*/
const CUT_FULL_EJECT = 67;

/**
* Make a total cut and partial eject sheet (eg. on VKP80III Custom printer), when used with Printer::cut
*/
const CUT_FULL_PARTIAL_EJECT = 68;

/**
* Use Font A, when used with Printer::setFont
*/
Expand Down Expand Up @@ -511,7 +531,20 @@ public function close()
public function cut(int $mode = Printer::CUT_FULL, int $lines = 3)
{
// TODO validation on cut() inputs
$this -> connector -> write(self::GS . "V" . chr($mode) . chr($lines));
switch ($mode) {
case Printer::CUT_FULL:
case Printer::CUT_PARTIAL:
$this -> connector -> write(self::GS . "V" . chr($mode) . chr($lines));
break;
case Printer::CUT_FULL_EJECT:
$this -> connector -> write(self::GS . chr(101) . self::ENQ);
break;
case Printer::CUT_FULL_PARTIAL_EJECT:
$this -> connector -> write(self::GS . "e" . self::ETX . self::FF);
break;
default;
break;
}
}

/**
Expand All @@ -538,6 +571,14 @@ public function feedForm()
$this -> connector -> write(self::FF);
}

/**
* Emit a sound with a internal buzzer
*/
public function buzzer()
{
$this->connector->write(PRINTER::FS . "\xc0" . "\x07");
}

/**
* Some slip printers require `ESC q` sequence to release the paper.
*/
Expand Down Expand Up @@ -704,7 +745,7 @@ public function pulse(int $pin = 0, int $on_ms = 120, int $off_ms = 240)
* @param int $size Pixel size to use. Must be 1-16 (default 3)
* @param int $model QR code model to use. Must be one of Printer::QR_MODEL_1, Printer::QR_MODEL_2 (default) or Printer::QR_MICRO (not supported by all printers).
*/
public function qrCode(string $content, int $ec = Printer::QR_ECLEVEL_L, int$size = 3, int $model = Printer::QR_MODEL_2)
public function qrCode(string $content, int $ec = Printer::QR_ECLEVEL_L, int $size = 3, int $model = Printer::QR_MODEL_2)
{
self::validateInteger($ec, 0, 3, __FUNCTION__);
self::validateInteger($size, 1, 16, __FUNCTION__);
Expand Down Expand Up @@ -1035,7 +1076,7 @@ public function textRaw(string $str = "")
* @param string $m Modifier/variant for function. Often '0' where used.
* @throws InvalidArgumentException Where the input lengths are bad.
*/
protected function wrapperSend2dCodeData(string $fn, string $cn, string$data = '', string $m = '')
protected function wrapperSend2dCodeData(string $fn, string $cn, string $data = '', string $m = '')
{
if (strlen($m) > 1 || strlen($cn) != 1 || strlen($fn) != 1) {
throw new InvalidArgumentException("wrapperSend2dCodeData: cn and fn must be one character each.");
Expand All @@ -1052,7 +1093,7 @@ protected function wrapperSend2dCodeData(string $fn, string $cn, string$data = '
* @param string $data Data to send.
* @throws InvalidArgumentException Where the input lengths are bad.
*/
protected function wrapperSendGraphicsData(string $m, string $fn, string$data = '')
protected function wrapperSendGraphicsData(string $m, string $fn, string $data = '')
{
if (strlen($m) != 1 || strlen($fn) != 1) {
throw new InvalidArgumentException("wrapperSendGraphicsData: m and fn must be one character each.");
Expand Down