From a8f4b0eb396099ebb95940491d04306c144856a5 Mon Sep 17 00:00:00 2001 From: aarnaude Date: Wed, 15 Feb 2017 21:44:20 +0100 Subject: [PATCH] imprimante --- Makefile | 5 +++++ test_imprimante_v3.c | 278 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test_imprimante_v4.c | 395 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 678 insertions(+), 0 deletions(-) create mode 100644 Makefile create mode 100644 test_imprimante_v3.c create mode 100644 test_imprimante_v4.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7707760 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +CC = gcc +CFLAGS = -Wall -Wextra + +imprimante : + $(CC) $(CFLAGS) test_imprimante_v4.c -o imprimante diff --git a/test_imprimante_v3.c b/test_imprimante_v3.c new file mode 100644 index 0000000..8839265 --- /dev/null +++ b/test_imprimante_v3.c @@ -0,0 +1,278 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#define SPEED B9600 +#define PATH "/dev/usb/lp1" + +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 C = 0x43; +unsigned char c = 0x63; +unsigned char NUL = 0; +unsigned char UN = 1; +unsigned char DX = 2; +unsigned char TROIS = 3; +unsigned char QUATRE = 4; +unsigned char CVS = 0x7F;//127 +unsigned char SQ = 0x40; //64 +unsigned char v = 0x76; +unsigned char V = 0x56; +unsigned char U = 0x55; +unsigned char DOL = 0x24;//$ +unsigned char BSLASH = 0x5C;// "\" +unsigned char SOIXANTE = 60; + +unsigned char q = 0x71; +unsigned char k = 0x6B; +unsigned char t = 0x74; +unsigned char r = 0x72; +unsigned char X = 0x58; +unsigned char EQUAL = 0x3D; + +unsigned char l = 0x6C; +unsigned char Q = 0x51; + + +void init_impr(int fd) +{ + int france=1; + + write(fd, &ESC, 1); //ESC + write(fd, &AT, 1); //@ : ESC @ permet d'initialiser l'imprimante + + write(fd,&R,1); + write(fd,&france,1); + + write(fd, &CR, 1); + write(fd, &LF, 1); +} + +void graphic_mode(int fd) +{ + write(fd,&ESC,1); + write(fd,&OPAR,1); + write(fd,&G,1); + write(fd,&UN,1); + write(fd,&NUL,1); + write(fd,&UN,1); +} + +/*void print_data(int fd, int data) +{ + //ESC ( ^ + + +}*/ + +void beep(int fd) +{ + unsigned char BEL = 0x07; //BEL beeper + write(fd,&BEL,1); +} + +void bold(int fd,int on) +{ + write(fd,&ESC,1); + if(on==1){ + write(fd,&E,1); + } + else{ + write(fd,&F,1); + } +} + +void italic(int fd, int on) +{ + write(fd,&ESC,1); + if(on==1){ + write(fd,&IQ,1); + } + else{ + write(fd,&IC,1); + } +} + +void double_strike(int fd, int on) +{ + write(fd,&ESC,1); + if(on==1){ + write(fd,&G,1); + } + else{ + write(fd,&H,1); + } +} + +void paper_out_detector(int fd, int on) +{ + write(fd,&ESC,1); + if(on==1){ + write(fd,&NEUF,1); + } + else{ + write(fd,&HUIT,1); + } +} + +void underline(int fd, int on) +{ + unsigned char UNDERLINE = 0x2D; // - + write(fd,&ESC,1); + write(fd,&UNDERLINE,1); + write(fd,&on,1); +} + +void hor_tab(int fd) +{ + unsigned char HT = 0x09; + write(fd,&HT,1); +} + +void ver_tab(int fd) +{ + unsigned char VT = 0x0B; + write(fd,&VT,1); +} + +struct termios saveterm; + +int init_serial(char *device,int speed) { // Fonction pour initialiser le port Serie + struct termios new; + int fd=open(device,O_RDWR|O_NOCTTY);// On ouvre un descripteur de fichier en mode lecture et ecriture, ici ça sera notre port série + if(fd<0){perror(device); exit(-1);} + tcgetattr(fd,&saveterm); // save current port settings + 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) { // fermeture du Port Série + tcsetattr(fd,TCSANOW,&saveterm); + close(fd); +} + +void multipoint_print_mode(int fd){ + +/* Color multipoint font driver P335 */ + + printf("Début du mode multipoint\n"); + +/* Step 1 : Start Job */ + + printf("Initialisation de l'imprimante\n"); + init_impr(fd); + +/* Step 2 : Set Specific Configuration */ + + /* Set units ESC ( U */ + /* A4 8.27 x 11.69 inches */ + + write(fd,&ESC,1); + write(fd,&OPAR,1); + write(fd,&U,1); + write(fd,&UN,1); + write(fd,&NUL,1); + /* Unit is 1/60inch */ + write(fd,&SOIXANTE,1); + + /* Assign character table ESC ( t */ + + write(fd,&ESC,1); + write(fd,&OPAR,1); + write(fd,&t,1); + write(fd,&TROIS,1); + write(fd,&NUL,1); + /* Select tab 1 */ + write(fd,&NUL,1); + /* Canada - French */ + write(fd,&HUIT,1); + write(fd,&NUL,1); + + /* Set page length ESC ( C */ + + write(fd,&ESC,1); + write(fd,&OPAR,1); + write(fd,&C,1); + write(fd,&DX,1); + write(fd,&NUL,1); + unsigned char CQVN = 189; + write(fd,&CQVN,1); + write(fd,&DX,1); + + /* Set page format ESC ( c */ + + write(fd,&ESC,1); + write(fd,&OPAR,1); + write(fd,&c,1); + write(fd,&QUATRE,1); + write(fd,&NUL,1); + write(fd,&NUL,1); + write(fd,&CQVN,1); + write(fd,&DX,1); + + /* Set pitch ESC X, ESC P, ESC M, ESC g */ + + /* Set left and right margins ESC l,Q */ + /* Using default configuration */ + + /* Set line spacing n/360" */ + +/* Step 3 : Adjust Vertical Print Position OPTIONNAL */ + +/* Step 4 : Adjust Horizontal Print Position OPTIONNAL */ + + +/* Step 5 : Output Text */ + + write(fd,&ESC,1); + write(fd,&t,1); + write(fd,&NUL,1); + + +/* Final step : End Page & End Job */ + + /* Send FF */ + + /* ESC @ */ + +} + +int main(void) { + int fd = init_serial(PATH, SPEED); + int cpt = 0,i=0; + printf("Debut de controle imprimante\n"); + + + + +/* TIFF compressed mode p182 */ + +/* write(fd,&ESC,1); + write(fd,&DOT,1); + write(fd,&DX,1); + write(fd,&VINGT,1); + write(fd,&VINGT,1); + write(fd,&CQV,1); + write(fd,&UN,1); + write(fd,&NUL,1); + write(fd,&NUL,1); +*/ +return 0; +} diff --git a/test_imprimante_v4.c b/test_imprimante_v4.c new file mode 100644 index 0000000..50599cc --- /dev/null +++ b/test_imprimante_v4.c @@ -0,0 +1,395 @@ +/* code contrôle de l'imprimante + * + * EPSON LQ 570 + + * P406 + * Buffer size = 8kB + * + * Commandes indisponible pour ce modèle : + * ESC r : color*/ + + +#include +#include +#include +#include +#include +#include +#include +#include + +#define SPEED B9600 +#define PATH "/dev/usb/lp0" + +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 C = 0x43; +unsigned char c = 0x63; +unsigned char NUL = 0; +unsigned char UN = 1; +unsigned char DX = 2; +unsigned char TROIS = 3; +unsigned char QUATRE = 4; +unsigned char NEUF = 0x39; +unsigned char HUIT = 0x38; +unsigned char VINGT = 20; +unsigned char CVS = 0x7F;//127 +unsigned char SQ = 0x40; //64 +unsigned char v = 0x76; +unsigned char V = 0x56; +unsigned char U = 0x55; +unsigned char DOL = 0x24;//$ +unsigned char BSLASH = 0x5C;// "\" +unsigned char SOIXANTE = 60; +unsigned char DOT = 0x2E;// . + +unsigned char q = 0x71; +unsigned char k = 0x6B; +unsigned char t = 0x74; +unsigned char r = 0x72; +unsigned char X = 0x58; +unsigned char EQUAL = 0x3D; + +unsigned char l = 0x6C; +unsigned char Q = 0x51; + + +void init_impr(int fd) +{ + int france=1; + unsigned char R = 0x52; + write(fd, &ESC, 1); //ESC + write(fd, &AT, 1); //@ : ESC @ permet d'initialiser l'imprimante + + write(fd,&R,1); + write(fd,&france,1); + + write(fd, &CR, 1); + write(fd, &LF, 1); +} + +void beep(int fd) +{ + unsigned char BEL = 0x07; //BEL beeper + write(fd,&BEL,1); +} + +void bold(int fd,int on) +{ + + unsigned char E = 0x45; + unsigned char F = 0x46; + write(fd,&ESC,1); + if(on==1){ + write(fd,&E,1); + } + else{ + write(fd,&F,1); + } +} + +void italic(int fd, int on) +{ + unsigned char IQ = 0x34; + unsigned char IC = 0x35; + write(fd,&ESC,1); + if(on==1){ + write(fd,&IQ,1); + } + else{ + write(fd,&IC,1); + } +} + +void double_strike(int fd, int on) +{ + + unsigned char G = 0x47; + unsigned char H = 0x48; + write(fd,&ESC,1); + if(on==1){ + write(fd,&G,1); + } + else{ + write(fd,&H,1); + } +} + +void paper_out_detector(int fd, int on) +{ + write(fd,&ESC,1); + if(on==1){ + write(fd,&NEUF,1); + } + else{ + write(fd,&HUIT,1); + } +} + +void underline(int fd, int on) +{ + unsigned char UNDERLINE = 0x2D; // - + write(fd,&ESC,1); + write(fd,&UNDERLINE,1); + write(fd,&on,1); +} + +void hor_tab(int fd) +{ + unsigned char HT = 0x09; + write(fd,&HT,1); +} + +void ver_tab(int fd) +{ + unsigned char VT = 0x0B; + write(fd,&VT,1); +} + +struct termios saveterm; + +int init_serial(char *device,int speed) { // Fonction pour initialiser le port Serie + struct termios new; + int fd=open(device,O_RDWR|O_NOCTTY);// On ouvre un descripteur de fichier en mode lecture et ecriture, ici ça sera notre port série + if(fd<0){perror(device); exit(-1);} + tcgetattr(fd,&saveterm); // save current port settings + 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) { // fermeture du Port Série + tcsetattr(fd,TCSANOW,&saveterm); + close(fd); +} + +void multipoint_print_mode(int fd){ + + /* Color multipoint font driver P335 */ + + printf("Début du mode multipoint\n"); + + /* Step 1 : Start Job */ + + printf("Initialisation de l'imprimante\n"); + init_impr(fd); + + /* Step 2 : Set Specific Configuration */ + + /* Set units ESC ( U */ + /* A4 8.27 x 11.69 inches */ + + write(fd,&ESC,1); + write(fd,&OPAR,1); + write(fd,&U,1); + write(fd,&UN,1); + write(fd,&NUL,1); + /* Unit is 1/60inch */ + write(fd,&SOIXANTE,1); + + /* Assign character table ESC ( t */ + + write(fd,&ESC,1); + write(fd,&OPAR,1); + write(fd,&t,1); + write(fd,&TROIS,1); + write(fd,&NUL,1); + /* Select tab 1 */ + write(fd,&NUL,1); + /* Canada - French */ + write(fd,&HUIT,1); + write(fd,&NUL,1); + + /* Set page length ESC ( C */ + + write(fd,&ESC,1); + write(fd,&OPAR,1); + write(fd,&C,1); + write(fd,&DX,1); + write(fd,&NUL,1); + unsigned char CQVN = 189; + write(fd,&CQVN,1); + write(fd,&DX,1); + + /* Set page format ESC ( c */ + + write(fd,&ESC,1); + write(fd,&OPAR,1); + write(fd,&c,1); + write(fd,&QUATRE,1); + write(fd,&NUL,1); + write(fd,&NUL,1); + write(fd,&CQVN,1); + write(fd,&DX,1); + + /* Set pitch ESC X, ESC P, ESC M, ESC g */ + + /* Set left and right margins ESC l,Q */ + /* Using default configuration */ + + /* Set line spacing n/360" */ + + /* Step 3 : Adjust Vertical Print Position OPTIONNAL */ + + /* Step 4 : Adjust Horizontal Print Position OPTIONNAL */ + + + /* Step 5 : Output Text */ + //table 0 + write(fd,&ESC,1); + write(fd,&t,1); + write(fd,&NUL,1); + + int i=0,cpt_max=100; + unsigned char data=0x69; + for(i=0;i