我正在尝试通过 php 套接字从 Zebra QLn220 移动打印机获取响应。
与打印机的通信很好,我可以发送配置参数并打印我需要的标签/收据,但我无法从打印机获得任何响应。
// Toy socket connection to Zebra QLn220 mobile printer
// set up socket
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
if (!$sock){
die("boourns, no socket created");
}
echo "Socket created".PHP_EOL;
$printer_ip = '192.168.0.11';
// connect socket to printer
if(!socket_connect($sock, $printer_ip, 6101)){
$errorcode = socket_last_error();
$errormsg = socket_str($errorcode);
die("Could not connect: [$errorcode] $errormsgn");
}
// this is actually a CPCL set up command, not ZPL, but I can't get a response regardless of language
$get_mac = '! U1 getvar "wlan.mac_addr"'
$success = socket_send($sock, $get_mac, strlen($out), 0);
$result = socket_read($sock, 1024);
echo $result.PHP_EOL;
通过套接字发送有效,但我最终永远等待并且在调用socket_read
时没有得到任何响应。
在如何从插座读取时,我可能会关闭,或者打印机根本没有响应我尝试过的任何请求?
通过套接字成功传输消息的其他示例,因此您可以看到我不只是对深渊大喊大叫:
$m1 = "^XA".
"^FO20,50".
"^A0N50,50".
"^FDHello, World!".
"^FS".
"^XZ";
$m2 = "^XA".
"^FO15,60".
"^BCN,75,Y,N,N".
"^FDFront Shelf-2^FS".
"^XZ";
$m3 = "^XA".
"^POI".
"^FO50,50".
"^ADN,36,20". // height, width of characters. min is 18,10
"^FDInverted label^FS".
"^XZ";
$m4 = "^XA".
"^FO15,15".
"^FDONLY ONE LABEL?!?!^FS".
"^XZ";
$m5 = "~JC". // set media sensor calibration
"^XA".
"^JUS". // Configuration update. SAVE settings
"^XZ";
每个 SGD 命令都需要从新行开始,并以rn
所以在此行中添加一个rn
:
$get_mac = 'rn! U1 getvar "wlan.mac_addr"rn'