LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1099|回复: 0

以下是并口打印机监控程序!各位大侠 在这基础上 帮我改成监控串口打印机的 谢

[复制链接]
发表于 2009-7-30 11:17:44 | 显示全部楼层 |阅读模式
#include <sys/ioctl.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <getopt.h>

#include <linux/lp.h>


int CheckParPortState(int fd, int m_bits)
{
int status;

/* Get Par Port State */
if (ioctl(fd, LPGETSTATUS, (char*)&status) < 0) {
return (0);
}
if (m_bits != 0x20) return ( status & m_bits );
else return( !(status & m_bits) );
}

main()
{
int fd;

if ( (fd = open("/dev/lp0", O_WRONLY , 0)) < 0) {
perror("/dev/lp0 error");
exit(-1);
};


if (!CheckParPortState(fd, LP_PBUSY))
printf("printer is busy \n");

if (!CheckParPortState(fd, LP_PACK))
printf("printer answer \n");

if (!CheckParPortState(fd, LP_POUTPA))
printf("printer paper out \n");

if (!CheckParPortState(fd, LP_PERRORP))
printf("printer error \n");


close(fd);

}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表