Add to Favorites    Make Home Page 1462 Online  
 Language Categories  
 Our Services  

Home » C Home » Hardware Interaction Through C Home » file transfer between two computers using communication ports.

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title file transfer between two computers using communication ports.
Author sanjoy saha and avik debnath
Author Email sanjay432 [at] indiatimes.com
Description To transfer text and html files between two computers using three wire connections between com ports.a little modification can also transfer image and multimedia files.
Category C » Hardware Interaction Through C
Hits 397403
Code Select and Copy the Code
#include<stdio.h> #include<conio.h> #include<process.h> #include<dos.h> #include<graphics.h> #include<start.h> void baudset(long); void comparm(int,int,int); int port_address; union REGS i,o; void main() { int gd=DETECT,gm,maxx,maxy,x,y,button,ex=1,c,v=1,run=1; FILE *f; char chr; char *fname; int result,status,choice,port; unsigned int fstat,mstat,lstat; st(); while(1) { initgraph(&gd,&gm," "); cleardevice(); maxx=getmaxx(); maxy=getmaxy(); setbkcolor(9); if(run==1) { gotoxy(32,1); printf("PORT INACTIVE"); run++; } else { gotoxy(32,1); printf("PORT ACTIVATED"); } choice=0; rectangle(0,20,maxx,maxy); setviewport(1,5,maxx-1,maxy-1,1); if(initmouse()==0) { closegraph(); restorecrtmode(); outtextxy(100,100,"mouse driver not loaded"); exit(1); } restrictmouseptr(1,20,maxx-1,maxy-1); showmouseptr(); setcolor(6); outtextxy(115,30,"PROGRAM TO TRANSFER FILES BETWEEN TWO COMPUTERS"); setcolor(3); outtextxy(430,45,"ver 1.0 "); setcolor(14); outtextxy(170,45,"Sanjoy Saha & Avik Debnath"); setcolor(10); outtextxy(200,100,"1 : SEND FILE"); outtextxy(200,120,"2 : RECIEVE FILE"); outtextxy(200,140,"3 : EXIT"); outtextxy(200,175,"enter your choice (1,2 or 3)::"); rectangle(195,95,210,110); rectangle(195,115,210,130); rectangle(195,135,210,150); setcolor(13); outtextxy(20,450,"PRESS 'F1' TO ACTIVATE THE PORTS"); setcolor(9); while(v==1) { if(kbhit()) { chr=getch(); if(chr==0) { chr=getch(); c=(int)chr; if(c==59) { gotoxy(31,1); printf("PORT ACTIVATED"); v=2; break; } } } } while(ex==1) { getmousepos(&button,&x,&y); gotoxy(5,1); (button & 1)== 1 ? printf("DOWN"):printf("UP"); gotoxy(20,1); (button & 2) == 2 ? printf("DOWN"):printf("UP"); gotoxy(65,1); printf("X=%03d Y=%03d",x,y); if((button & 1)==1) { if((x>=195 && x<=210) && (y>=95 && y<=110)) { choice=1; } if((x>=195 && x<=210) && (y>=115 && y<= 130)) { choice=2; } if((x>=195 && x<=210) && (y>=135 && y<=150)) { choice=3; } } if(choice==1 || choice==2 || choice==3) goto sos; if(kbhit()) { goto sob; } } fflush(stdin); sob: gotoxy(60,12); scanf("%d",&choice); sos: switch(choice) { case 1: { setcolor(12); outtextxy(10,205,"select port (1: com1 2: com2) ::"); rectangle(470,200,485,215); rectangle(510,200,525,215); outtextxy(474,203,"1"); outtextxy(514,203,"2"); gotoxy(50,14); scanf("%d",&port); if(port==1) port_address=0x3F8; else port_address=0x2F8; baudset((long)2400); comparm(0,1,8); outport(port_address+4,1|2); outtextxy(10,240,"enter the name of file to be sent::"); gotoxy(50,16); scanf("%15s",&fname); f=fopen(&fname,"r"); if(f==NULL) { setcolor(4); outtextxy(10,300,"*** file do not exist ***"); setcolor(6); outtextxy(10,320,"hit any key to continue........"); getch(); break; } closegraph(); restorecrtmode(); clrscr(); textcolor(2); for(;;) { if(kbhit()) { if(getch()==27) break; } lstat=inportb(port_address+5); if(!(lstat & 32)) continue; else { chr=fgetc(f); } if(chr==EOF) { cprintf("FILE TRANSMITTED "); outportb(port_address,EOF); getch(); break; } outportb(port_address,chr); putchar(chr); } fclose(f); break; } case 2: { setcolor(12); outtextxy(10,205,"select port (1: com1 2: com2) ::"); gotoxy(50,14); scanf("%d",&port); if(port==1) port_address=0x3F8; else port_address=0x2F8; baudset((long)2400); comparm(0,1,8); outportb(port_address+4,1|2); textcolor(4); outtextxy(10,240,"save as file name::"); gotoxy(50,16); scanf("%15s",&fname); f=fopen(&fname,"w"); if(f==NULL) { setcolor(4); outtextxy(10,300,"*** cannot open file ***"); break; } closegraph(); restorecrtmode(); clrscr(); textcolor(4); cprintf("waiting for i/p "); textcolor(7); cprintf("press esc for exit "); gotoxy(1,4); for(;;) { if(kbhit()) { if(getch()==27) break; } fstat=inportb(port_address+5); if(fstat & 2) cprintf("over run time error "); if(fstat & 4) cprintf("parity error"); if(fstat & 8) cprintf("framing error "); if(fstat & 16) cprintf("break recieved "); if(!(fstat & 1)) continue; chr=inportb(port_address); if(chr==EOF) { textcolor(2); cprintf("FILE RECIEVED "); exit(0); } putchar(chr); fputc(chr,f); } outportb(port_address+4,0); fclose(f); break; } case 3: exit(0); default: sound(900); delay(10000); nosound(); break; } } } void baudset(long baudrate) { unsigned int divisor; unsigned char lsb,msb; divisor=1152001/baudrate; msb=divisor>>8; lsb=(divisor<<8)>>8; outportb(port_address+3,128); outportb(port_address,lsb); outportb(port_address+1,msb); } void comparm(int parity,int stop,int databit) { int parmbyte; parmbyte=databit-5; if(stop==2) parmbyte|=4; if(parity!=0) parmbyte|=8; if(parity==2) parmbyte|=16; outportb(port_address+3,parmbyte); } /* MOUSE WORK */ initmouse() { i.x.ax=0; int86(0x33,&i,&o); return(o.x.ax); } showmouseptr() { i.x.ax=1; int86(0x33,&i,&o); } restrictmouseptr(int x1,int y1,int x2,int y2) { i.x.ax=7; i.x.cx=x1; i.x.dx=x2; int86(0x33,&i,&o); i.x.ax=8; i.x.cx=y1; i.x.dx=y2; int86(0x33,&i,&o); } getmousepos(int *button,int *x,int *y) { i.x.ax=3; int86(0x33,&i,&o); *button=o.x.bx; *x=o.x.cx; *y=o.x.dx; }

Related Source Codes

Script Name Author
The Game Opposite as seen on Nokia 2300 Mobile Manikanta
RECURSIVE BALANCED QUICK SORT ashish
Radix Sort ashish
Change your mouse pointer Ashim
The blinking star Shashank
Data Validation Crylittlebaby
To search a file by giving file type like mp3 or mpeg or doc Prashanth SR
Menus Demonstration B.Chidhambaram
Employee Database Project Using C. Reenku Raman Nayak
Creating a Lexical Analyzer in c fahad bader al-buhairi �դ ?�� ��??���
Calendar Program Omkar & Devendra
Stop double Process for start in C Cedrik Jurak
Stop double Process for start in C Cedrik Jurak
Time Scheduler Atiq Anwar
A timepass game between atmost two players Rahul Roy

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=698


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review