如何从POS打印机获取状态

时间:2010-04-28 17:09:53

标签: linux printers

我正试图找到一种从POS打印机获取纸张状态的方法;我想我会使用GS a,GS r序列,但我无法理解如何从打印机返回信息;我在Linux下,POS打印机在哪里返回有关状态的信息?

1 个答案:

答案 0 :(得分:1)

我终于解决了我的问题...我在linux上使用PHP框,这里是代码,希望能帮到任何人:

<?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);
}
?>