English 中文(简体)
How to get status from POS Printer
原标题:

I m trying to find a way to get paper status from a POS printer; 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******
";
else
    print "---Paper ok
";

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




相关问题
Signed executables under Linux

For security reasons, it is desirable to check the integrity of code before execution, avoiding tampered software by an attacker. So, my question is How to sign executable code and run only trusted ...

encoding of file shell script

How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

热门标签