我试图打印一个QR代码与我的爱普生TM-T88IV系列打印机使用php。但是,我的php文件安装在服务器上,我可以从html文件成功地调用它。我正在使用一个名为ESCPOS-PHP (https://github.com/mike42/escpos-php)的库,计算机正在运行Windows。下面是我的php代码片段(中间还有更多,但打印操作不需要):
<?php
require __DIR__. '/escpos-php-master/Escpos.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
[...]
try {
$connector = new WindowsPrintConnector("EPSON TM-T88IV Receipt");
$printer = new Escpos($connector);
$printer -> text("Hello World!\n");
$printer -> cut();
// Close printer
$printer -> close();
} catch(Exception $e) {
echo "Couldn't print to this printer: " . $e -> getMessage() . "\n";
}
?>好像我连不上打印机了。我也试过
$connector = new FilePrintConnector("/dev/ttyS0");
$printer = new Printer($connector);这应该是串行打印机的方式(我不确定应该放什么,而不是“/dev/ttsyS0 0”)。也许我不应该尝试通过服务器触发它?我这么做是因为我不能修改他的POS系统(Maitre D),而且我需要一种简单的方法在钞票上打印QR代码。如果你知道任何工作环境,任何建议都将不胜感激!谢谢
发布于 2016-09-10 08:55:52
这里是escpos的作者。
escpos自述建议您首先尝试将数据发送到命令行上的打印机,因为它将允许您在尝试使用驱动程序之前确定如何打印。
例如,如果您打算在COM1上设置打印机,可以尝试键入:
echo "Hello world" > COM1对应于:
<?php
$connector = new FilePrintConnector("COM1");
$printer = new Escpos($connector);
$printer -> text("Hello World\n");WindowsPrintConnector用于连接到Windows共享打印机。这个例子有一些有用的命令来确保在打开PHP之前可以打印。例如,
echo "Hello world" > foo.txt
net use "\\computername\Receipt Printer" /user:Bob secret
copy testfile "\\computername\Receipt Printer"
del testfile这相当于:
<?php
$connector = new WindowsPrintConnector("smb://bob:secret@computername/Receipt Printer");
$printer = new Escpos($connector);
$printer -> text("Hello World\n");无论如何,有两个问题:
https://stackoverflow.com/questions/36893074
复制相似问题