php 连续打印设置,QT 怎么实现连续纸张的打印

这个程序需要操作lp端口,所以运行此程序的用户要被赋予“lp“的权限,在用户管理里面做。

这四个函数,第一个打开端口,第二个关闭端口,第三个送单个字符,第四个送字串。我在我们单位的挂号程序里就是这么用的。

先打开端口,再送字符或字串,再关闭端口。

送字串函数开头送的两个字符,是我的打印机的打印方式控制码,你可以查你自己的打印机手册,看你应该用什么控制码。

#include

#include

#include

#include

#include

//

inline int prtBegin()

{

int fd= open("/dev/lp0", O_WRONLY);

if ( fd < 0) {

QMessageBox::warning(0,"ERROR","open paraport error!");

return -1;

}else{

return fd;

}

}

//

inline void prtEnd(int fd)

{

::close(fd);

}

//

inline bool prtChar(int fd,char ch)

{

if(write(fd,&ch,1)!=1){

QMessageBox::warning(0,"ERROR","write paraport error with character"+QString::number(ch)+" !");

return false;

}

return true;

}

//

inline bool prtLine(int fd,QString str,int h,int w)

{

if(!prtChar(fd,27))return false;

if(!prtChar(fd,33))return false;

char tmp=0;

if(h==1)    {

tmp=tmp | 0x10;

}else if(h!=0){

QMessageBox::warning(0,"ERROR","prtLine parameter h error  !");

return false;

}

if(w==1)    {

tmp=tmp | 0x20;

}else if(w!=0){

QMessageBox::warning(0,"ERROR","prtLine parameter w error  !");

return false;

}

if(!prtChar(fd,tmp))return false;

QTextCodec *codec = QTextCodec::codecForName("GBK");

QByteArray encstr = codec->fromUnicode(str);

int len=encstr.length();

if(write(fd,encstr,len)!=len){

QMessageBox::warning(0,"ERROR","write paraport error with "+str+" !");

return false;

}

return true;

}