From 9ad19c33d47f5d5e107b00f95d763ec0be3eb342 Mon Sep 17 00:00:00 2001 From: Francimar Alves Date: Fri, 18 Aug 2023 02:48:05 -0300 Subject: [PATCH] =?UTF-8?q?feat(code128):=20adicionado=20c=C3=B3digo=20de?= =?UTF-8?q?=20barras=20CODE=20128?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Thermal/Printer.php | 9 +++++---- src/Thermal/Profile/Daruma.php | 1 + src/Thermal/Profile/Diebold.php | 8 +++++++- src/Thermal/Profile/Epson.php | 7 ++++++- tests/Thermal/PrinterTest.php | 13 +++++++++++++ tests/Thermal/Profile/DarumaTest.php | 11 +++++++++++ tests/Thermal/Profile/DieboldTest.php | 11 +++++++++++ tests/resources/barcode_code128_IM453_Diebold.bin | Bin 0 -> 20 bytes tests/resources/barcode_code128_MP-4200_TH.bin | 1 + tests/resources/barcode_code128_daruma.bin | Bin 0 -> 20 bytes 10 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 tests/resources/barcode_code128_IM453_Diebold.bin create mode 100644 tests/resources/barcode_code128_MP-4200_TH.bin create mode 100644 tests/resources/barcode_code128_daruma.bin diff --git a/src/Thermal/Printer.php b/src/Thermal/Printer.php index 6ee95a3..55abf6f 100644 --- a/src/Thermal/Printer.php +++ b/src/Thermal/Printer.php @@ -21,10 +21,11 @@ class Printer const DRAWER_1 = 0; const DRAWER_2 = 1; - const BARCODE_UPC_A = 0; - const BARCODE_UPC_E = 1; - const BARCODE_EAN13 = 2; - const BARCODE_EAN8 = 3; + const BARCODE_UPC_A = 0; + const BARCODE_UPC_E = 1; + const BARCODE_EAN13 = 2; + const BARCODE_EAN8 = 3; + const BARCODE_CODE128 = 73; /** * Model diff --git a/src/Thermal/Profile/Daruma.php b/src/Thermal/Profile/Daruma.php index 2762e03..a30b3d7 100644 --- a/src/Thermal/Profile/Daruma.php +++ b/src/Thermal/Profile/Daruma.php @@ -93,6 +93,7 @@ public function barcode($data, $format) Printer::BARCODE_UPC_E => 8, Printer::BARCODE_EAN13 => 1, Printer::BARCODE_EAN8 => 2, + Printer::BARCODE_CODE128 => 5, ]; $new_format = $tipo[$format]; $this->getConnection()->write("\eb" . chr($new_format) . chr(2) . chr(50) . chr(0) . $data . chr(0)); diff --git a/src/Thermal/Profile/Diebold.php b/src/Thermal/Profile/Diebold.php index f44d732..ebd3390 100644 --- a/src/Thermal/Profile/Diebold.php +++ b/src/Thermal/Profile/Diebold.php @@ -19,9 +19,15 @@ public function barcode($data, $format) Printer::BARCODE_UPC_E => '8', Printer::BARCODE_EAN13 => '0', Printer::BARCODE_EAN8 => '4', + Printer::BARCODE_CODE128 => '3', ]; $new_format = $tipo[$format]; - $this->getConnection()->write("\e|" . $new_format . chr(50) . chr(0b00010010) . chr(0) . $data); + if ($format === Printer::BARCODE_CODE128) { + $len = strlen($data); + $this->getConnection()->write("\e|" . $new_format . chr(50) . chr(0b00010010) . chr(0) . chr($len) . $data); + } else { + $this->getConnection()->write("\e|" . $new_format . chr(50) . chr(0b00010010) . chr(0) . $data); + } } /** diff --git a/src/Thermal/Profile/Epson.php b/src/Thermal/Profile/Epson.php index 0d7cad7..3b94e09 100644 --- a/src/Thermal/Profile/Epson.php +++ b/src/Thermal/Profile/Epson.php @@ -120,7 +120,12 @@ public function drawer($number, $on_time, $off_time) public function barcode($data, $format) { - $this->getConnection()->write("\x1dk" . chr($format) . $data . chr(0)); + if ($format === Printer::BARCODE_CODE128) { + $len = strlen($data); + $this->getConnection()->write("\x1dk" . chr($format) . chr($len) . $data); + } else { + $this->getConnection()->write("\x1dk" . chr($format) . $data . chr(0)); + } } public function qrcode($data, $size) diff --git a/tests/Thermal/PrinterTest.php b/tests/Thermal/PrinterTest.php index d449847..8bbb0f1 100644 --- a/tests/Thermal/PrinterTest.php +++ b/tests/Thermal/PrinterTest.php @@ -131,6 +131,19 @@ public function testBarcode() ); } + public function testBarcodeCode128() + { + $this->connection->clear(); + $this->printer->setAlignment(Printer::ALIGN_CENTER); + $this->printer->barcode('0123456789101', Printer::BARCODE_CODE128); + $this->printer->setAlignment(Printer::ALIGN_LEFT); + + $this->assertEquals( + self::getExpectedBuffer('barcode_code128_MP-4200_TH', $this->connection->getBuffer()), + $this->connection->getBuffer() + ); + } + public function testQrcode() { $this->connection->clear(); diff --git a/tests/Thermal/Profile/DarumaTest.php b/tests/Thermal/Profile/DarumaTest.php index 15f0e33..dcf4cad 100644 --- a/tests/Thermal/Profile/DarumaTest.php +++ b/tests/Thermal/Profile/DarumaTest.php @@ -106,6 +106,17 @@ public function testBarcode() ); } + public function testBarcodeCode128() + { + $this->connection->clear(); + $profile = $this->model->getProfile(); + $profile->barcode('0123456789101', Printer::BARCODE_CODE128); + $this->assertEquals( + PrinterTest::getExpectedBuffer('barcode_code128_daruma', $this->connection->getBuffer()), + $this->connection->getBuffer() + ); + } + public function testQrcode() { $this->connection->clear(); diff --git a/tests/Thermal/Profile/DieboldTest.php b/tests/Thermal/Profile/DieboldTest.php index c3f5a51..66749f7 100644 --- a/tests/Thermal/Profile/DieboldTest.php +++ b/tests/Thermal/Profile/DieboldTest.php @@ -48,6 +48,17 @@ public function testBarcode() ); } + public function testBarcodeCode128() + { + $this->connection->clear(); + $profile = $this->model->getProfile(); + $profile->barcode('0123456789101', Printer::BARCODE_CODE128); + $this->assertEquals( + PrinterTest::getExpectedBuffer('barcode_code128_IM453_Diebold', $this->connection->getBuffer()), + $this->connection->getBuffer() + ); + } + public function testDrawer() { $this->connection->clear(); diff --git a/tests/resources/barcode_code128_IM453_Diebold.bin b/tests/resources/barcode_code128_IM453_Diebold.bin new file mode 100644 index 0000000000000000000000000000000000000000..87896982998854ca2db068dd7eb1d7838a0daa13 GIT binary patch literal 20 bcmb2HF*Xun;59HbGBz