d3yii2/d3printer

此包的最新版本(dev-main)没有可用的许可信息。

打印机监控

dev-main 2024-09-04 06:27 UTC

This package is auto-updated.

Last update: 2024-09-04 06:27:29 UTC


README

Yii2

打印机监控"

功能

安装

安装此扩展的首选方式是通过composer

可以运行

$ composer require d3yii2/d3printer "*"

或者添加到 composer require 部分

"d3yii2/d3printer": "*"

打印机定义为由组件组成

为每种类型的打印机创建自己的类。例如,参见 components/D3PrinterGodex5000.php

标签

标签作为对象创建。例如

namespace components\printers;

use d3yii2\d3printer\components\G500LabelBase;
use d3yii2\d3printer\components\G500LabelInterface;
use Dbr\Ezpl\Builder;
use Dbr\Ezpl\Command\CommandPipe;
use Dbr\Ezpl\Command\Image\QRCode;

class G500ProductLabel extends G500LabelBase implements G500LabelInterface
{
    /** @var string */
    public $qrCode;

    /** @var $date */
    public $date;

    /** @var float */
    public $qnt;

    /** @var string */
    public $unitLabel;

    /** @var string */
    public $productName;

    public function createCommand(): Builder
    {
        return (new Builder(new CommandPipe()))
            ->resetMemory()
            ->setLabelHeight($this->labelHeight, 2)
            ->setLabelWidth($this->labelWidth)
            ->setDensity($this->density)
            ->copies($this->copies)
            ->labelStart()
            ->qrcode($this->createQrCode())
            ->text(14, 250, 10, 1, 1, 0, 0, $this->date)
            ->text(18, 250, 70, 1, 1, 0, 0, $this->qnt . ' ' . $this->unitLabel)
            ->text(10, 250, 200, 1, 1, 0, 0, $this->qrCode)
            ->text(14, 10, 260, 1, 1, 0, 0, $this->productName)
            ->labelEnd();
    }

    public function createQrCode(): QRCode
    {
        return (new QRCode($this->qrCode))
            ->setHorizontal(10)
            ->setVertical(10)
            ->setInputMode(QRCode::INPUT_MODE_MIXING)
            ->setType(QRCode::TYPE_ORIGINAL)
            ->setErrorLevel(QRCode::ERROR_CORRECTION_MEDIUM)
            ->setMaskingFactor(QRCode::MASKING_AUTO)
            ->setMultiple(10)
            ->setRotate(0);
    }
}

使用方法

require('../../../../autoload.php');
require('../../../../yiisoft/yii2/Yii.php');

use aluksne\app\components\printers\G500ProductLabel;
use d3yii2\d3printer\components\D3PrinterGodex5000;

$label = Yii::createObject([
    'class' => G500ProductLabel::class,
    'productName' => 'CLT60 C 3(20-20-20)V/V/5000/7000',
    'qrCode' => 'P100022342',
    'date' => '2021-09-20',
    'qnt' => 11.,
    'unitLabel' => 'M3',
]);

$printer = Yii::createObject([
    'class' => D3PrinterGodex5000::class,
    'printerIp' => '192.168.88.228',
]);

$printer->check();

echo $printer->getCheckResponseCode() . PHP_EOL;
echo $printer->getCheckResponseLabel() . PHP_EOL;

$printer->print($label);

健康监控

在 app 控制台配置中定义健康组件

    'kaltePrinterHealth' => [
            'class' => '\d3yii2\d3printer\components\D3Printer',
            'printerCode' => 'officePrinter',
            'printerName' => 'Godex G500',
            'accessSettings' => [
                'home_url' => '<printer home URL>',
            ],
        ],

读取并保存当前状态(文件位于 [app 路径]/runtime/d3printer/[printerCode]

     /usr/bin/php <sitepath>/yii d3printer/health-cron <printerCode>

在 app 主要配置中定义打印机状态面板

'panels' => [
    'printers' =>
        [
            [
                'route' => '/d3printer/info-panel/status',
                'params' => [
                    'printerComponent' => 'officePrinter',
                    'healthComponent' => 'officePrinterHealth',
                ]
            ],
            [
                'route' => '/d3printer/info-panel/status',
                'params' => [
                    'printerComponent' => 'homePrinter',
                    'healthComponent' => 'homePrinterHealth',
                ]
            ],

在 app 视图中显示状态面板

PanelWidget::widget(['name' => 'printers'])

示例

通过打印机代码获取打印机状态、墨盒和鼓

 $printerComponent = D3Printer::getPrinterComponent('officePrinter');
 $deviceHealth = $printerComponent->deviceHealth();

 $status = $deviceHealth->getStatus();
 $cartridgeRemaining = $deviceHealth->getCartridgeRemaining();
 $drumRemaining = $deviceHealth->getDrumRemaining();