#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <linux/lp.h>
int main(int argc, char **argv)
{
int fd;
int fp;
int prnstate;
int lp;
unsigned char buff [128];
fd = open("/dev/lp0", O_RDWR | O_NDELAY);
if (fd < 0) {
perror("open error");
exit(1);
}
fp = open("/dev/port", O_RDWR);
if (fp < 0) {
perror("open error");
exit(1);
}
while (1) {
ioctl(fd, LPGETSTATUS, &prnstate); / * 读取 select 脚状态 (第 13 脚) */
if (prnstate & LP_PSELECD) { /* 高点平则 LED 亮 */
lseek(fp, 0x378, SEEK_SET);
buff [0] = 0xff;
write(fp, buff, 1);
} else {
lseek(fp, 0x378, SEEK_SET); /* 低电平 LED 灯灭 */
buff [0] = 0x00;
write(fp, buff, 1);
}
usleep(50000);
}
close(fd);
return (0);
}
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |