/* code contrôle de l'imprimante * * EPSON LQ 570 + * P406 * Buffer size = 8kB * */ #include #include #include #include #include #include #include #include /************** * Constantes * * ************/ #define SPEED B9600 #define PATH "/dev/usb/lp0" #define N_TEST 3 /********************** * Commandes usuelles * * ********************/ unsigned int N_COLUMN=12; unsigned char ESC=0x1B; unsigned char AT = 0x40;//@ unsigned char CR = 0x0D; unsigned char LF = 0x0A; unsigned char FF = 0x0C; unsigned char OPAR = 0x28;//( unsigned char NUL = 0; unsigned char UN = 1; /********************************* * Fonctions communication série * *********************************/ struct termios saveterm; int init_serial(char *device,int speed) { struct termios new; int fd=open(device,O_RDWR|O_NOCTTY); if(fd<0){perror(device); exit(-1);} tcgetattr(fd,&saveterm); bzero(&new,sizeof(new)); new.c_cflag=CLOCAL|CREAD|speed|CS8; new.c_iflag=0; new.c_oflag=0; new.c_lflag=0; // set input mode (non-canonical, no echo,...) new.c_cc[VTIME]=0; // inter-character timer unused new.c_cc[VMIN]=1; // blocking read until 1 char received tcflush(fd, TCIFLUSH); tcsetattr(fd,TCSANOW,&new); return fd; } void close_serial(int fd) { tcsetattr(fd,TCSANOW,&saveterm); close(fd); } /********************************************* * Fonction d'initialisation de l'imprimante * *********************************************/ void init_impr(int fd) { write(fd, &ESC, 1); //ESC write(fd, &AT, 1); //@ : ESC @ permet d'initialiser l'imprimante } /***************************************** * Fonctions de controle de l'imprimante * *****************************************/ void bit_image(int fd){ //P29 unsigned char STAR = 0x2A; unsigned char PLUS = 0x2B; unsigned int QH = 48; unsigned int data1 = 0xA0; unsigned int data2 = 0x3A; unsigned int data3 = 0x9F; unsigned int data4 = 0xCD; unsigned char G = 0x47; unsigned int j = 0; unsigned int test = 0; //P176 //Entering Graphic mode write(fd,&ESC,1); write(fd,&OPAR,1); write(fd,&G,1); write(fd,&UN,1); write(fd,&NUL,1); write(fd,&UN,1); // Set line spacing with ESC + 48 write(fd,&ESC,1); write(fd,&PLUS,1); write(fd,&QH,1); //Go to starting line write(fd,&CR,1); write(fd,&LF,1); // ESC * for each line of dots P184 for(test=0;test