VDM*.tmp

hello all,
i'm now developing a program to read text file and send all the value from text file via serial communication. After i sent all the value from text file, i remove that file because another text file will be generated. What i'm asking, why after i remove the .txt file, the file changed into VDM*.tmp and after several times my program stop working, how to prevent it ?. Here is my code :

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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <dos.h>

#define PORT1 0x3F8

/*
Serial Port Address
COM1 0x3F8
COM2 0x2F8
COM3 0x3E8
cOM4 0x2E8
*/

void get_serial_data()
{
	int c;
	int counter;
	char buffer[100];	

	while(1)
	{
		c = inportb(PORT1 + 5);
		if(c & 1)
		{
			buffer[counter] = inport(PORT1);
			printf("%c", buffer[counter]);
		}
		if(kbhit())
		{
			break;
		}
	}		
}

void open_com_port()
{
	outportb(PORT1 + 1 , 0);   /* Turn off interrupts - Port1 */

	/*         PORT 1 - Communication Settings         */

	outportb(PORT1 + 3 , 0x80);  /* SET DLAB ON */
	outportb(PORT1 + 0 , 0x01);  /* Set Baud rate - Divisor Latch Low Byte */
				     /* Default 0x03 =  38,400 BPS */
				     /*         0x01 = 115,200 BPS */
				     /*         0x02 =  57,600 BPS */
				     /*         0x06 =  19,200 BPS */
				     /*         0x0C =   9,600 BPS */
				     /*         0x18 =   4,800 BPS */
				     /*         0x30 =   2,400 BPS */
	outportb(PORT1 + 1 , 0x00);  /* Set Baud rate - Divisor Latch High Byte */
	outportb(PORT1 + 3 , 0x03);  /* 8 Bits, No Parity, 1 Stop Bit */
	outportb(PORT1 + 2 , 0xC7);  /* FIFO Control Register */
	outportb(PORT1 + 4 , 0x0B);  /* Turn on DTR, RTS, and OUT2 */
}

void default_position_command()
{
	int value_default = 255;

	clrscr();
	outportb(PORT1, value_default);

	get_serial_data();
}

void move_all_axis_command()
{
	clrscr();
	printf("Please Insert Parameter\n");

	int duty_cycle_axis_1, arah_axis_1, angle_axis_1;
	int duty_cycle_axis_2, arah_axis_2, angle_axis_2;
	int duty_cycle_axis_3, arah_axis_3, angle_axis_3;
	int duty_cycle_axis_4, arah_axis_4, angle_axis_4;
	int duty_cycle_axis_5, arah_axis_5, angle_axis_5;

	int value_move_all_axis = 254;

	outportb(PORT1, value_move_all_axis);

	get_serial_data();

	//duty_cycle_axis_1
	printf("duty_cycle_axis_1 :  ");
	scanf("%d", &duty_cycle_axis_1);
	outportb(PORT1, duty_cycle_axis_1);

	get_serial_data();

	//arah_axis_1
	printf("arah_axis_1 :  ");
	scanf("%d", &arah_axis_1);
	outportb(PORT1, arah_axis_1);

	get_serial_data();

	//angle_axis_1
	printf("angle_axis_1 :  ");
	scanf("%d", &angle_axis_1);
	outportb(PORT1, angle_axis_1);

	get_serial_data();

	//duty_cycle_axis_2
	printf("duty_cycle_axis_2 :  ");
	scanf("%d", &duty_cycle_axis_2);
	outportb(PORT1, duty_cycle_axis_2);

	get_serial_data();

	//arah_axis_2
	printf("arah_axis_2 :  ");
	scanf("%d", &arah_axis_2);
	outportb(PORT1, arah_axis_2);

	get_serial_data();

	//angle_axis_2
	printf("angle_axis_2 :  ");
	scanf("%d", &angle_axis_2);
	outportb(PORT1, angle_axis_2);

	get_serial_data();

	//duty_cycle_axis_3
	printf("duty_cycle_axis_3 :  ");
	scanf("%d", &duty_cycle_axis_3);
	outportb(PORT1, duty_cycle_axis_3);

	get_serial_data();

	//arah_axis_3
	printf("arah_axis_3 :  ");
	scanf("%d", &arah_axis_3);
	outportb(PORT1, arah_axis_3);

	get_serial_data();

	//angle_axis_3
	printf("angle_axis_3 :  ");
	scanf("%d", &angle_axis_3);
	outportb(PORT1, angle_axis_3);

	get_serial_data();

	//duty_cycle_axis_4
	printf("duty_cycle_axis_4 :  ");
	scanf("%d", &duty_cycle_axis_4);
	outportb(PORT1, duty_cycle_axis_4);

	get_serial_data();

	//arah_axis_4
	printf("arah_axis_4 :  ");
	scanf("%d", &arah_axis_4);
	outportb(PORT1, arah_axis_4);

	get_serial_data();

	//angle_axis_4
	printf("angle_axis_4 :  ");
	scanf("%d", &angle_axis_4);
	outportb(PORT1, angle_axis_4);

	get_serial_data();	

	//duty_cycle_axis_5
	printf("duty_cycle_axis_5 :  ");
	scanf("%d", &duty_cycle_axis_5);
	outportb(PORT1, duty_cycle_axis_5);

	get_serial_data();	

	//arah_axis_5
	printf("arah_axis_5 :  ");
	scanf("%d", &arah_axis_5);
	outportb(PORT1, arah_axis_5);

	get_serial_data();

	//angle_axis_5
	printf("angle_axis_5 :  ");
	scanf("%d", &angle_axis_5);
	outportb(PORT1, angle_axis_5);

	get_serial_data();

}

void manual_mode()
{
	int select_command;

	clrscr();
	printf("Manual Mode Activated\n");
	printf("Select Command\n");
	printf("1. Default Position\n");
	printf("2. Move_All_Axis\n");
	scanf("%d", &select_command);

	switch(select_command)
	{
		case 1 :
		default_position_command();
		break;

		case 2 :
		move_all_axis_command();
		break;
	}
}

void web_based_loop()
{
	while(1)
	{
		clrscr();

		FILE *file_pointer;
		int counter;
		int movement_data[14] = {0};
		int value_web_based;			

		if(kbhit())
		{
			movement_data[0] = 0;
			movement_data[1] = 0;
			movement_data[2] = 0;
			movement_data[3] = 0;
			movement_data[4] = 0;
			movement_data[5] = 0;
			movement_data[6] = 0;
			movement_data[7] = 0;
			movement_data[8] = 0;
			movement_data[9] = 0;
			movement_data[10] = 0;
			movement_data[11] = 0;
			movement_data[12] = 0;
			movement_data[13] = 0;
			movement_data[14] = 0;

			delay(100);
			outportb(PORT1, movement_data[0]);
			delay(100);
			outportb(PORT1, movement_data[1]);
			delay(100);
			outportb(PORT1, movement_data[2]);
			delay(100);
			outportb(PORT1, movement_data[3]);
			delay(100);
			outportb(PORT1, movement_data[4]);
			delay(100);
			outportb(PORT1, movement_data[5]);
			delay(100);
			outportb(PORT1, movement_data[6]);
			delay(100);
			outportb(PORT1, movement_data[7]);
			delay(100);
			outportb(PORT1, movement_data[8]);
			delay(100);
			outportb(PORT1, movement_data[9]);
			delay(100);
			outportb(PORT1, movement_data[10]);
			delay(100);
			outportb(PORT1, movement_data[11]);
			delay(100);
			outportb(PORT1, movement_data[12]);
			delay(100);
			outportb(PORT1, movement_data[13]);
			delay(100);
			outportb(PORT1, movement_data[14]);

			remove("D:/adtj/www/htdocs/skripsi/kdt.txt");
			break;
		}

		if((file_pointer = fopen("D:/adtj/www/htdocs/skripsi/kdt.txt","rb")) == NULL)
		{
			printf("Movement File NOT Found!\n");
			printf("Press ENTER to exit\n");
		}		
	

		if((file_pointer = fopen("D:/adtj/www/htdocs/skripsi/kdt.txt","rb")) != NULL)
		{
			printf("Movement File Found!\n");
			printf("Press ENTER to exit\n");
			
			for(counter = 0; counter <= 14; counter++)
			{
				fscanf(file_pointer, "%d", &movement_data[counter]);
			}
	
			delay(100);
			outportb(PORT1, movement_data[0]);
			delay(100);
			outportb(PORT1, movement_data[1]);
			delay(100);
			outportb(PORT1, movement_data[2]);
			delay(100);
			outportb(PORT1, movement_data[3]);
			delay(100);
			outportb(PORT1, movement_data[4]);
			delay(100);
			outportb(PORT1, movement_data[5]);
			delay(100);
			outportb(PORT1, movement_data[6]);
			delay(100);
			outportb(PORT1, movement_data[7]);
			delay(100);
			outportb(PORT1, movement_data[8]);
			delay(100);
			outportb(PORT1, movement_data[9]);
			delay(100);
			outportb(PORT1, movement_data[10]);
			delay(100);
			outportb(PORT1, movement_data[11]);
			delay(100);
			outportb(PORT1, movement_data[12]);
			delay(100);
			outportb(PORT1, movement_data[13]);
			delay(100);
			outportb(PORT1, movement_data[14]);
			
			printf("Movement File Executed\n");

			delay(3000);
			printf("Sending Web Command\n");

			delay(3000);
			value_web_based = 253;
			printf("%d\n", value_web_based);

			delay(4000);
			outportb(PORT1, value_web_based);

			fclose(file_pointer);

			remove("D:/adtj/www/htdocs/skripsi/kdt.txt");

			printf("File Removed\n");
		}

		delay(1000);
	}
}


void web_mode()
{
	int value_web_based;
	int web_based_command;

	clrscr();
	printf("1. Activate Web Based Loop\n");
	printf("2. Exit\n");
	scanf("%d", &web_based_command);

	switch(web_based_command)
	{
		case 1 :
		value_web_based = 253;
		outportb(PORT1, value_web_based);
		web_based_loop();
		break;
		
		case 2 :
		value_web_based = 252;
		outportb(PORT1, value_web_based);
		break;
	}
	
}

void exit_program()
{
	exit(0);
}

void main()
{
	while(1)
	{
		int select_mode;

		clrscr();
		printf("Movemaster RV-M1 Interface Driver\n");
		printf("Select Mode\n");
		printf("1. Manual Mode\n");
		printf("2. Web Based\n");
		printf("3. Exit\n");
		scanf("%d", &select_mode);

		switch(select_mode)
		{
			case 1 :
			open_com_port();
			manual_mode();
			break;

			case 2 :
			open_com_port();
			web_mode();
			break;

			case 3 :
			exit_program();
			break;
		}

		getch();
	}
}


thx for the help..
Last edited on
Hello!

Isn't problem that you used slash symbol instead backslash in the path?

remove("D:/adtj/www/htdocs/skripsi/kdt.txt");

Do you use Borland c on Dos? It is possible that your proble can releated that compiler and linker...

If it is disturb you, you can use other compiler e.g. open watcom c for dos.
Topic archived. No new replies allowed.