#include #include #include //#include #define time 10000000 #include #include #include #include #include #include #include #include #include #include #include #include #include /* struct tms */ //Пример работы с принтером используя различные методы - печать на принтере, //получение информации о регистрах принтера через заголовочные файлы //parport.h и ppdev.h, и через прямое чтение из порта struct tms tms_stop, tms_start; clock_t real_stop, real_start; clock_t HZ; /* число ticks в секунде */ /* Засечь время момента старта процесса */ void hello(void){ real_start = times(&tms_start); } /* Засечь время окончания процесса */ void bye(int n){ real_stop = times(&tms_stop); clock_t HZ = sysconf(_SC_CLK_TCK); printf("Real time = %g seconds [%lu ticks]\n",(real_stop - real_start) / (double)HZ, real_stop - real_start); exit(n); } int main() { hello(); printf("Nachinaem\n"); unsigned char bitpat,rel,cla,dat; unsigned char status,reg_data,reg_status,reg_ctrl; int fd,i,j; //Открываем параллельный порт fd = open("/dev/lp0", O_RDWR); //Если хендлер вернул ошибку if(fd==-1) { printf("ERROR cannot open device \n"); return(0); } //Получаем системную информацию через директивы ioctl(fd,PPRSTATUS,&status); printf("\nSTATUS PORTA: %d\n",status); ioctl(fd,PPRELEASE,&rel); printf("\nRELIASE: %d\n",rel); ioctl(fd,PPCLAIM,&cla); printf("\nCLAIM: %d\n",cla); ioctl(fd,PPDATADIR,&dat); printf("\nDIR: %d\n",dat); printf("\nPishem...\n"); usleep(500000); //Печатаем путем прямой записи write(fd,"\nTest\r",sizeof("\nTest\r")); printf("\nZapis ok\n"); usleep(500000); //Получаем информацию путем прямого чтения из порта iopl(3); reg_data=inb(0x378); reg_status=inb(0x379); reg_ctrl=inb(0x37a); printf("\n\nDATA: %x\n ",reg_data); printf("\nSTATUS: %x\n",reg_status); printf("\nCONTROL: %x\n\n",reg_ctrl); bye(0); }