Alternatively, send the size of the file in a "header packet" somehow.
--
Mats
Alternatively, send the size of the file in a "header packet" somehow.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
yes, sir i was just wondering why its taking so much time and realized that delay is the reason..also sir, I have one question,
If transfer can be done so easily using these commands then why use bioscom or createfile etc. commands? I mean what is the main difference?(just curious)..
Thanks
Edesign
Perhaps you'd want to use it within a 32-bit application (e.g. receive a LARGE file and store it in memory before writing anything to disk - just as an example), use higher than 38400 bps with some reliability, and not consume 100% of the CPU whilst doing it?
Also, your serial port may not be where you expect it to be - e.g. it may be a USB port in between, and it MAY be that the DOS emulation inside Windows handles that too, but it may also NOT do that. Even in the case of DOS emulation actually handling the IO, it will most likely take MUCH longer to perform this emulation process with a USB device, and the overhead is noticeable.
--
Mats
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Ok..thanks....
I got it...Now I will try using fiber optic kit that I have at my college...I hope that also work..
Thanks..all
Hello all,
I made a complete program & now suddenly I am facing a strange problem...for text files it works perfectly but for other type files it transfers 1KB & then stops..what can be the reason..
I can't find out what can go wrong...I changed everything I can think of causing the problem...Code:#include <stdio.h> #include <dos.h> #include<string.h> #include<stdlib.h> #include<conio.h> #include<limits.h> #define PORT1 0x3f8 #define PATH_MAX 512 long int length; char ch,cha; char a,c; int choice,i; void main() { void transmitfile(FILE *,long int); void receivefile(FILE *); long int sizeoffile(FILE *); char filename[PATH_MAX],filename2[PATH_MAX],buf; FILE *in,*out; clrscr(); outportb(PORT1+3,0x80); outportb(PORT1,0x03); outportb(PORT1+3,0x03); printf("\nthis computer is going to act as a:"); printf("\n 1.sender \n2.receiver\n\nEnter the choice:"); scanf("%d",&choice); char x; switch(choice) { case 1: x=getchar(); printf("enter the filename to be created:"); fgets(filename,PATH_MAX,stdin); in=fopen(filename,"rb"); length=sizeoffile(in); if(length!=NULL) printf("\n\nsending.....\n\n"); else printf("\n\nFile does not exist\n\n"); transmitfile(in,length); fclose(in); printf("Reading from the port..."); printf("writing to file %s",filename2); break; case 2: x=getchar(); printf("enter the filename to be created:"); fgets(filename2,PATH_MAX,stdin); out=fopen(filename2,"wb"); printf("Reading from the port..."); printf("writing to file %s",filename2); receivefile(out); break; default: exit(1); } getch(); } long sizeoffile(FILE *fp){ long curpos, length; curpos = ftell(fp); fseek(fp, 0L, SEEK_END); length = ftell(fp); fseek(fp, curpos, SEEK_SET); return(length); } void transmitfile(FILE *in,long int len) { long int i=0; do{ { ch=fgetc(in); do{ a=inportb(0x3fd)&0x40; }while(a!=0x40); outportb(PORT1,ch); //printf("%c",ch); i++; }while(i<len); } void receivefile(FILE *out) { do { do { c=inportb(PORT1+5)&0x01; }while(c!=0x01); cha=inportb(PORT1); //printf("%c",buf); fputc(cha,out); //delay(10); if(kbhit()) { ch=getch(); } }while(ch!=27); }
Thanks
Edesign
I don't see any reason why your code should stop after 1KB - are you sure it's exactly 1KB, or some other amount, and perhaps it makes sense to add a log-file that prints each byte sent as a hex number (using " %02x" format), for the transmit and receive sides, and see where it stops.
I'm surprised that works at all - fgets() is supposed to leave a newline in the string, and fopen() should complain about that.Code:fgets(filename,PATH_MAX,stdin); in=fopen(filename,"rb");
Ehm, NULL is meant to be used with pointers. The variable "length" is a pointer.Code:length=sizeoffile(in); if(length!=NULL)
Perhaps this belongs just after scanf(), rather than in each of the two switch statements?Code:x=getchar();
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Hello Sir,
yes..I should move it before switch..also..I will change the fgets to readline that you suggested me ...then I will check again...If I keep the printf statements uncommented it prints same garbage on both screens...I'll check once again...
Thanks,
Edesign
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
also note that main returns int - read FAQ
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
Sir there is also one more question - general
When i pass the file path as command line arguments and if the path is having space " ", then it is not able to open the file...that is c:\documents & settings\hi.txt..can't be opened..how to overcome this?
Edesign
use quotes around the path
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
You should pass the path in ""
QuantumPete
"No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
"Have you tried turning it off and on again?" - The IT Crowd
And one drawback of using an old DOS-based compiler is that it doesn't "understand" long filenames. Long filenames is anything that:
Contains a mix of lower and upper case
Contains one or more spaces.
Has more than 8 characters before the dot or more than 3 after, or more than one dot in the name.
[There are PROBABLY other things that classify as "long name" too, but those are the most common "long name" rules].
You then need to specify the filename using the "old style names". If you do dir /X it will show the names as 8.3 compliant names. Names will look like this XXXXXX~1.YYY. So your file to copy would be perhaps "c:\Docume~1\hi.txt"
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.