公司工程师遇到个问题,要在局域网环境使用网络POS打印机。以前没有这样用过,便找了台SPRNT S76打印机开始测试。来不及仔细看打印机的开发说明,加上问对方技术支持也是半懂不懂的,只好自己测试。可惜了半卷纸。。。。。。
代码如下:
<?php
$fp = fsockopen("172.16.12.10", 9100, $errno, $errstr, 10);
if (!$fp) {
echo "$errstr ($errno)<br />/n";
}
else {
$out="/n 美亚大酒店西餐厅/n";
$out.="======================================/n";
fwrite($fp,$out);
MIEA_delay(500);
for ($i=1;$i<=20;$i++){ //测试20行数据
if ($i<10) $tmp="0".$i; else $tmp=$i;
$out=$tmp." 123456789a123456789b123456789c/n";
fwrite($fp,$out);
MIEA_delay(100);
}
//连续打印$k行空格
$k=3;
for($i=0;$i<$k;$i++){
fwrite($fp,chr(13).chr(10));
MIEA_delay(100);
}
//最后五行用于挤出缓冲区内容
$out="/n/n/n/n/n";
fwrite($fp,$out);
MIEA_delay(100);
//切纸
$out=chr(29)."V1";
fwrite($fp,$out);
}
fclose($fp);
//-----------------------------
//2011/06/29 刘武
//毫秒级延时函数 0<dblLong<1000
function MIEA_delay($dblLong){
if ($dblLong>=1000)$dblLong=999;
$startTime=floor(microtime()*1000);
$endTime=$startTime+$dblLong;
if ($endTime>999)$endTime=$endTime-999;
while (floor(microtime()*1000)!=$endTime){
//echo floor(microtime()*1000)."<br>";
}
}
//=============================
?>