Home › Forums › C Programming › Communcation between 2 pcs using port
- This topic has 1 reply, 2 voices, and was last updated 18 years, 8 months ago by msaqib.
Viewing 1 reply thread
- AuthorPosts
- February 23, 2005 at 10:50 pm #1883JAZYY18Participant123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314<br />/* Communcation between 2 pcs using port */<br />#include<stdio.h><br />#include<conio.h><br />#include<process.h><br />#include<dos.h><br />#include<graphics.h><br />#include<start.h><br />void baudset(long);<br />void comparm(int,int,int);<br />int port_address;<br />union REGS i,o;<br />void main()<br />{<br />int gd=DETECT,gm,maxx,maxy,x,y,button,ex=1,c,v=1,run=1;<br />FILE *f;<br />char chr;<br />char *fname;<br />int result,status,choice,port;<br />unsigned int fstat,mstat,lstat;<br />st();<br />while(1)<br />{<br />initgraph(&gd,&gm," ");<br />cleardevice();<br />maxx=getmaxx();<br />maxy=getmaxy();<br />setbkcolor(9);<br />if(run==1)<br />{<br />gotoxy(32,1);<br />printf("PORT INACTIVE");<br />run++;<br />}<br />else<br />{<br />gotoxy(32,1);<br />printf("PORT ACTIVATED");<br />}<br />choice=0;<br />rectangle(0,20,maxx,maxy);<br />setviewport(1,5,maxx-1,maxy-1,1);<br />if(initmouse()==0)<br />{<br />closegraph();<br />restorecrtmode();<br />outtextxy(100,100,"mouse driver not loaded");<br />exit(1);<br />}<br />restrictmouseptr(1,20,maxx-1,maxy-1);<br />showmouseptr();<br />setcolor(6);<br />outtextxy(115,30,"PROGRAM TO TRANSFER FILES BETWEEN TWO COMPUTERS");<br />setcolor(3);<br />outtextxy(430,45,"ver 1.0 ");<br />setcolor(14);<br />outtextxy(170,45,"Sanjoy Saha & Avik Debnath");<br />setcolor(10);<br />outtextxy(200,100,"1 : SEND FILE");<br />outtextxy(200,120,"2 : RECIEVE FILE");<br />outtextxy(200,140,"3 : EXIT");<br />outtextxy(200,175,"enter your choice (1,2 or 3)::");<br />rectangle(195,95,210,110);<br />rectangle(195,115,210,130);<br />rectangle(195,135,210,150);<br />setcolor(13);<br />outtextxy(20,450,"PRESS 'F1' TO ACTIVATE THE PORTS");<br />setcolor(9);<br />while(v==1)<br />{<br />if(kbhit())<br />{<br />chr=getch();<br />if(chr==0)<br />{<br />chr=getch();<br />c=(int)chr;<br />if(c==59)<br />{<br />gotoxy(31,1);<br />printf("PORT ACTIVATED");<br />v=2;<br />break;<br />}<br />}<br />}<br />}<br />while(ex==1)<br />{<br />getmousepos(&button,&x,&y);<br />gotoxy(5,1);<br />(button & 1)== 1 ? printf("DOWN"):printf("UP");<br />gotoxy(20,1);<br />(button & 2) == 2 ? printf("DOWN"):printf("UP");<br />gotoxy(65,1);<br />printf("X=%03d Y=%03d",x,y);<br />if((button & 1)==1)<br />{<br />if((x>=195 && x<=210) && (y>=95 && y<=110))<br />{<br />choice=1;<br />}<br />if((x>=195 && x<=210) && (y>=115 && y<= 130))<br />{<br />choice=2;<br />}<br />if((x>=195 && x<=210) && (y>=135 && y<=150))<br />{<br />choice=3;<br />}<br />}<br />if(choice==1 || choice==2 || choice==3)<br />goto sos;<br />if(kbhit())<br />{<br />goto sob;<br />}<br />}<br />fflush(stdin);<br />sob: gotoxy(60,12);<br />scanf("%d",&choice);<br />sos: switch(choice)<br />{<br />case 1: {<br />setcolor(12);<br />outtextxy(10,205," select port (1: com1 2: com2) ::");<br />rectangle(470,200, 485,215);<br />rectangle(510,200, 525,215);<br />outtextxy(474,203, "1");<br />outtextxy(514,203, "2");<br />gotoxy(50,14);<br />scanf("%d",&po rt);<br />if(port==1)<br />port_address =0x3F8;<br />else<br />port_address =0x2F8;<br />baudset((long)2400 );<br />comparm(0,1,8);<br />outport(port_addre ss+4,1|2);<br />outtextxy(10,240," enter the name of file to be sent::");<br />gotoxy(50,16);<br />scanf("%15s",& fname);<br />f=fopen(&fname ,"r");<br />if(f==NULL)<br />{<br />setcol or(4);<br />outtex txy(10,300,"*** file do not exist ***");<br />setcol or(6);<br />outtex txy(10,320,"hit any key to continue........");<br />getch( );<br />break;<br />}<br />closegraph();<br />restorecrtmode();<br />clrscr();<br />textcolor(2);<br />for(;;)<br />{<br />if(kbh it())<br />{<br />if(getch()==27)<br />break;<br />}<br />lstat= inportb(port_address+5);<br />if(!(l stat & 32))<br />continue;<br />else<br />{<br />chr=fgetc(f);<br />}<br />if(chr ==EOF)<br />{<br />cprintf("FILE TRANSMITTED");<br />outportb(port_address,EOF);<br />getch( );<br />break;<br />}<br />outpor tb(port_address,chr);<br />putcha r(chr);<br />}<br />fclose(f);<br />break;<br />}<br />case 2: {<br />setcolor(12);<br />outtextxy(10,205," select port (1: com1 2: com2) ::");<br />gotoxy(50,14);<br />scanf("%d",&po rt);<br />if(port==1)<br />port_address=0x3F8 ;<br />else<br />port_address=0x2F8 ;<br />baudset((long)2400 );<br />comparm(0,1,8);<br />outportb(port_addr ess+4,1|2);<br />textcolor(4);<br />outtextxy(10,240," save as file name::");<br />gotoxy(50,16);<br />scanf("%15s",& fname);<br />f=fopen(&fname ,"w");<br />if(f==NULL)<br />{<br />setcolor(4);<br />outtextxy(10 ,300,"*** cannot open file ***");<br />break;<br />}<br />closegraph();<br />restorecrtmode();<br />clrscr();<br />textcolor(4);<br />cprintf("waiting for i/p");<br />textcolor(7);<br />cprintf("press esc for exit");<br />gotoxy(1,4);<br />for(;;)<br />{<br />if(kbh it())<br />{<br />if(getch()==27)<br />break;<br />}<br />fstat= inportb(port_address+5);<br />if(fst at & 2)<br />cprint f("over run time error");<br />if(fst at & 4)<br />cprint f("parity error");<br />if(fst at & 8)<br />cprint f("framing error");<br />if(fst at & 16)<br />cprint f("break recieved");<br />if(!(f stat & 1))<br />continue;<br />chr=in portb(port_address);<br />if(chr ==EOF)<br />{<br />textcolor(2);<br />cprintf("FILE RECIEVED");<br />exit(0);<br />}<br />putcha r(chr);<br />fputc( chr,f);<br />}<br />outportb(port_address+4,0);<br />fclose(f);<br />break;<br />}<br />case 3: exit(0);<br />default: & ;nbs p; sound(900);<br />delay(10000);<br />nosound();<br />break;<br />}<br />}<br />}<br /><br />void baudset(long baudrate)<br />{<br />unsigned int divisor;<br />unsigned char lsb,msb;<br />divisor=1152001/baudrate;<br />msb=divisor>>8;<br />lsb=(divisor<<8)>>8;<br />outportb(port_address+3,128);<br />outportb(port_address,lsb);<br />outportb(port_address+1,msb);<br />}<br /><br />void comparm(int parity,int stop,int databit)<br />{<br />int parmbyte;<br />parmbyte=databit-5;<br />if(stop==2)<br />parmbyte|=4;<br />if(parity!=0)<br />parmbyte|=8;<br />if(parity==2)<br />parmbyte|=16;<br />outportb(port_address+3,parmbyte);<br />}<br />/* MOUSE WORK */<br />initmouse()<br />{<br />i.x.ax=0;<br />int86(0x33,&i,&o);<br />return(o.x.ax);<br />}<br /><br />showmouseptr()<br />{<br />i.x.ax=1;<br />int86(0x33,&i,&o);<br />}<br /><br />restrictmouseptr(int x1,int y1,int x2,int y2)<br />{<br />i.x.ax=7;<br />i.x.cx=x1;<br />i.x.dx=x2;<br />int86(0x33,&i,&o);<br />i.x.ax=8;<br />i.x.cx=y1;<br />i.x.dx=y2;<br />int86(0x33,&i,&o);<br />}<br /><br />getmousepos(int *button,int *x,int *y)<br />{<br />i.x.ax=3;<br />int86(0x33,&i,&o);<br />*button=o.x.bx;<br />*x=o.x.cx;<br />*y=o.x.dx;<br />}<br />
- April 11, 2006 at 6:46 am #3138msaqibParticipant
No description for the code?
Also i could not run the code as it says can not find the header file start.h.
Can you please write the brief description so that I can use this program.
Thanks
Saqib
- AuthorPosts
Viewing 1 reply thread
- The forum ‘C Programming’ is closed to new topics and replies.