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;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值