如何从 POS 打印机获取状态

发布于 2024-08-30 19:54:37 字数 103 浏览 3 评论 0原文

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美人如玉 2024-09-06 19:54:37

我终于解决了我的问题...我在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);
}
?>

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);
}
?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文