开发者

How to get status from POS Printer

I'm trying to find a way to get paper status from a POS pr开发者_开发技巧inter; I think I would use GS a, GS r sequence but I cannot understand how to return info from the printer; I'm under Linux, where does the POS printer returns info about status?


I've finally solved my problem ... i use PHP on linux box, here is the code, hope to help anyone:

<?php

$device="/dev/usb/lp0";
$printer=fopen($device, 'w');

//La sequenza di ESCAPE DLE EOT n consente 
//la trasmissione in realtime
//dello status
//n=1: printer status
//n=2: printer offline status
//n=3: error status
//n=4: paper roll sensor status

//Per n=4 i bits valorizzati sono:
//BIT   Off/On  Dec Desc
//0     Off     0   not used, fixed to Off
//1     On      2   not used, fixed to On
//2,3   Off     0   Paper adequate
//2,3   On      12  Paper near end detected
//4     On      16  Not used, fixed to On
//5,6   Off     0   Paper present   
//5,6   Off     96  Paper roll end
//7     Off     0   Not used, fixed to Off


fwrite($printer,kbyte(16).kbyte(4).kbyte(4));
//fwrite($printer,kbyte(29).kbyte(73).kbyte(69));

fclose($printer);
$r_printer=fopen($device, 'r');
$ret=fgets($r_printer);
fclose($r_printer);
$bit_val=ord($ret[0]);

print "Retval=".$bit_val;

if(($bit_val & 12) || ($bit_val & 96))
    print "******Out of paper******\n";
else
    print "---Paper ok\n";

function kbyte($num) {
    return pack('C', $num);
}
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜