Specifications
CONSTRUCTION
Program Listing for PC-to-PC Communication in C
/* PROGRAM FOR LASER / IR COMMUNI-
CATION BETWEEN TWO PCs */
/* by K.S.Sankar for EFY Nov/Dec’2000 */
#include <stdio.h> /* Header Files */
#include <dos.h>
#include <conio.h>
#include<graphics.h>
#include<stdlib.h>
#define DEL 25 /* Preprocessor - Delay Vari-
able */
#define COM 0X03f8 /*0x02f8 -com2,0x03f8-
com1 */
char gra=’Y’; /* Global Variables */
int flag=0;
union REGS inregs,outregs; /* Union declara-
tion for registers */
FILE *fp; /* File declaration */
int status;
char temp=’\n’,t2;
int t1=10;
/* The Main Function */
void main(void)
{
char ch,chr,chs; /* Local Variable */
clrscr();
if(flag==0)
/* splash();*/ /* Calling Splash routine */
flag++;
textcolor(4);gotoxy(26,6);
cprintf(“INFRARED/LASER COMMUNICA-
TION”);
gotoxy(34,9);textcolor(10);
cprintf(“R”);textcolor(7);cprintf(“eceive mode”);
textcolor(14);gotoxy(35,12);
cprintf(“S”);textcolor(7);cprintf(“end mode”);
textcolor(6);gotoxy(37,15);
cprintf(“E”);textcolor(7);cprintf(“xit”);
ch = getch(); /* Select Mode */
switch(toupper(ch))
{
case ‘R’: R:clrscr();
textcolor(4);gotoxy(26,6);
cprintf(“INFRARED/LASER COMMUNI-
CATION”);
textcolor(138);gotoxy(33,9);
cprintf(“RECEIVE MODE”);
textcolor(9);gotoxy(33,12);
cprintf(“A”);textcolor(7);cprintf(“lign de-
vice”);
textcolor(11);gotoxy(33,15);
cprintf(“F”);textcolor(7);cprintf(“ile receive”);
textcolor(6);gotoxy(36,18);
cprintf(“Q”);textcolor(7);cprintf(“uit”);
chr = getch();
switch(toupper(chr))
{
case ‘A’: ralgn();break;
case ‘F’: f_rcv();break;
case ‘Q’: main();
default : clrscr();
printf(“Wrong Key Pressed”);
goto R;
}
break;
case ‘S’: S:clrscr();
textcolor(4);gotoxy(26,6);
cprintf(“INFRARED/LASER COMMUNI-
CATION”);
textcolor(142);gotoxy(36,9);
cprintf(“SEND MODE”);
textcolor(9);gotoxy(34,12);
cprintf(“A”);textcolor(7);cprintf(“lign de-
vice”);
textcolor(11);gotoxy(34,15);
cprintf(“T”);textcolor(7);cprintf(“ransfer
file”);
textcolor(6);gotoxy(38,18);
cprintf(“Q”);textcolor(7);cprintf(“uit”);
chs = getch();
switch(toupper(chs))
{
case ‘A’: salgn();break;
case ‘T’: f_snd();break;
case ‘Q’: main();
default : clrscr();
printf(“Wrong Key Pressed”);
goto S;
}
break;
case ‘E’: clrscr();
textcolor(143);
gotoxy(35,13);
cprintf(“GOOD BYE”);
exit(1);
default : clrscr();
printf(“Wrong Key Pressed”);
main();
return ;
}
}
/* Function for receive (For Device Alignment)
*/
ralgn(void)
{
char st = ‘ ‘; /* Local variables */
clrscr();
gotoxy(30,2);
textcolor(10);
cprintf(“RECEIVE MODE :”);
textcolor(9);cprintf(“ ALIGN DEVICE”);
printf(“\n”);
initial(); /* Call Initialisation routine */
loop:if(!kbhit())
{
if(st==0x04) /* Check for end of Transmis-
sion */
{
clrscr();
textcolor(140);
gotoxy(30,12);
cprintf(“ALIGNED PROPERLY”);
gotoxy(48,24);
printf(“ Press any key to quit .”);
getch();
main(); /* Got to main function after aligning
properly */
}
status = inp(0X3fd); /*Checking status at
com1 port */
if((status & 0x01)==0x00) /* Check for Data
Ready */
goto loop;
else if(!kbhit())
{
st = inp(COM); /*Get character from
com1 port till */
printf(“%c”,st); /* key hit or end of
transmission */
goto loop;
}
else
main(); /*Call main function if key hit */
}
return;
}
/*Function for File Receive */
f_rcv()
{
int flag=0,bytecount=0,count; /* Local Vari-
ables */
float ot = 0.00,nt = 0.00;
char ch,st[55000],fnm[30];
clrscr();
initial(); /*Calling Initialisation Routine */
ot = clock() / 18.2; /*Calculate exec time in
secs from start of program */
gotoxy(2,2);
printf(“ FILE NAME ? : “);
fp=fopen(gets(fnm),”wb”); /*Get file name in
write mode */
gotoxy(26,10);
printf(“(Ready for) RECEIVING DATA ....”);
gotoxy(50,24);
textcolor(138);
cprintf(“Don’t KEY IN may loss data”);
loop: nt = clock()/18.2; /*Calculate exec time in
secs from start of
program */
status = inp(0X3FD);/*Get character from
com1 port */
if((status & 0x01)==0x00) /* Check for Data
Ready */
{
/* Check for no data reception for five seconds
after
start of reception if no data is received con-
tinue other process */
if((bytecount>0) && (nt-ot)>5.0)
{
clrscr();
for(count=0;count<flag;count++)
{
gotoxy(26,10);
textcolor(11);
cprintf(“ Saving data in”);
gotoxy(43,10);
textcolor(12);
cprintf(“ %s”,fnm);
/*Dump the data received in a File */
fprintf(fp,”%c”,st[count]);
}
fclose(fp);
gotoxy(26,13);
textcolor(11);
cprintf(“ File %s of %d bytes created
“,fnm,count);
gotoxy(50,24);
textcolor(7);
178