我需要使用Carrier Return和Line Feed打印DataMatrix。 我的打印机是Zebra GK420t。 我在Zebra Designer中制作标签,当从Zebra Designer打印标签时CR和LF有效,但是当我将标签导出到PRN文件时,要用PHP打印,CR和LF无法正常工作。
PHP代码
<?php
class ZebraBarcode {
var $host = "";
var $port = "";
var $error = "";
var $prn = "";
function __construct($host,$port) {
$this->host = $host;
$this->port = $port;
$this->prn = "CT~~CD,~CC^~CT~
^XA~TA000~JSN^LT0^MNW^MTT^PON^PMN^LH0,0^JMA^PR2,2~SD30^JUS^LRN^CI0^XZ
^XA
^MMT
^PW799
^LL0400
^LS0
^FO4,4^GB795,396,8^FS
^FO5,197^GB794,101,8^FS
^FT642,236^A0N,25,26^FH\^FDCANTIDAD^FS
^FT275,67^A0N,37,52^FH\^FDMEMORIA GRABADA^FS
^FT587,328^A0N,28,28^FH\^FDLOTE^FS
^FT355,328^A0N,28,28^FH\^FDPANEL^FS
^FT22,329^A0N,28,28^FH\^FDMODELO^FS
^FT30,236^A0N,25,26^FH\^FDSEMIELABORADO^FS
^FT34,122^A0B,25,24^FH\^FDEBS^FS
^FT34,277^A0N,34,33^FH\^FD4-651-IAPOWTV00148^FS
^FT587,381^A0N,39,38^FH\^FDL104^FS
^FT355,380^A0N,39,38^FH\^FDHIR^FS
^FT21,381^A0N,39,38^FH\^FD32LD846HT^FS
^FT294,165^A0N,90,88^FH\^FDOP-84366^FS
^FT613,283^A0N,42,69^FH\^FD99000^FS
^BY160,160^FT53,187^BXN,5,200,0,0,1,_
^FH\^FDOP-84188\0D\0A4-651-IAPOWTV00148\0D\0APLA\0D\0A99000\0D\0A100\0D\0AP3-UshZebra3^FS
^FO15,333^GB773,0,6^FS
^FO575,299^GB0,92,4^FS
^FO344,299^GB0,92,4^FS
^LRY^FO593,208^GB0,79,7^FS^LRN
^LRY^FO582,300^GB206,0,31^FS^LRN
^LRY^FO351,300^GB222,0,32^FS^LRN
^LRY^FO602,208^GB185,0,34^FS^LRN
^LRY^FO16,300^GB325,0,32^FS^LRN
^LRY^FO264,26^GB470,0,54^FS^LRN
^LRY^FO17,208^GB222,0,34^FS^LRN
^LRY^FO14,14^GB0,180,23^FS^LRN
^PQ1,0,1,Y^XZ
";
}
function Imprimir(){
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
$this->error = "socket_create() failed: reason: " . socket_strerror(socket_last_error($socket)) . "\n";
return false;
}
$result = socket_connect($socket, $this->host, $this->port);
if ($result === false) {
$this->error = "socket_connect() failed.\nReason: ($result) " . socket_strerror(socket_last_error($socket)) . "\n";
return false;
}
socket_write($socket, $this->prn, strlen($this->prn));
socket_close($socket);
return true;
}
}
$o = new ZebraBarcode("10.30.30.128",9100);
$o->Imprimir();
?>
代码有效!!但CR和LF仍无法正常工作。有什么想法吗?
提前致谢!
答案 0 :(得分:0)
十六进制值通常以_(下划线)转义。
尝试用_0D_0A
代替\0D\0A
!