charlieuki / receipt-printer-example

Example usage of Laravel package to integrate ECS/POS Print Driver for PHP
24 stars 15 forks source link

Does this have pulse() method to open cash drawer same as on mike42/escpos-php? #10

Open jumarjuaton opened 3 years ago

jumarjuaton commented 3 years ago

Hello,

I was testing out the cash drawer, and using pulse() method in mike42/escpos-php works fine? I just followed this:

Does your package have something like this too?

charlieuki commented 3 years ago

Hi there. This package does not have that at the moment, but I am planning to add it soon because there are several requests about that recently.

jumarjuaton commented 3 years ago

I see, I guess to have to use mike42/escpos-php for now. Thank you @charlieuki

jumarjuaton commented 3 years ago

As a temporary solution, here's the code someone can use in Laravel with mike42/escpos-php (with pulse() method).

Note: This is for Windows connector only. This only serves as basis. Don't forget to install the package on your project first.

composer require mike42/escpos-php

Controller:

<?php

namespace App\Http\Controllers;

use App\Http\Controllers;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
use Mike42\Escpos\Printer;

class PrinterController extends Controller
{
    public function test()
    {
        try{ 
            $connector = new WindowsPrintConnector("Printer-Name-Here");
            $printer = new Printer($connector);
            $printer->text("Hello World!\n");
            $printer->cut();
            $printer->pulse();
            $printer->pulse(1);
            $printer->pulse(0, 100, 100);
            $printer->pulse(0, 300, 300);
            $printer->pulse(1, 100, 100);
            $printer->pulse(1, 300, 300);
            $printer->close();
        } catch (Exception $e) {
            echo "Couldn't print to this printer: " . $e -> getMessage() . "\n";
        }
    }
}