Вы находитесь на странице: 1из 51

C Program for file transfer through infra red media

DEPARTMENT OF TECHNICAL EDUCATION

SRI JAYACHAMARAJENDRA (GOVT.) POLYTECHNIC


(An Autonomous Institution)
Sheshadri Road, K.R.Circle, Bangalore-560001

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

CERTIFICATE

Certified that the project work entitled “C Program to File Transmission


Through IR-Component Connect to RS-232” is a bonafied work carried out
successfully by Jagadish.T.S (A04CS19), in Partial fulfillment for the award
of

DIPLOMA IN COMPUTER SCIENCE & ENGINEERING


Prescribed by the
„ACADEMIC COUNCIL, S.J.(Govt.) POLYTECHNIC‟
(Approved by the Board of Technical Education.)
during the year 2006-2007

Project Guide Head Of the Department Principal


(Smt. Thulasi .M.B) (Smt.Gayathri.V) (Sri.S.R.Murthy)
Sr. Grade Lecturer

Date:
Place: Bangalore.

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

The satisfaction & happiness that accompanies the successful completion of


any task would be incomplete without mention of the people who made it possible,
whose constant guidance & encouragement crown all efforts with success.
First of all we have great pleasure in expressing our heartful gratitude to our
esteem Principal, Sri S.R.Murthy and also to our Head of the Department, Smt.
V.Gayathri, to carry out the project successfully and for their untiring zeal, which
constantly inspired me during the completion of this project.
We express our deep sense of gratitude to our guide Smt. M.B.Thulase for her
guidance throughout the project. We would also like to express our sincere thanks to
Smt. Usharani madam, Mr. Mahadevaiah Sir, Smt. Kavitha madam for their support
and timely co-operation throughout this project.
We once again thank one and all whose guidance and contributions proved to
be extremely helpful in completion of this project. Special thanks to all the staff of the
laboratories for helping during the long hours of stay at the labs.
Last but not least, thanks are due to our friends and parents.

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

CONTENTS

 SYNOPSIS

 INTRODUCTION

 ABOUT COMMUNICATION SYSTEM.

 ABOUT INFRARED TECNOLOGY

 NETWORKING GOALS

 ABOUT HARDWARE

 ABOUT SOFTWARE

 CODE

 OUTPUT

 FEATURES

 ADVANTAGES

 CONCLUSION

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

SYNOPSIS

This project would be the first step in achieving the WIRELESS


NETWORKING (opto networking) which is revolutionizing the field of Computer
networking and the application like wireless mouse and keyboard work on the above
principle.
This project will be capable of transferring files from one system to another by
means of simple optical linking. The optical linking is provided by an hardware
module which will be present in both the PC‟s. The module is a combination of IR
LED and IR DETECTOR.
Each of the two modules are interfaced to the PCs with an RS 232 standard,
trough the serial port. These modules from the front end and the back end of the two
communication entities (system). Each module consists of a level shifter (MAX 232
IC), which is a carrier wave generator for the INTENSITY MODULATION of the IR
light generated by the transceiver and IR detector.
This project is expected to work satisfactorily for a distance of up to 40 feet
and the coverage area can be improved with additional LEDs.
Besides the hardware modules, a C - program involving file manipulating
functions would be written to make the system more user friendly.

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

INTRODUCTION
There is always a need to transfer or share information from one computer to
other. This is done in two ways.
Firstly, the data is transferred to a portable storage medium like floppies, CD‟s
etc and then copied to a target system.
Secondly, both the system are linked through a cable and data is transferred
either in serial or parallel mode.
The prototype model developed in this project the data from one pc to other pc
without any cable connection between them.
The term Communication refers to sending, receiving and processing of
information by electronic means. Communication started with Wire Telegraphy in the
1840s, developing with telephony some decades later and radio at the beginning of
this century. Communication subsequently became even more widely used and
refined through the invention and use of transistors, integrated circuits and other
semiconductor devices. Thus a communication System has tree basic components.
1. Transmitter
A transmitter is equipment, which converts a physical message into an
electrical message
2. Receiver
A receiver on the other hand is equipment, which converts the
electrical signal back to the physical signal.
3. Channel
The electrical signal from transmitter is conveyed to file receiver through
the channel.
This project basically deals with communication between Computers i.e.
transferring data between two computers using infrared beam.

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

About communication System:


In modem age communication systems, computers are used broadly. The
technology development in the software field has given a boost in the communication
to implement complex and diversely featured communication systems. With the
information technology jump the communication and computer industries are merged
together and resulting advanced technologies, which comprise services of both
computers and communication systems.
The most advanced communication technology is computer networking
computer network is the interconnection of autonomous computers. Autonomous
computers are the computers, which have their own hardware and software and don‟t
depend on any other unit for processing works.
On the basis of area covered, computer networks are distinguished in three
categories.
1. Local Area Network[LAN]
2. Metropolitan Area Network[MAN]
3. Wide Area Network[WAN]

LOCAL AREA NETWORKS:


Local area networks are privately owned networks with in a single campus of
up to a few kilometers in size. They are widely used to connect personal computers
and work attains in company offices and factories to share resources and exchange
information.
They are the simplest form of networks, which often use a transmission
technology consisting of a single cable to which all the machines are attached.
Traditional speed of LANs is 10-100Mbps.

METROPOLITAN AREA NETWORKS:


A metropolitan area network is basically a bigger version of LAN and
normally used a similar technology.
It might cover a group of nearby corporate offices or a city and might be
either private or public.It can support both data and voice. A MAN just has one or two
cables and does not contain switches, which shunt packets.

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

WIDE AREA NETWORKS:


A Wide area network spans a large geographical area of a Country or
Continents. It contains a collection of machines intended for running application
programs. The most WAN consist of two distinct components: transmission lines and
switching elements. Switching elements are specialized computers used to connect
two or more transmission lines. The INTERNET comes under this category.
Depending on the transmission media the computer networks are categorized in two
ways. They are as follows:

1. Solid transmission lines computer networks.


2. Wireless computer networks.

The computer networks, in which the transmission media used is cables, wires
or optical fibers, comes in the category of solid transmission line computer network.
The attenuation using solid transmission line is more than that of wireless
transmission. The systems become expensive due to large number of repeaters for
large distances.
The alternative, wireless communication, is cheaper and more efficient as the
media is cost free. The new tech communication systems are adopting this technology
due to its very advantages. The bandwidth available is infinite and thus giving room
for a lot of channels to frequency multiplexed. Less number of repeaters are required
than that of wire communication thus reducing the maintenance cost. Wireless LANs
are easy to install as compared to wired networks. On contrary, they require complex
electronics circuitry and antennas. They have the capacity of 1-2 Mbps, which is
much slower than wired LAN. The error rates are often much higher.

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

DATA TRANSMISSION TECHNIQUES


All communication system are divided into two categories on basis of method
of transmission data bits. They are
1. Parallel Transmission
2. Serial Transmission

Parallel Transmission:
In parallel data transmission each bit of message has its own path and the total
message is transmitted at the same time.
This means that an n-bit message must be transmitted through n separate
conductor paths.
Parallel transmission is faster but requires many wires. It is used for short
distances and where speed is important, if a system has n parallel transmission lines
then it will more than n times faster than that of serial transfer.
For example in computers, parallel data transfer scheme is used for fast
processing. The deciding feature of speed of any microprocessor is number of data
lines in it and the clock frequency. The data lines are actually parallel conductor‟s
paths, which makes the parallel communication channel in computer architecture.

Serial Transmission:
In serial data transmission each bit in message is sent in sequence one at a time.
This method requires use of one pair of conductors or one conductor and a common
ground.
Serial transmission is slower but is less expensive since if requires only one pair of
conductors.
For example, all Public Telephone Networks are used for serial transmission of data
as the transmission path length is very from few meters to many kilometers. All
computer networks use serial transmission technique as it requires less out system
space and is cheap.
Although this makes the speed slower but the advantages out weights the
disadvantages. In account of load offered by any network, serial transmission is
capable of handling the load with bearable failures and sufficient efficiency.

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

RS–232 SPECIFICATIONS
RS–232 is a “complete” standard. This means that the standard sets out to
ensure compatibility between the host and peripheral systems by specifying
1) Common voltage and signal levels,
2) Common pin wiring configurations, and
3) A minimal amount of control information between the host and peripheral systems.

Unlike many standards which simply specify the electrical characteristics of a


given interface, RS-232 specifies electrical, functional, and mechanical characteristics
in order to meet the above three criteria.

NETWORKING GOALS.
1. RESOURCE SHARING:
Computer network provides shared access to resources (program or data) to
everyone on the network.

2. HIGHLY RELIALIBILITY:
A second goal is to provide high reliability by having alternative source of
supply. For example, files could be stored on two or more machines on the
network. Even if one machine fails due to hardware problem, the files can be
retrieved from other machines and work can progress.

3. COMMUNICATION MEDIUM:
A computer network provides a powerful communication medium among
widely separated people.

ABOUT INFRARED TECNOLOGY:


Infrared data communication is a mode of communication that plays an
important role in wireless data communication.
The infrared data association [IRDA] was established in1993 to create and
maintain international standards for the hardware & software used in infrared
communication links.
Infrared is simply an invisible light .It has all the properties of visible light
except that our eyes can‟t see it.
In infrared data communication, a focused ray of light in the infrared
frequency is modulated with information and sent from a transmitter to a receiver.
The communication between the devices requires each has a transceiver (a
combination of a transmitter and a receiver) in order to communicate however a
devices may also require further specialized software allowing communication to be
synchronized. One of the examples of this is the design support that is in Microsoft
windows as operating system.
Infrared uses either directed (line-of-sight) or diffuse technology.

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

VOLTAGE LEVEL CONVERTER(MAX 232):


For converting the voltage level of serial output of computer (TTL/CMOS
levels) of 9v to interfacing circuit compatible levels 0/5v we have used the IC
MAX232 which is a bi-directional voltage converter. The internal description is
shown in Figure 3
A MAX232 is a lever converter driver chip basically called a charge pump.
The chip requires four capacitors to help it build up 10 volts that it can communicate
with a PC serial port on the outbound side. On the other side of the chip, you must
have a micro-processor or some sort of serial input usually from some find of logic
circuit. The chip is typically powered by a 5v dc regulated supply.

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

MODULATOR AND TRANSMITTER (555 timer):


The modulator used in the circuit is astable multivibrator using 555 timer. The
duty cycle is set to 25% and it generates square waves of 38 kHz, which modulates
the signal to be transmitted. The NE555 silicon monolithic timing circuit is a highly
stable controller capable of producing accurate time delays, or oscillation. In the time
delays, mode of operation, one external resistor and capacitor precisely control the
time.
The block diagram and pin diagram of 555timer is shown in figure.

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

9-PIN ‘D’ Connector:

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

RECEIVER (IR RXR MODULE):


To receiver the infrared signals we have used IR RXR Module, which senses
the infrared signals and generates corresponding voltages.

COMPONENT DESCRIPTION
The component as an interfacing circuit facilitating the convert the electrical
signals in to infrared radiation with modulating unit. Detailed description of the
interfacing unit is presented below based on the interfacing, circuit diagram shown in
Figure 2.
The interfacing unit consists of following main parts:
1. 9 pin „D‟ connector.
2. Voltage level converter[IC MAX232]
3. Modulator and transmitter [555 timer in Astable Mode]
4. Receiver [Infrared RXR Module]

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

WORKING OF HARDWARE :
Transmitter:
Data singles transmitted through pin 3 of 9 pin „D‟ connector of RS 232 COM
1 port are sent to pin 8 of MAX 232 and it converts these EIA( Electronics Ind ustry
Association) RS232 compatible levels of 9 volts to 0/5 TTL levels as given in table 1.
The output pin of MAX 232 TC (pin no. 9) drives the BC 547 npn transistor and
powers the base of transistor. Now, depending on the input at pin 8 of IC MAX232,
the transistor goes in active region or in cutoff. Let us take this one by one.
1. With input at pin 8 is +9v:
The output at pin 9 of MAX232 will be 0v and thus the transistor T1 will be in
cutoff. This supply voltage (+5v) will thus appear on collector of trans istor T1 and
the 555 timer will reset as collector is connected to pin 4 of 555 timer (reset pin). This
output thus goes to logic 1 at pin 3 of 555 timer and IR LEDs will glow.
2. With input at pin 8 is -9v:
The output in this case on pin 9 of MAX232 will be +5 volts thus driving the
transistor T1 in active region. The voltage at pin 4 of 555 timer will goes to zero and
output at pin 3 of 555 timer goes low thus the LEDs will not glow. The electrical
pulses send by the COM port are now converted into corresponding modulated pulses
of IR light.
The a stable multivibrator is set to generate square wave of 38 kHz as the IR
module used in the circuit is tuned to 38 kHz. The range of 38kHz is widely used in
practical purposes as most Television remote controls operates on this frequency thus
providing extra tool for testing.

Receiver:
A visible LED 1 at pin 7 of Max 232 IC indicates that the signals are being
received. Pin is also connected to pin2 (receiving pin) of 9-pin(or pin 3 of 25 pin) „D‟
connector used for the serial port in the PC so that the data may be read. The optical
signals received by the IR Module are in fact converted to the electrical pulses and
both PCs „think‟ that there is a null modem cable connected between them in some
PCs the serial port is terminated it to a 9 pin „D‟ connector and in some others in to a
25 pin „D‟ connector.
The module used works in active low and thus when receives TR radiation
gives output low. With low logic at base of transistor T2 the emitter of it will be at
low voltage level voltage and then the received low voltage signal is converted into
+9 voltage level by IC232.
When there is no IR radiation on the module it gives high output. With high
logic at base of transistor T2 the emitter of it will be at high voltage level and then the
received high voltage signal is converted into -9 voltage level by IC232.

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

File transfer using com port


This program written in Turbo C uses the pc‟s serial port, also known as com
port or RS-232, to transfer files between two computers. The hard ware used is quite
simple and economical, as only 3-core cable with 9-pin D connectors on either side is
required to connect the infrared module which consists of some electronic
components and the MAX232 IC and 555 IC .

COM port communication basics


Data communication equipment (DCE) and data terminal equipment (DTE)
use serial cables for communication. Examples of data communication equipment and
data terminal equipment are modems & computers (or terminals), respectively.
To connect the two computers (DTE‟S) together, we can use the null-modem
configuration. The Wiring diagram for the null – modem configuration is shown in
Fig 1. The signal details on the 9-pin‟D‟ connector are given in Table 1.
In null – modem configuration, only three wires are required (TD, RD, and
SG) to connect the ports. Thus it is more cost effective for long cable runs.
In this wiring configuration a computer thinks that it is talking to a modem
rather than another computer. Any data transmitted from one computer must be
received by the other, so TD pin of first PC is connected to RD pin of the other PC.
The second PC also must have a similar set up. Thus its TD pin is connected to RD
pin if the former computer. Signal ground (SG) pins of both the PC‟s must be
connected together, so that the ground forms the common reference for the RS-232C
signals from to each computer.
The data terminal ready (DTR) signal is looped back to data set ready (DSR)
and carrier detect (CD) on both the computers. Hence when DTR is active, DSR and
CD immediately become active. The computer now thinks the configuration to which
it is connected is that of a virtual modem in ready state. When the computer has to
send data , it makes request –to –send (RTS) high .As this signal is looped back to the
computer‟s own clearance -to-send (CTS) signal pin, the computer immediately gets
a reply that it‟s okay to send .We„ve not used the ring indicator (pin 9) as it is not
required in this configuration.

Programming for communication


There are two methods for writing the program, namely, polling method and
interrupt method.
Polling method – In this method, the UART is repeatedly checked for any new data
in it‟s receive buffer.
Interrupt method- An interrupt handler is used to remove the data from the UART
when an interrupt is generated.

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

The port base address and IR’s for com ports are as follows:
Name Address IR Int (Hex)
COM1 3F8 4 0C
COM2 2F8 3 0B
COM3 3E8 4 0C
COM4 2E8 3 0B
We use inport ( ) and outport ( ) instructions to read and write to the registers
used for serial communication. Various registers with their addresses (related to their
port base addresses) are shown in table II .Though there are only eight addresses , we
are able to control twelve registers by using divisor latch –enable bit (DLAB) , i.e.,
bit 7 of the line control register. Bit functions of the line control register are shown in
TableIII.

UART settings
As the computer works with data in parallel form, we need the serial
transmission converted back to parallel format so that data could be used .This can be
done using universal asynchronous receiver transmitter (UART) chip.
In order to use the UART, we first need to make certain register settings. The
sequential steps for polling method are given below:
1. Stop interrupts generation on the UART, so that the UART doesn‟t interrupt the
initialization.
2. Now the interrupt vector is set.
3. The next step is to set the speed at which the communication takes place. This is
done by setting bit 7 (DLAB) of the LCR (refer TableIII) to logic 1, so as to have
an access to divisor latch high and low bytes. Some common baud rates and the
corresponding hex values we used to set the high & low bytes are shown in table
iv .(Baud rates are based on the assumption that the UART utilizes a 1.832 MHz
crystal , which is divided by 16 inside the UART to obtain basic baud rate of
115,200 bits/sec.)
4. Then we set the divisor latch -low byte in the registers as per the address shown in
TableII.
5. The next step is to reset /turn off the divisor latch access bit (DLAB) and set the
word length and parity in the LCR .Here we‟ve selected the word length as 8 bits,
no parity, and one stop bit. This is done by moving 0x03 to the line control
register .As this will also turn off the LAB, we can access the interrupt enable
register and receiver and transmitter buffers.
6. Now the FIFO buffers are turned „on‟ and cleared.
7. DTR, RTS, and OUT 2 are made high in modem control register.

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

Running the program


The following steps need to be taken before running the program:
1. Connect both the computers via their com ports.
2. Use the correct com port address at the respective computers. One easy way to
determine this is using a loop back plug with connections as shown in figure.2 .It
has the same configuration as that of a null-modem, but only one computer is used
in this configuration with its TD pin 3 shorted to RD pin 2 .In this configuration,
the computer receives what it sends.
3. It is better to run this program in DOS mode .So, if required, shut down windows
and restart in DOS mode before execution.

COMPUTER A COMPUTER B
PIN SIG. SIG. PIN
3 TD RD 2
2 RD TD 3
5 SG SG 5
4 DTR DTR 4
6 DSR DSR 6
1 CD CD 1
7 RTS RTS 7
8 CTS CTS 8
9 RI RI 9

Wiring for the null -modem configuration

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

TABLE I
D-Type 9-Pin Connector Details
D-Type 9-Pin No. Abbreviation Full Name
Pin3 TD Transmit data
Pin2 RD Receive data
Pin7 RTS Request to send
Pin8 CTS Clear to send
Pin6 DSR Dataset ready
Pin5 SG Signal ground
Pin1 CD Carrier detect
Pin 4 DTR Data terminal ready
Pin9 RI Ring indicator
TD – This pin is used to send the data.
RD – This pin is used to receive data.
RTS - Used in modem communication, this pin tells that the UART
Is ready to send data.
CTS- It indicates that the modem is ready to exchange data.
DSR- It tells the UART that the modem is ready to establish a link.
SG- Signal ground.
CD - This pin is high when the modem detects a carrier from the
Modem at the other end of the phone.
DTR- It tells the modem that the UART is ready to link.
RI- This pin is high when the modem receives a ring from the public
Switched telephone network (PSTN).

TABLE II
Registers With Their Addresses
Base address DLAB* Read/Write Abbreviation Register name
+0 =0 Write ---- Transmitter holding buffer
+0 =0 Read ---- Receive buffer
+0 =1 Read/ Write ---- Device latch-low byte
+1 =0 Read/ Write IER Interrupt enable register
+1 =1 Read/ Write ---- Device latch-high byte
+2 --- Read IIR Interrupt Identification register
+2 --- Write FCR FIFO control register
+3 --- Read/Write LCR Line control register
+4 --- Read/ Write MCR Modem control register
+5 --- Read LSR Line status register
+6 --- Read MSR Modem status register
+7 --- Read/ Write ---- Scratch register
*DLAB- Divisor latch access bit

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

/* This is a program to transfer the file,


receive the text file and chat between the two
computers, using the infra red module connected
to the RS-232 port on the each computer */

#include<io.h>
#include<graphics.h>
#include<stdlib.h>
#include<ctype.h> //for toupper
#include<time.h> //for clock
#include<string.h>
#include<conio.h> //for
getch,putch,textcolor...
#include<bios.h> //for bioscom
#include<stdio.h> //for file functions
#include<dos.h> //for
delay,inport,outport...

#define SETTINGS ( 0x80 | 0x02 | 0x00 | 0x00)


//baud 1200, 7 data bits, no parity, 1 stop bit
#define DEL 25 //Delay time
#define COM 0x03f8 //Specifies to com address

int ralgn(void); //device alignment for


receiving
int initial(); //Initialisation
int f_rcv(); //file receive function
int salgn(void); //device alignment for
sending
int splash(void);
int f_snd(); //file sending function
void welcome();
void chatwindow(); //draws the chat window
void chatting(); //chatting function
void dsply(char *, int);
char gra='Y';
int flag=0;
union REGS inregs,outregs; //The union REGS is
used to
// pass information to and from inbuilt function
int 86
FILE *fp;
int status;

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

char temp='\n',t2;
int t1=10;

/*main funtion*/

void main(void)
{
char ch,chr,chs;
clrscr();
if(flag==0)
{
flag++;
welcome(); // calls the welcome
function
}
clrscr();
textbackground(0);
textcolor(4);
gotoxy(30,6);
cprintf("INFRARED COMMUNICATION");
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(9);
gotoxy(36,15);
cprintf("C");
textcolor(7);
cprintf("hatting");
gotoxy(38,18);
textcolor(6);
cprintf("E");
textcolor(7);
cprintf("xit");
ch=getch();
switch(toupper(ch))

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

{
case 'R':R:clrscr(); //Enters to the
receive menu
textcolor(4);
gotoxy(30,6);
cprintf("INFRARED
COMMUNICATION");
textcolor(138);
gotoxy(33,9);
cprintf("RECEIVE MODE");
textcolor(9);
gotoxy(33,12);
cprintf("A");
textcolor(7);
cprintf("lign device");
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");
delay(2000);
goto R;
}
break;

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

case 'S':S:clrscr(); //Enters in to the


send menu
textcolor(4);
gotoxy(30,6);
cprintf("INFRARED
COMMUNICATION");
textcolor(142);
gotoxy(36,9);
cprintf("SEND MODE");
textcolor(9);
gotoxy(34,12);
cprintf("A");
textcolor(7);
cprintf("lign device");
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");
delay(2000);
goto S;
}
break;
case 'C':clrscr(); //Enters into the
chatting
textbackground(0);
chatwindow();

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

chatting();
main();
break;
case 'E':clrscr(); //Exits from main
menu
textcolor(143);
gotoxy(35,13);
splash();
delay(2000);
exit(1);
break;
default:clrscr();
printf("Wrong key pressed");
main();
return;
}
}

// function for recive(for device alingment)

int ralgn(void)
{
char st = ' ';
clrscr();
gotoxy(30,2);
textcolor(10);
cprintf("RECIVE MODE");
textcolor(9);
cprintf("ALIGN DEVICE");
printf("\n");
initial();
loop:
if (!kbhit())
{
if(st==0x04)
{
clrscr();
textcolor(140);
gotoxy(30,12);
cprintf("Aligned properly");
gotoxy(48,24);
printf("press any key to quit");
getch();

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

main();
}
status=inp(0x3fd);
if((status && 0x01)==0x00)
goto loop;
else if(!kbhit())
{
st=inp(COM);
printf("%c",st);
goto loop;
}
else
main();
}
main();
return 0;
}

// function for file receive

int f_rcv()
{
int flag=0,bytecount=0,count;
float ot=0.00,nt=0.00;
char ch,st[5500],fnm[30];
clrscr();
initial();
ot=clock()/18.2;
gotoxy(2,2);
printf("FILE NAME?:");
fp=fopen(gets(fnm),"wb");
gotoxy(26,10);
printf("(Ready for)RECEIVING DATA");
gotoxy(47,24);
textcolor(138);
cprintf("Don't Press any KEY data may loss");
loop:nt=clock()/18.2;
status=inp(0x3FD);

if((status & 0x01)==0x00)


{

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

/*check for no data reception for five


/*seconds after start of reception if no
data is
/* received continue 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);
cprintf("press any key to quit:");
getch();
main();
}
goto loop;
}
else if(!kbhit())
{
st[flag]=inp(COM);
flag++;
bytecount++;
ot=clock()/18.2;
goto loop;
}
else

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

{
clrscr();
for(count=0;count<flag;count++)
{
gotoxy(26,3);
textcolor(11);
cprintf("Saving data in");
textcolor(12);
cprintf("%s",fnm);
fprintf(fp,"%c",st[count]);
}
fclose(fp);
gotoxy(26,13);
textcolor(11);
cprintf("file %s of %d bytes
created"

,fnm,count);
sleep(5);
main();
}
return 0;
}

/*function for send alignment*/

int salgn(void)
{
int flag=0;
char st[27];
clrscr();
initial();
textcolor(14);
cprintf("type the sentence( <27 chars)");
puts("\n");
gets(st);
loop:status=inp(0x3FD);
if((status & 0x20)==0x00)
goto loop;
else

do
{

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

if(!kbhit())
{
outport(COM,0x0D);
outport(COM,0x0A);
if(flag==strlen(st))
{
printf("/n");
flag=0;
outport(COM,0X0D);
delay(5);
outport(COM,0X0A);
delay(5);
}
else
{
outport(COM,st[flag]);
printf("%c",st[flag]);
flag++;
delay(DEL);
}
}
if(kbhit())
{
delay(1);
outport(COM,0X04);
main();
}
}
while(!kbhit());
return 0;
}

/*function for file transfer*/

int f_snd()
{
int flag=0,count=0,fl;
char ch,st[55000],fnm[20];
clrscr();
initial();
gotoxy(2,2);
printf("FILE NAME ? : ");
gets(fnm);

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

fp=fopen(fnm,"rb");
if(fp==NULL)
{
clrscr();
gotoxy(35,13);
printf("FILE NOT FOUND!");
delay(1000);
main();
}
else
{
fl=filelength(5);
gotoxy(23,20);
printf("file being transfered has %ld
bytes",fl);
clrscr();
do
{
ch=fgetc(fp);
printf("%c",ch);
st[count]=ch;
count++;
}
while(ch != EOF);
}
fclose(fp);
loop:status=inp(0x3fd);
if((status & 0x20)==0x00)
goto loop;
else
do
{
if(flag==count)
{
gotoxy(50,24);
printf("press any key to exit");
getch();
main();
}
else
{
outport(COM,st[flag]);
flag++;

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

delay(DEL);
}
}
while(!kbhit());
return 0;
}

/*initialisation funtion*/

int initial()
{
inregs.h.ah=0;
//The 0 is used to initialize the specified
serial //communications port to a desired baud
rate, parity, //word length and number of stop
bits.
inregs.h.al=0x63;
//sets the baud rate to 600, none parity, one
stop bit //and word length is 8bits
inregs.x.dx=0;
//DX=communication port number (
0=COM1,1=COM2,etc )
int86(0x14,&inregs,&outregs);
return 0;
}

/*function for splash screen*/

int splash(void)
{
int d=DETECT,m,j,i;
struct palettetype pal;
initgraph(&d,&m,"c:\\tc\\bgi");
setcolor(15);
settextstyle(1,0,4);
setbkcolor(9);
for(i=0;i<5;i+=2)
{
setcolor(i);
outtextxy(35+i,200+i,"PC TO PC INFRARED

COMMUNICATION
");

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

}
sleep(2); //suspends the execution for 2
seconds
cleardevice();
for(i=0;i<5;i+=2)
{
setcolor(i);
outtextxy(275+i,200+i,"By");
}
sleep(1);
cleardevice();
for(i=0;i<5;i+=2)
{
setcolor(i);
outtextxy(180+i,160+i,"Jagadish.T.S");
outtextxy(200+i,205+i,"Suman.A");
outtextxy(182+i,250+i,"Adarsha.M.C");
}
getch();
cleardevice();
closegraph();
return 0;
}

// Function for drawing chatwindow

void chatwindow()
{
int i,j;
textbackground(0);
clrscr();
cprintf("Esc: Main Menu Enter: Send
:Recieved msg

:Sent msg");
gotoxy(63,1);
textcolor(14);
putch(219);
gotoxy(43,1);
textcolor(10);
putch(219);
window(10,3,70,20);
textbackground(1);

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

clrscr();
textcolor(3);
window(1,1,80,25);
for(i=0;i<=60;i++)
{
gotoxy(10+i,3);
putch(205); //=
gotoxy(10+i,20);
putch(205); //=
}
for(j=0;j<=16;j++)
{
gotoxy(10,3+j);
putch(186); //
gotoxy(70,3+j);
putch(186); //
}
gotoxy(10,3);
putch(201); //
gotoxy(70,3);
putch(187); //
gotoxy(10,20);
putch(200); //
gotoxy(70,20);
putch(188); //
textbackground(3);
textcolor(1); //BLUE
window(1,22,80,24);
clrscr(); //make
background blue
window(1,1,80,25);
for(i=1;i<=80;i++)
{
gotoxy(i,22);
putch('-');
gotoxy(i,24);
putch('-');
}
gotoxy(2,23);
putch(16); //
}

//Funtion for Chatting

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

void chatting()
{
char msg[80],msg_in[80];
int status,out,in,count=0,count_in=0,i,extra;
bioscom(0, SETTINGS, COM); //init. port
//alternative to outportb(),particularly for
RS 232

communication.
window(3,23,80,23); //message entry
window
while (1)
{
status = bioscom(3, 0, COM);
if (status & 0x100)
{
if ((out = bioscom(2, 0, COM) &
0x7F) != 0)
// input message byte.
msg_in[count_in++]=out;
if(out==13)
{
dsply(msg_in,10);
count_in=0;
gotoxy(count+1,1);
}
}
if (kbhit()) //character entered
{
gotoxy(count+1,1);
if ((in = getche()) == 27)
{
textbackground(0);
window(1,1,80,25);

break;
}
if(in==0)
{
in= getch();
//special function key pressed, ignore
continue;

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

}
if(in==8 && count>0)
{
count-=2;
cprintf(" \b"); //BackSpace
}
else
msg[count]=in;
if(count==70)
{
in=13;
msg[70]=13;
}
count++;
if(in==13 ) //Enter: Send
{
i=0;
dsply(msg,14);
for(i=0;i<count;i++)
{
bioscom(1, msg[i], COM);
}
clrscr();
count=0;
}
}
}
}

// Function for displaying the chatting text

void dsply(char str[80],int col)


{

int i=0;
static int line=1;
window(11,4,69,19); //Chat display
window
textbackground(1); //BLUE

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

textcolor(col);
gotoxy(1,line);
putch('\n');
putch(175);
while(str[i]!=13)
{
putch(str[i]);
i++;
}
line=wherey(); //store present line
window(3,23,80,23); //message enter window
textbackground(3);
textcolor(1);
}

// Function to show the welcome screen

void welcome()
{
int i,j;
clrscr();
textcolor(4);
gotoxy(24,5);
cprintf("Welcome to PC to PC Communication");
gotoxy(28,6);
cprintf("Using infrared device");
textcolor(2);
gotoxy(25,7);
cprintf("By Adarsha, Jagadish & Suman ");
sleep(1);
window(10,9,70,23);
textbackground(1);
clrscr();
textcolor(3);
window(1,1,80,25);
for(i=0;i<=60;i++)
{
gotoxy(10+i,3);
putch(205); // =
gotoxy(10+i,23);
putch(205); // =
}
for(j=0;j<=20;j++)

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

{
gotoxy(10,3+j);
putch(186); //
gotoxy(70,3+j);
putch(186); //
}
gotoxy(10,3);
putch(201); //
gotoxy(70,3);
putch(187); //
gotoxy(10,23);
putch(200); //
gotoxy(70,23);
putch(188); //
sleep(1);
gotoxy(15,10);
window(12,11,68,22);
cprintf("To start wireless communication
between the"
"two computers, connect infrared device
module to "
"serial port COM1 of each computer.");
gotoxy(3,12);
cprintf("Press any key to start....");
window(1,1,80,25);
getch();
}

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

OUTPUT:

Welcome window of pc to pc communication software

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

Main menu window

By Choosing the receive mode we are aligning the devices.

Type a word and then press ENTER to align.

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

Window after the device has been aligned.

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

Choosing the send mode

Send mode window

Type the path of the file to be sent

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

Contents of the file to be sent

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

Choosing the receive mode on the other terminal

Receive mode window

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

Set the path of the file to be received

Window after receiving the file

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

CHATTING
Choose the chatting mode from the main menu to chat with the person on other
computer

Window used for chatting

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

Type the message to be sent

Reply from the other computer

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

FEATURES:
 Maximum transmission rate of 2400 bps .
 Half duplex operation.
 Efficient conversion of RS232 –TTL by a single chip
 Simple interface through standard 9-pin cable.
 IR modulating frequency is 36 KHZ

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

ADVANTAGES:
The advantage of this project over traditional wired networks is
1. This system provides the users to access the information any where in the
organization.
2. Installing this system is fast & easy & can eliminate the need to pull cable through
walls and ceilings.
3. This system is suited for the organization requiring frequent moves and changes.

If the distance and the speed of the data transfer are increased in this project, it can
be used for many applications like
1. Sending data from computer to printer.
2. It can be used in fax machine overhead projectors etc.

The distance can be increased by


1. Increasing the modulating frequency.
2. By providing repeater circuit.
3. Using additional IR LED‟s.

Using higher version ports can increase the speed of data transfer.

It is very much applicable to use in sensitive areas like gas stations, oil refineries
etc... Where other forms of wireless communication may be dangerous as they might
produce electrical sparks and may cause disasters.
Infrared wireless communication module is very much safer and cheaper compared
to other systems.
It is highly compatible with all types of PC‟s and it works with all versions of
windows, as it is DOS based.
The software has a user-friendly text interface written in “C”.

CONCLUSION:
This is one of the efficient communicating methods compared to other method
because it is very easy to communicate and also there is no need to have network of
card for communication. Moreover it is very cheaper than compared to other forms
of wireless communication method.

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

BIBLOGRAPHY

INTRODUCTION TO DIGITAL AND ANALOG COMMUNICATION-


SIMON HAYKIN
http://www.anglefire.com/electronic
http://www.electronicsforu.com
http://www.ee.ed.ac.uk/~kap/Haed/555
http://www.docu-track.com
ELECTRONICS FOR YOU, MAGAZINE, APRIL 2002 ISSUE

Dept. of Co mputer Science & Engineering S.J.P


C Program for file transfer through infra red media

Dept. of Co mputer Science & Engineering S.J.P

Вам также может понравиться