Commit 996f12b0a580ff8a55607cf1f41a964a7697d5a4

Authored by aarnaude
1 parent 73746090

controle en mode bit image + tests d'envoi de differentes datas

Showing 5 changed files with 296 additions and 7 deletions   Show diff stats
Makefile
1 1 CC = gcc
2 2 CFLAGS = -Wall -Wextra
3 3  
  4 +bit :
  5 + $(CC) $(CFLAGS) bit_image.c -o bit
  6 +
4 7 imprimante :
5   - $(CC) $(CFLAGS) test_imprimante_v4.c -o imprimante
  8 + $(CC) $(CFLAGS) test_imprimante_v4.c -o v4
... ...
bit 0 → 100755
No preview for this file type
bit_image.c 0 → 100644
... ... @@ -0,0 +1,189 @@
  1 +/* code contrôle de l'imprimante
  2 + *
  3 + * EPSON LQ 570 +
  4 + * P406
  5 + * Buffer size = 8kB
  6 + *
  7 + */
  8 +
  9 +
  10 +#include <stdio.h>
  11 +#include <stdlib.h>
  12 +#include <unistd.h>
  13 +#include <termios.h>
  14 +#include <sys/types.h>
  15 +#include <sys/stat.h>
  16 +#include <fcntl.h>
  17 +#include <strings.h>
  18 +
  19 +/**************
  20 + * Constantes *
  21 + * ************/
  22 +
  23 +#define SPEED B9600
  24 +#define PATH "/dev/usb/lp0"
  25 +#define N_TEST 3
  26 +
  27 +/**********************
  28 + * Commandes usuelles *
  29 + * ********************/
  30 +
  31 +unsigned int N_COLUMN=12;
  32 +unsigned char ESC=0x1B;
  33 +unsigned char AT = 0x40;//@
  34 +unsigned char CR = 0x0D;
  35 +unsigned char LF = 0x0A;
  36 +unsigned char FF = 0x0C;
  37 +unsigned char OPAR = 0x28;//(
  38 +unsigned char NUL = 0;
  39 +unsigned char UN = 1;
  40 +
  41 +/*********************************
  42 + * Fonctions communication série *
  43 + *********************************/
  44 +
  45 +struct termios saveterm;
  46 +
  47 +int init_serial(char *device,int speed) {
  48 + struct termios new;
  49 + int fd=open(device,O_RDWR|O_NOCTTY);
  50 + if(fd<0){perror(device); exit(-1);}
  51 + tcgetattr(fd,&saveterm);
  52 + bzero(&new,sizeof(new));
  53 + new.c_cflag=CLOCAL|CREAD|speed|CS8;
  54 + new.c_iflag=0;
  55 + new.c_oflag=0;
  56 + new.c_lflag=0; // set input mode (non-canonical, no echo,...)
  57 + new.c_cc[VTIME]=0; // inter-character timer unused
  58 + new.c_cc[VMIN]=1; // blocking read until 1 char received
  59 + tcflush(fd, TCIFLUSH);
  60 + tcsetattr(fd,TCSANOW,&new);
  61 + return fd;
  62 +}
  63 +
  64 +void close_serial(int fd) {
  65 + tcsetattr(fd,TCSANOW,&saveterm);
  66 + close(fd);
  67 +}
  68 +
  69 +/*********************************************
  70 + * Fonction d'initialisation de l'imprimante *
  71 + *********************************************/
  72 +
  73 +void init_impr(int fd)
  74 +{
  75 + write(fd, &ESC, 1); //ESC
  76 + write(fd, &AT, 1); //@ : ESC @ permet d'initialiser l'imprimante
  77 +}
  78 +
  79 +/*****************************************
  80 + * Fonctions de controle de l'imprimante *
  81 + *****************************************/
  82 +
  83 +void bit_image(int fd){
  84 + //P29
  85 + unsigned char STAR = 0x2A;
  86 + unsigned char PLUS = 0x2B;
  87 + unsigned int QH = 48;
  88 + unsigned int data1 = 0xA0;
  89 + unsigned int data2 = 0x3A;
  90 + unsigned int data3 = 0x9F;
  91 + unsigned int data4 = 0xCD;
  92 +
  93 + unsigned char G = 0x47;
  94 + unsigned int j = 0;
  95 + unsigned int test = 0;
  96 +
  97 + //P176
  98 + //Entering Graphic mode
  99 + write(fd,&ESC,1);
  100 + write(fd,&OPAR,1);
  101 + write(fd,&G,1);
  102 + write(fd,&UN,1);
  103 + write(fd,&NUL,1);
  104 + write(fd,&UN,1);
  105 +
  106 + // Set line spacing with ESC + 48
  107 + write(fd,&ESC,1);
  108 + write(fd,&PLUS,1);
  109 + write(fd,&QH,1);
  110 +
  111 + //Go to starting line
  112 + write(fd,&CR,1);
  113 + write(fd,&LF,1);
  114 +
  115 + // ESC * for each line of dots P184
  116 + for(test=0;test<N_TEST;test++){
  117 + write(fd,&ESC,1);
  118 + write(fd,&STAR,1);
  119 + write(fd,&NUL,1); // m = 0
  120 + write(fd,&N_COLUMN,1); // nl
  121 + write(fd,&NUL,1); // nh
  122 + for(j=0;j<(N_COLUMN);j++){
  123 + //8 dot columns, 1 byte per column
  124 + write(fd,&data1,1);
  125 + write(fd,&data2,1);
  126 + write(fd,&data3,1);
  127 + write(fd,&data4,1);
  128 + }
  129 + // CR LF
  130 + write(fd,&CR,1);
  131 + write(fd,&LF,1);
  132 + }
  133 +
  134 + data1=0xF0;
  135 + data2=0xF1;
  136 + data3=0xF2;
  137 + data4=0xF4;
  138 + for(test=0;test<N_TEST;test++){
  139 + write(fd,&ESC,1);
  140 + write(fd,&STAR,1);
  141 + write(fd,&NUL,1); // m = 0
  142 + write(fd,&N_COLUMN,1); // nl
  143 + write(fd,&NUL,1); // nh
  144 + for(j=0;j<N_COLUMN;j++){
  145 + // 8 dot columns, 1 byte per column
  146 + write(fd,&data1,1);
  147 + write(fd,&data2,1);
  148 + write(fd,&data3,1);
  149 + write(fd,&data4,1);
  150 + }
  151 + // CR LF
  152 + write(fd,&CR,1);
  153 + write(fd,&LF,1);
  154 + }
  155 +
  156 + data1=0xA0;
  157 + data2=0xA1;
  158 + data3=0xA2;
  159 + data4=0xA4;
  160 + for(test=0;test<N_TEST;test++){
  161 + write(fd,&ESC,1);
  162 + write(fd,&STAR,1);
  163 + write(fd,&NUL,1); // m = 0
  164 + write(fd,&N_COLUMN,1); // nl
  165 + write(fd,&NUL,1); // nh
  166 + for(j=0;j<N_COLUMN;j++){
  167 + // 8 dot columns, 1 byte per column
  168 + write(fd,&data1,1);
  169 + write(fd,&data2,1);
  170 + write(fd,&data3,1);
  171 + write(fd,&data4,1);
  172 + }
  173 + // CR LF
  174 + write(fd,&CR,1);
  175 + write(fd,&LF,1);
  176 + }
  177 +}
  178 +
  179 +/********
  180 + * Main *
  181 + ********/
  182 +
  183 +int main(void) {
  184 + int fd = init_serial(PATH, SPEED);
  185 + init_impr(fd);
  186 + bit_image(fd);
  187 + close_serial(fd);
  188 + return 0;
  189 +}
... ...
test_imprimante_v4.c
... ... @@ -4,8 +4,7 @@
4 4 * P406
5 5 * Buffer size = 8kB
6 6 *
7   - * Commandes indisponible pour ce modèle :
8   - * ESC r : color*/
  7 + */
9 8  
10 9  
11 10 #include <stdio.h>
... ... @@ -19,6 +18,7 @@
19 18  
20 19 #define SPEED B9600
21 20 #define PATH "/dev/usb/lp0"
  21 +#define LINE_LENGTH 16
22 22  
23 23 unsigned char ESC=0x1B;
24 24 unsigned char AT = 0x40;//@
... ... @@ -274,7 +274,7 @@ void multipoint_print_mode(int fd){
274 274 write(fd,&ESC,1);
275 275 write(fd,&t,1);
276 276 write(fd,&UN,1);
277   -
  277 +
278 278 data=0x69;
279 279 for(i=0;i<cpt_max;i++)
280 280 write(fd,&data,1);
... ... @@ -343,10 +343,10 @@ void rle_mode(int fd){
343 343 write(fd,&UN,1);
344 344 /* Step 3 : Specific Configuration */
345 345 // default
346   -
  346 +
347 347 /* Step 4 : Horizontal & Vertical Print Position */
348 348 // default
349   -
  349 +
350 350 /* Step 5 : Output Raster Graphics */
351 351 write(fd,&ESC,1);
352 352 write(fd,&BSLASH,1);
... ... @@ -376,11 +376,105 @@ void rle_mode(int fd){
376 376 write(fd,&AT,1);
377 377 }
378 378  
  379 +
  380 +//P297
  381 +void bit_image(int fd){
  382 +
  383 + unsigned int VHUIT = 8;
  384 + unsigned char STAR = 0x2A;
  385 + unsigned char PLUS = 0x2B;
  386 + unsigned int QH = 48;
  387 + unsigned int data1 = 0x5E;
  388 + unsigned int data2 = 0x7F;
  389 + unsigned int data3 = 0x43;
  390 + unsigned int data4 = 0x86;
  391 +
  392 + unsigned char G = 0x47;
  393 + int i = 0;
  394 +
  395 + //P176
  396 + //Entering Graphic mode
  397 + write(fd,&ESC,1);
  398 + write(fd,&OPAR,1);
  399 + write(fd,&G,1);
  400 + write(fd,&UN,1);
  401 + write(fd,&NUL,1);
  402 + write(fd,&UN,1);
  403 +
  404 + // Set line spacing with ESC + 48
  405 + write(fd,&ESC,1);
  406 + write(fd,&PLUS,1);
  407 + write(fd,&QH,1);
  408 +
  409 + //Go to starting line
  410 + write(fd,&CR,1);
  411 + write(fd,&LF,1);
  412 +
  413 + // ESC * for each line of dots P184
  414 + write(fd,&ESC,1);
  415 + write(fd,&STAR,1);
  416 + write(fd,&NUL,1); // m = 0
  417 + write(fd,&VHUIT,1);
  418 + write(fd,&NUL,1);
  419 + /* 8 dot columns, 1 byte per column */
  420 + for(i=0;i<LINE_LENGTH;i++){
  421 + write(fd,&data1,1);
  422 + write(fd,&data2,1);
  423 + write(fd,&data3,1);
  424 + write(fd,&data4,1);
  425 + }
  426 +
  427 + // CR LF
  428 + write(fd,&CR,1);
  429 + write(fd,&LF,1);
  430 +
  431 + //New line
  432 + write(fd,&ESC,1);
  433 + write(fd,&STAR,1);
  434 + write(fd,&NUL,1); // m = 0
  435 + write(fd,&VHUIT,1);
  436 + write(fd,&NUL,1);
  437 +
  438 + data1=0xF1;
  439 + data2=0xF2;
  440 + data3=0xF4;
  441 + data4=0xF8;
  442 + for(i=0;i<LINE_LENGTH;i++){
  443 + write(fd,&data1,1);
  444 + write(fd,&data2,1);
  445 + write(fd,&data3,1);
  446 + write(fd,&data4,1);
  447 + }
  448 + write(fd,&CR,1);
  449 + write(fd,&LF,1);
  450 +
  451 + //New line
  452 + write(fd,&ESC,1);
  453 + write(fd,&STAR,1);
  454 + write(fd,&NUL,1); // m = 0
  455 + write(fd,&VHUIT,1);
  456 + write(fd,&NUL,1);
  457 +
  458 + data1=0xF0;
  459 + data2=0x0F;
  460 + data3=0xFA;
  461 + data4=0xAF;
  462 + for(i=0;i<LINE_LENGTH;i++){
  463 + write(fd,&data1,1);
  464 + write(fd,&data2,1);
  465 + write(fd,&data3,1);
  466 + write(fd,&data4,1);
  467 + }
  468 + write(fd,&CR,1);
  469 + write(fd,&LF,1);
  470 +}
  471 +
379 472 int main(void) {
380 473 int mode = 1;
381 474 int fd = init_serial(PATH, SPEED);
  475 + init_impr(fd);
382 476 printf("Debut de controle imprimante\n");
383   - printf("Choisir un mode d'impression :\n 1 = Multipoint \t 2 = Compressed Raster Graphics\n");
  477 + printf("Choisir un mode d'impression :\n 1 = Multipoint \t 2 = Compressed Raster Graphics \t 3 = Bit Image \n");
384 478 scanf("%d",&mode);
385 479 switch(mode){
386 480 case 1 :
... ... @@ -389,6 +483,9 @@ int main(void) {
389 483 case 2 :
390 484 rle_mode(fd);
391 485 break;
  486 + case 3 :
  487 + bit_image(fd);
  488 + break;
392 489 }
393 490 close_serial(fd);
394 491 return 0;
... ...
v4 0 → 100755
No preview for this file type