2016-04-27 81 views
0

我试图用我的爱普生TM-T88IV串行打印机使用php打印QR码。然而,我的PHP文件安装在服务器上,我可以从HTML文件成功地调用它。我正在使用名为ESCPOS-PHP(https://github.com/mike42/escpos-php)的库,并且计算机正在运行Windows XP Professional。这里是我的PHP代码段(还有更多的在中间,但不需要打印动作):Escpos-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”来代替)。也许我不应该试图通过服务器触发它?我这样做是因为我无法修改他的POS系统(Maitre D),我需要一种简单的方法在账单上打印QR码。如果你知道任何workaroung,任何意见将不胜感激!谢谢

+0

从什么时候Windows XP有'/ dev/ttyS0'?这是一个unix主义。 –

+0

我刚刚从github自述文件中给出的信息中,我知道我必须放些别的东西,但我不知道究竟是什么。 –

回答

1

escpos-php的作者在这里。

escpos-php README建议您应该尝试首先在命令行上将数据发送到您的打印机,因为它可以让您在尝试使用该驱动程序之前确定如何打印。

例如,如果您打算设置在COM1您的打印机,你可以尝试键入:

echo "Hello world" > COM1 

与对应:

<?php 
$connector = new FilePrintConnector("COM1"); 
$printer = new Escpos($connector); 
$printer -> text("Hello World\n"); 

的WindowsPrintConnector是用于连接到Windows共享打印机。 This example有一些有用的命令来确保您可以在打开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:[email protected]/Receipt Printer"); 
$printer = new Escpos($connector); 
$printer -> text("Hello World\n"); 

在任何情况下,两个陷阱:

  • 只有通用/文本仅驱动程序使用。 escpos-php会输出原始的ESC/POS,这会混淆任何期望文档的驱动程序。
  • 这是服务器端。确保PHP正在执行打印的计算机上运行,​​或者如果使用网络打印,您至少位于内部网络上。
+0

计算机是我的本地主机名还是活的服务器主机名? –

+0

@MuhammadUsman - 在局域网上共享打印机的计算机 – mike42

+0

可以是USB连接的打印机吗? –