Blame view

test_imprimante_v3.c 4.75 KB
a8f4b0eb   aarnaude   imprimante
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
  #include <stdio.h>
  #include <stdlib.h>
  #include <unistd.h>
  #include <termios.h>
  #include <sys/types.h>
  #include <sys/stat.h>
  #include <fcntl.h>
  #include <strings.h>
  
  #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;
  }