1990
Free space laser communications on the Macintosh
computers
Sohrab Modi
Follow this and additional works at:
http://scholarworks.rit.edu/theses
This Thesis is brought to you for free and open access by the Thesis/Dissertation Collections at RIT Scholar Works. It has been accepted for inclusion
in Theses by an authorized administrator of RIT Scholar Works. For more information, please contact
ritscholarworks@rit.edu.
Recommended Citation
by
Sohrab Modi
A thesis, submitted to
the Faculty of the School of Computer Science and Technology
in partial fulfillment of the requirements for the degree of
Master of Computer Science
Approved
by
:
Dr.-JameSHeTict~-(Cha~man~-Dep[-Of-COmP~~s~:~ce:
Rochester Institute of Technology,
New York
14623
---~/~~'j~---Prof.
Alan
Kaminsky, Dept.
of Information Technology,
Rochester Institute of Technology, New York
14623
contacted each time a request for reproduction
of the code is made.
Acknowledgements
This thesis
is
dedicated to my late
grandfather
Dr.
S.
N.
Deboo
whosehelp
and encourgment madeit
possiblefor
meto
achieve allmy
goals.I
wishto
thank
my
advisorDr.
James
Heliotis
who alwaysfound the
time
to
help
advice and encourage mein
this
project, attimes
whenI
needed
it
most.I
would alsolike to thank my
advisorsDr.
Ronald
Jodoin
and
Prof. Alan
Kaminsky
without whosehelp
I
would nothave been
ableto
completethis
project.A
specialthank
youto
Dr. Arthur
Kovacs
for
allowing
methe
use ofthe
laboratory
andany
equipmentthat
was available withthe Physics
department, to
help
completemy
experiment.I
also wishto
thank Bill
Vandeveer
for
allhis
help
and advice andfor
alwayscoming
up
withthe
equipment
I
needed.A
specialthank
youto
Prof.
Guy
Johnson
for
allowing
methe
use ofhis
Macintosh
Computer.
Finally,
avery
specialthank
youto my
family
who stoodby
mein
my
Abstract
Lasers
have
proved their reliability in high speed communications through fibre optics.The disadvantage
withfibre
opticsis
the high cost and the needfora cabletoconnectthesenderto the receivers,hence
making
it impractical to have fibreoptic cables overlarge
distances.The
movetoday
is to communicate between points with a free spacelaser
(
ie. a beam unboundedby
cables). Semi conductorlasers as used in fibre opticcables are generally not
strong
enough to communicate over very large distances.Hence a high power laser is used with a modulation technique to transmit this data
across.
This thesis demonstrates the use of a Helium Neon laser to communicate between two
Macintosh computers. Bit signals generated
by
the Sender are converted to laserpulses withthe
help
of crystals. These pulses are again regenerated as bit signals atthe
receiver.This complete hardware interface of the Macintosh to the laserwas
designed
and built for this thesis.
The Software Protocolwritten for this thesis issimilarto the sliding window protocol used
by
the ISO reference model. The protocol has been modified to handle high speedtransmissions. The windowing environment, has been set up with pull down menu and
submenu systems.
Dialog
boxes generate responses to errors.Disturbances
in theTable
of
Contents
Chapter
Contents
Page
1.0
Introduction
1
1.1
Historyof Free Space
Laser Communications
2-4
1.2
Hardware
requirements andtheir drawback
for the Thesis
4-6
2.0.0
Hardware
Introduction
7
2.1.0
A
note aboutLasers
7
2.1.1
StimulatedEmissions
8
2.1.2
Amplification
through
populationinversion
8
2.1.3
Different
types
ofLasers
andthe
Helium-Neon Laser
9-10
2.2.0
Polarization
effect and electromagnetic effects10
2.2.1
A
brief
note onPolarized light
andtypes
ofPolarized light
10
2.2.2
Electro
optrics11-12
2.2.3
Wave
Plates
13-14
2.2.4
The Pockel Cell
14-16
2.3.0
A
brief discreption
ofhow
transmission
takes
place16
2.3.1
At
the Serial Port
16
2.3.2
Circuit #1
16-18
2.3.3
At
the
Pockel Cell
1
8
-20
2.3.4
The
Pascal
switch(Laser
switch)
20-21
2.3.5
Data
Transmission
Summary
22
3.0.0
Software
Design
Introduction
23
3
1
0
Understanding
the
needfor
sliding
windowProtocol
23-24
3.1.1
Higher
Transmission
Rates
24
3.1.2
Changes to the
Protocol
25
3.1.3
Calculation
oftimeouts
26
3.2.0
The
Protocol
Scenario
27
3.2.1
Scenario
#1
:All frames
sentcorrectly
28
3.2.2
Scenario #2
:Negative
acknowledgmentsreceived
28-29
3.2.3
Scenario
#3
:Sender
time
outs30-31
3.2.4
Scenario #4
:Receiver
time
outs31
3.2.5
Headers
&
errors31-33
4.0.0
Programming
Design
Introduction
34
4.1.0
The
Launguage
34
4.1.1
The Think C Language
34-35
4.2.0
Events their
use andhow
they
have
affectedthe
software
design
35-37
4.3.0
Macintosh
resources andits implementation
in
the
program40-41
4.4.0
The
display
enviornment42
4.4. 1
Model
ofthe
window enviornment42
-43
4.4.2
The Menu
Bar
43
5.0.0
Software
Implementation,
introduction
44
5.1.0
The
program structure45
5.1.1
The
programFlow
45-47
5.1.2
Initialization
48-50
5. 1
.3Initializing
the
serial port50
-52
5.2.0
Introduction to the
protocolimplementation
53-54
5.2.1
The
Handshaking
Implementation
54-56
5.3.0
The Receiver Protocol
57-59
5.3.1
Receiving
the
packet59-64
5.3.2
Receiver
acks&
nacks64-65
5.4.0
The
senderimplementation
66-69
5.4.1
Some
important
proceduresin the
sender69-72
5.4.2
The Nacks
andthe time
outs73
-75
5.5.0
Conclusion
75
6.0.0
Recommendations
andConclusions,
introduction
76
61.0
Improving
the
risetime
77-80
6.2.0
Recommendations
in
the
softwareimplementation
80
6.2.1
Floating
to
fixed
windows80-81
6.2.2
Closing
the
transmission
and receivertime
outs81
-82
6.3.0
Conclusions
82
Bibliography
Appendix
A
Appendix
B
Appendix
C
Appendix
D
Appendix
E
Appendix
F
Appendix
G
Appendix
H
Appendix
I
Appendix
J
Appendix
K
Appendix
L
Appendix
M
Appendix
N
Appendix
O
Glossary
Program
Code
Program Flow
Serial
portdiagram
Feild
vectordiagram
Circuit
#1
Oscilloscope
representationThe Entire
Picture
Pascol Switch
Cross Polarizers
Wave
plateDiagram
Inside the
pockel ceilDialog
Box
Window
Display
Menu
Display
Rise Time
Display
Ratio
graph ofIntensity
vsVoltage
HI
iii-iv
v
vi
vii-viii
ix
x-xi
xii
xiii
xiv
xv
xvi
xvii
xviii
xix
XX
CHAPTER
1
INTRODUCTION
1.0
INTRODUCTION.
Free
spacelaser
communications, is atechnique
by
which data canbe
transmittedover a laser beam.
The
advantage of using light over radio waves lies in the higherbandwith. Also as
Information capacity
is proportional to carrierfrequency
and as thecarrier
frequency
for lightis high,
it makes light a good medium fortransporting
data.Light however has a
disadvantage;
it tends to dissipate into its surroundings due toabsorptions. Laser
beams
brighter and more directional and are therefore capable oftravelling
greatdistances before
dissipating.The idea
of this thesisis to
show that communications over a laser beam is possibleunder
the
simplest of conditions and at a minimal cost.Here
I have usedtwo Macintoshcomputers to actas senderand receiver. An electro optic light modulator isattached
to thesenderto actas a highspeed shutter whilea light receiving diode is attached to
the receiver. A helium neon laser beam generated at source flies through the light
modulator and
is
received atthe diode.The
problem I haveto
deal with here is a twofold
one. The firstbeing
the hardwareinterface
ofthe
electro optic light modulator (Pockel cell) to the Macintoshcomputer'sserial port. Thesecond
being
the
software supportto
transmit and receivedata
overthe
helium neon Laser beam in a way that would minimize the errors intransmission. Also as Iwill be using theMacintosh computersIwould be requiredto
build
some sort of
display
environment (like a window). Each topic willbe
addressed1.1
History
ofFree
space LaserCommunications.
(1)
The
birth offree
space laser communications gave way to thediscovery
of what weknow
today
asthe Optical Fibre
technology. HoweverFibre Optic
cable alsohas
itsdraw backs.
The
cost ofhaving
aFibre Optic
cable is prohibitive, forexample thecostof
having
aFibre Optic
cable link between Japan and theUnited States which is in theprocess of
being
installed,
is estimatedto cost$
700 Million. None the lessdue
to hightraffic conditions between the two countries, it is at this point in time more efficient to
have this link than to have anothersatellite to handle the communication.
This is
mainlyattributed to the fact that
the
Laser beam inside the Optical fibrecan carry uptoafewGigabits
/secwith a high degreeof efficiency.Research in free space Laser communications on a commercial basis started in
earnest in 1962.
Twenty
seven years later there is still no known operational free spacelaser communication system. ESA (European Space
Agency)
is howeverdeveloping
an optical communication system for data link between two
Geostationary
satellites,orbetweena geostationarysatellite and a lowearth
orbiting
satellite.(
2)
The program known as SILEX
(
Semiconductor Inter satellite LaserExperiment)
wasselected as the bottom line for the experiment. The
following
is the schedule for theprogress ofthe European Data
Relay
Satellite (known asDRS)
1989 Components qualification
1993
. 1994 in- Orbitdemonstration of optical payloadFunding
inthe United States has been
mainly from1)
AirForce
:-Guiding
System,
tracking
systems(Lasercom).
2)
Navy
&
DARPA:-Space/Subspace Communication.
3)
NASA&
JPL:-Deep
Space
Communications.Funding
however has beenthe
majorsourceofdelay
for this program.Testing
started in thel960's after successful development of anengineering
model whichdemonstrated
its ability to work under adverse conditions. A space Flight using a Nd: YAG
(
yttrium AluminumGarnet)
laserwasfunded,
but the programcontractedfor in 1975got caught in redtape,
and had itsfunding
cut one afternoon atthePentagon,
whenanextra$ 300
Million was neededfor the MX missileproject.
The
Space
Flight Test system was near death when a last minute effort was made to revive it. The budgetwas untill1977,
and itwasin December 1976 thatadesperate bid toextend it through 1978was made.
A test flightwasquicklysetupwhichprovedto be asuccess. Aplane
(
C- 135)
flewinto
White
Planes(N.M)
whiletransmitting
data at rates of 1G
bit/sec. This successful flight brought back confidence in the program and opened doors for the flighttracking
systems.
The
United States Airforce had its own problems with what was calledLasercom,
inNASAwhich
had been
stoppedby
Congress
fromfunding
advanced communications,was brought in
to
work on a LaserCommunication
system on the AdvancedCommunication
Technology
Satellite
(ACTS). NASA isworking
on thisprojectalong
withLincoln
Labs
(M.I.T.). which isdeveloping
a semi conductor Laser CommunicationLink,
and
Goddard is
developing
asemiconductor direct detection link.Meanwhile the
Navy
and DARPA got together todevelop
a Submarine basedcommunication Link. Blueand
Green light,
whichtravels
through waterat a relativelylow loss offer Laser links as a means of
improving
sub communications. Developmenton this projecttook place and a successful air-to-submarine testwas concluded when
a plane
flying
through theclouds communicatedwith a submarineusing
adoubled
Nd:YAG Laser.
There
are four major reasons as to why Laser communications should be addressed.They
are :1
)
Wide Bandwith Greater than2Gigabits
/sec.2)
Small Antenna sizekey
viewing area asbeam is focased.3)
Privacy
Interceptionofbeam very difficult.4)
Jam ResistanceJamming
very difficult due tospaceorbitaldynamics and narrow beams.
1.2 Hardware requirements and their drawbacks for the Thesis.
This
laboratory
set up ismeant toshowthat such transmissionscan take place and canAlthough the
RS-422
islogically
the same as the RS-232 its electrical standards aredifferent.
The technique
ofascertaining
thepolarity
ofthe portby
locating
thenegativevoltage
to
the transmitter cannotbe
applied to an RS-422 port. This is because theTransmit and
Receive
lines ofthe RS-422 work on a differential voltage. The equipmentused in the experimentfor this Thesis is
:-1)
Helium-Neon Lasersource.2)
Electro-Optic
LightModulator (Pockel cell).3)
Pascal Laserswitch (refer toappendixG).4)
a)Quadruple
line receiverTi 75189.b)
Power transistor ECG 287.5)
2 Powersuppliesfor -18
V to+ 18 V,
onepowersupply from 0 to 300 V.6) One
Polarizerand oneAnalyzer.7)
One 150
MhzOscilloscope to
keep
trackofinputand output signals.8)
Two Macintosh computers.9)
differential linedriverUA9638 CP (TexasInst.)
10)
8-pin DIN plugs,breadboards,
etc.Although the equipment has been so chosento handle high transmission rates
there
area lot offactors thataffectthose rates.
Rise
time oftransistor is 2x 10
" 8sec, thatof
the
Pockelcell
is 2
x 10"^second ofthe Pascolswitchis 2x 10"'sec. Fora high
transmission
rate of57600 bits/sec and up, absolute groundingofthe equipmentis essential. Another
thing
that is required in high speed transmissionis,
that the chips and powertransistors
header. It is a valid header if the packet sequence number is the one it*/ /*
expects or if the packet sequence is less than the present working wind */ /* but
greater than the previous working window (that is it checks to see */ /* if a
retransmission is
taking
place of the previous window. Else it will*/ /* senda Negitive acknowlegment. */
CheckHeader( localSize ) int
localSize;
{
int previousStartWindow;
Boolean windowTurned =
FALSE;
previousStartWindow = startWorkWindow - NUM_OF_BUFFERS ;
if (previousStartWindow <
0)
{
previousStartWindow += (int)TOTAL_BUFFERS; windowTurned =
TRUE;
}
/* This indicates that it has received the correct sequence number */
if (pacSeqNum = readBuffNum
)
return(localSize) ;
/* this indicates that the ack/Nack had got lost and the sender
retransmitted the previous Buffer so acknowledge its receipt */ else
if((
pacSeqNum >= previousStartWindow)
&&(
pacSeqNum < readBuffNum ))
{
skipPacket = TRUE;
return(localSize);
}
else if( (windowTurned = TRUE) && ( ((pacSeqNum >= previousStartWindow) && (pacSeqNum <= 44)) II ((pacSeqNum >= 0) && (pacSeqNum< readBuffNum) ) ) {
skipPacket = TRUE;
return(localSize);
/*
We want to quit so inform Sender */
else if
(
(pacSeqNum == (unsigned char)END_HANDSHAKE) && (localSize ==0)
){
receivedClosing = TRUE;
SendAckSender
(
(unsigned char)END_HANDSHAKE) ;fclose(fwrit) ; return(localSize) ;
}
else
However as
these have
atendency
to blow quite often (due to open wiring andadverse
temperature
conditions) it is necessary to mountthem on breadboards. Openlong
wiring and extra connections (oscilloscope probes), extend the rise times.This
affects
the switching
time and therefore a high transmission rate is not possible underCHAPTER
2
HARDWARE
ITS
THEORY.
DESIGN
&
IMPLEMENTATION
2.0.0
HARDWARE INTRODUCTION.The equipment used in this demonstration is not the best equipment to use for the
experiment but was easily avalable and very inexpensive (expense
being
a majorfactor).
Also,
to make the equipment as portable as possible most connectors andcuircuits are made in such a way that
they
can be easilydismantled. Low transmissionrateis the price I have to pay for theabovetwo factors.
2.1.0 A note about Lasers.
Laser stands for Light Amplification
by
Stimulated Emission of Radiation. A lot can bewritten about
Lasers,
but would go beyond the scope of this thesis. However a briefdescription could be useful.
A laser is a device that produces a
highly
directional and intense beam of coherentlight.
Ordinarily,
when a beam of light travels through matter, the effects of absorptionand spontaneous emission overpower the effects of stimulated emission.
Hence
thereisa net reductionin
intensity
ofthe beam.In the laser however,conditions are arrangedsothatstimulated emissions are dominant
over absorptions and spontaneous emissions. The dominance of stimulated emissions
creates a pure lightsource ofa single frequency. This makes
lasers
an ideal medium for2.1.1
Stimulated
Emissions.
In thecaseof
light,
when photons enter a slabofmaterial containing photon-absorbing
atoms,the
intensity
ofthe beam is reduced. Eachatom thatabsorbs the photon is leftin an excited state and its
energy
is increasedby
hv(
where h is Plancks constantandvis the
frequency
). It could stay in this excited state orin only 1 xlO "8
seconds emitthephoton andreturn to its formerstate.
The
emitted photonhoweverneed nottravel in thedirection of propagation of the light beam
thereby
reducing theintensity
ofthe
lightbeam. In the case of stimulated emissionsthe photons striking an excited atom causes
theexcited atomto lose a photon hence the two photonstravel hand in hand along the
direction of propagation
thereby increasing
theintensity
ofthe beam. Howevereven inthe
stimulated emissions the net result is a loss inintensity,
as their are many moreabsorptions than there are stimulated emissions, the reason
being
that most atoms arein their lowest energystate.
(7)
2.1.2 Amplification through population inversion.
Population Inversion creates a situation where there are relatively many more atoms in
an excited state capable of emitting photons than there are atoms in a state that can
absorb them. Hence, a beam of photons passing through an inverted population gets
amplified as there are more stimulated emissions than there are absorptions. Each
photon of the incident beam can trigger the emission of others and each newborn
photon can travel on to simulate more emissions. If a sufficient number ofatoms are in
an excited state an avalanche of photons can result. Population inversion can be
2.1.3
Differenttypes
ofLasers
andthe
Helium-Neon
Laser.There are many different types of lasers.
1)
Ruby
laser: Active medium consistsofAI2O3
with asmall concentration ofCr203.
Laser rods are single crystals of ruby. Laser action takes place due to transitions from
level2 to level 1.
Energy
oftransition is 1.8eV,andthewavelengthis 694nm.2)
Neodymium laser:This, like
a ruby laser is also another optically pumped lasermaterial. Lasers of this
type
are Nd:glass andNd:YAG
(yttrium aluminum garnet) Thelatter
being
astrong
contenderforsatellite communications.3)
Organic dye lasers: This is another class of optically pumped systems. The activematerial is an organic dye dissolved in a suitable liquid. The dye molecules are a three
level system with energy levels represented as bands. Thewidth of the bands give rise
toa broad fluorescence hence
giving
risetowhat is knownastunable Lasers.4)
Ion lasers: Argon-Ion Lasers can be made to oscillate at several wavelengths.These are generally seen at the Blue-Green end in the visible spectrum. These have
been used
by
the USNavy
for submarine communications. Due to the high energyrequired to ionize the atom and raise it to an excited state the efficiencies of all arc
discharge Lasers is very low. However once population inversion has taken place then
these Lasers have a high gain and can produce several watts of continuous output
power.
5)
CO2
lasers:These Lasersoperate in the infrared region and areinvisible
to the nakedeye.
They
can be used as continuous, pulsed orQ-switched type lasers.Even a small fraction of a watt is capable of
heating
most materials to anincandescence in ashorttime. Hence
they
are used in thingsaswelding
and cutting..6)
OtherGas
Lasers: These are helium-cadmium, water vapor.HCN, Nitrogen,
TEA
7)
Semiconductor
Laser:This
is also known as a Junction laseror injection laser.They
are important in optical communications and optical computer design.
They
aregenerally pnjunction
diodes
ofGallium
Aluminum Arsenide.8)
Helium-Neon Laser:This
isthe
laser I will use for my thesis. The two essentialcomponents of a laserarethe active medium andthe optical resonator. In the
Helium-Neon laser theactive medium isa mixture ofHeliumand Neon. An active
discharge
willcause some of the atoms to ionize. Hence the active medium also contains positive
ions as well as electrons. The optical resonator usually consists of a pair of mirrors which
are made
highly
reflective.(
7)
frequency
of radiationV
= 4.7375x 10 14 Hz.The Laserwavelength
A
=C_
=6.328x 10
"7m or 632.8nm( C
=velocityof
light)
V)
(thiswave length givesthe lasera red color).
2. 2.
0
Polarization Effects and Electromagnetic Effects.2. 2. 1 A brief note on Polarized light and types of polarized light.
Light consists of
time-varying
electric and magneticfields. These fields are vectors andtheirdirectionsarealways perpendicularto the direction ofpropagation.
Whenthe electric-field vector E of a lightwave lies in only one planethe light is said
to
be plane polarized. The magnetic field vector H is then perpendicular to both
the
2.2.2
Electro-Optics
When certain liquids are placed in electric fields their molecules tend to align
themselves parallelto the directionoftheelectricfield. The greaterthe
field
strengththemore complete the alignment of the molecules. As the molecules are notsymmetrical,
the alignment causes the liquid to become anisotropic and birefringent.
Anisotropic
materials are substances whose physical properties varywith direction. The
anisotropy
is determined
by
the crystal structure ofthe material. If a narrow beam of unpolarizedlightwere shone on a crystal and two emerging beamswere polarized
orthogonally to
one another/then such a phenomena is termed as birefringence.
Such
electricfield
A Kerr cell
is
a cellcontaining
Nitrobenzene
or another suitable liquid between two flatparallel plates spaced
by
several millimeters. The Potential Difference betweenthe
platesis
typically
between10
or20
kV.A polarizerisa
device
thattransmits,
only lightwhose component ofelectricfield
vectoris parallel to an
imaginary
line known as the axis of the polarizer. The below diagramexplains what is meant
by
cross polarizers.Cross Polarizers
Transmission axis
Rotate polarizer *1 -through 90 degrees to obtain position of polarizer *2. Nov the cell lies betveen tvo cross polarizers.
Figure
2.0
Hence if the cell is located between cross-polarizers as used in the experiment, it may
be used as afastshutterknown asan electro-optic shutter.
In an electro-optic shutter, the direction of the electric fields is 45 degrees to the
direction ofthe polarizer axis. When the field strength is zero the polarizers transmit no
light. Whenever a voltage is applied to the cell it behaves as a half wave plate
(explained in section
2.2.3)
and rotatesthe plane of polarizationby
90
degrees. The Kerreffect is very fast and the shutter speeds are limited only
by
thedifficulty
ofgenerating
fast electronic pulses in the Kilovolt range. Hence in this experiment I
have instead
used [image:21.517.28.427.226.457.2]2.2.3
Wave
Plates.
Leta thin slab of
birefringent
material be cut sothat itsoptic axis lies in the plane ofthe
surface as shown
in the
belowfigure.
[image:22.517.24.340.175.316.2]^ E
Figure 2.1
Suppose
that plane polarized light falls at normal incident to the slab. Its electric feildvector then makes an angle 0 with the optic axis. We resolve the vector into
components perpendicular and parallel to the optic axis. The component parallel to
the optic axis propagates through the crystal as an extraordinary ray while the
component perpindicularto the optic axis propagates as an ordinary ray. Consider the
optic axisto bea fastaxis.
An optic axis is considered as a fast axis if a wave travels faster
along
the optic axisthen perpendicularto it. It is dependentonthe crystal. Calcite has afastaxis whilemica
has a slow axis. As the extraordinary ray is incident normal to the optic axis the
extraordinary raypropagatesthrough the crystal unchanged in direction but somewhat
fasterthan the ordinary ray. Let the index of refraction for for ordinaryrays ben and
for extraordinarywaves be n . If d is the thickness ofthe material then the
extraordinary
As a special case considerwhen 0 = n/4
. Then
the
ordinary rays andthe extraordinaryrayswill have
the
same magnitude. Furthersuppose that (no-ne)d is equal to X/4 atsome specific wavelength
X
Then the phase difference between the two platesis
given as n/2 andthe
lighttransmitted
by
the crystal willbe
circularly polarized.Thecrystal is then called a quarter wave plate. Halfwave plates cause a phase shift ofn.
The emerging
wave is plane polarizedwithits electricfieldvectormaking
an angle of0with the optic axis. The half wave plate can
therefore
be used to rotate the plane of polarizationthrough 2 0.2.2.4 The Pockel Cell.
The Pockel effect is an electro-optic effect that is observed in certain crystals such as
Potassium Dihyhdrogen Phospate
(KDP)
or Potassium DideuteriumPhospate
(KD*P). Itdiffers from the Kerr effect in two ways. The Pockels effect is linear in applied electric
fields,
thatis
the angle of rotation ofplaneof polarization 0isproportionalto thevoltagewhereasthe Kerreffect is quadraticin applied electric
fields,
that is theangleof rotationof plane of polarization 0 is proportional to the square of the voltage. The voltage
reauiredto drive the Kerrcellis very muchlarger than the Pockelcell.
The Pockel cell's electro-optic effect describes the relative phase change produced in
polarized light passing through certain uniaxial crystals which are under stress of an
electric field.
If
the
electricfield is applied parallel to the optic axisthe case is known aslongitudinal
The transverse Pockel
effecthas many
advantages overthe
longitudinal effect. Firstthe
electrodes lie parallel to
the
beam and do not obscure it (shown in figure below).Second the
indexdifference
(nQ
n@)'depends
on the electric-field strength in thecrystal,and not on thevoltage between the electrodes. In the case ofthe Longitudinal
Pockel cell if the length ofthe crystal is
increased
but thevoltage maintained constantthe
electricfield
inthe
crystalwilldecrease
proportionately.Hence the
index differencewill
decrease
andthe
phasediffrence
or retardation betweenthe
twopolarizationswillremain independentof the length ofthecrystal.
On the other
hand,
inatransverse Pockel cell,theelectrodes need beseperatedby
thediameter ofthe beam and no more.The electric fieldstrength in the crystaldepends on
the seperation between the electrodes and not on the length of the crystal.
Consequently lengthening
the crystal andmaintaining
the same seperation betweenthe electrodeswill result in increased retardation.
Incident Plane
Polarization
[image:24.517.26.496.421.592.2]^
I
have
used aPockel
cell ofthe transverse fields
operation madeby
Lasermetrics Inc.This
has PotassiumDiderterium Phosphate
asits
crystal material, its window materialis
made of
Fused Silica
and requires a voltage of250
V for it to behave as a halfwaveplate.
(4)
2.3.0
A brief discretion of how transmission takes place.2.3.1 At
the
Serial
Port.Let us begin at
the
Serial Port of the Sender. As explained before theserial port is aRS-422 type.
Generally
a one bit is representedby
somevoltage greaterthan +3Volts anda
0
bit is representedby
some voltage less than -3 Volts. The signal is said to bedifferential asthese voltagesare not relativeto ground but instead depend on voltage
diffrence between two lines.This differential signal has made things easierfor me in one
ofthe circuitsthat I have built. ToconvertaTTLsignalto an RS-232signalaline driver chip
wouldbe needed(Ti75188).
2.3.2 Circuit #1.
The
differential signalcoming
out ofthe Sender's serial port is fed into the line receiver.The line receiver chip made
by
Texas Instruments is a quadruple receiver. The output isfed into one of the receivers and a +5 Volt supply is fed at pin number 15. The line
receiverconverts the differential signal into a TTLsignal. This conversion from RS-422 to
TTL is necessary as the power transistor to which this signal is fed switches between
0
+
Input i3
adifferential
3ignalfrom
the
Macintosh (pin3 2
&3)
>
Line
receiverTi
SN75189ATTL
input'(0or5 volts)
-X^
R=100kA
VCCri(+250Volfe)
R=iMn
VCC
out(0volt3or250 volte)
output
to Poclek
cell4,
f
Figure
2.3
Whena 1 bit isoutputfromthe serial porttheline receiverputs out +5 voltsonthe baseof
the
transistor. Atthis pointthe transistor ison and no significant voltage (about +5Volts)
appears betweenthe collectorandthe emmiter oftWatransistor. Howeverwhen a0 bit
is output from the serial port the the receiver sends 0 volts to the transistor. Now the
transistor goes off and
250
V appears from between the collector and the emmiter.Hence as thestream of bits eruptfrom the serial port the transistorswitches between +5
and
250
Volts. At this point it is important to mention something else. The bit rate will [image:26.517.38.419.110.390.2]The transistor
has
a response of 50 MHz or risetime of2 xlO "8 seconds. Now for a2400
bps
transmission
ratethe
voltage pulse sentfrom the serial port is for atime duration of4.17 xl0~4
seconds.
As the risetime for
the transistor
is only 2xlO"8seconds
250
Volts is outputfor99.995 %
ofthe cycle.
This fraction
oftime lost due to the risetime
iswell into the uncertaintyrangeand would create no loss inpulses generated.
2.3.3
Atthe
Pockel CellThe Pockel cell is connectedto the other end of circuit #1 (Appendix A).
The
HeliumNeon Laser source is so positioned that the Laser beam enters the Polarizar and goes
through the aperture of
the
Pockel cell. The beam exists fromthe
otherside and goesthrough the analyzer. The beam that shoots out can either be received
directly by
alaserswitch orcan be bounced offmirrorsbefore
being
received.As
explained in section 2. 2.2,
the direction ofthe electricfield is at 45 degrees to thePolarizerand analyzer axis. When the field strengthiszero the
Polarizers
transmit no light.Going
by
thisconcept,whena 1 bit leaves theserial port(asa+5Volt)
itenters circuit# 1and putsthe transistor on,which throwsnegligible potential accrossthe Pockelcell.
This
has no effect on the cell and the apparatus behaves as explained above. The
intensify
of the beam is
thereby
cut. However here we have to make a small change to thesystem. We need to maximize the
intensity
when a 1 bit leaves the serial port.This
restriction is brought on
by
the Pascal switch. Hence instead ofmodifying
circuit #1 allwe need todonowisrotatethe plane of polarizationthrough 45 degrees. This is done
by
adjusting
the Polarizer and the Analyzer such thatthey
are both in phase with oneanother.
Hence
as shown in figure2.0
the polarizer#2 wouldhaveto be
movedback
455
Volts
Vcc
look
underAppendix
A
-TxD
(3)
Transmit data
Ground
=
G3s0i]
CTS
(2)
input
Handshake/
externalclock
DTR
(1)
Output
Handshake
Circuit
3
referto
Appendix G
(Pascal Svitch)
RxD+
TTL
toRS 422
conversionchip
(differential
line
driver UA 9638 CP
imgijE3H
: >
RxD-DTR
(1)
Output
Handshake
CTS
(2)
Input
Handshake
Figure
[image:28.517.42.440.46.707.2]Hence
when a 1 bitleaves the
sender's serial port the transistor is on and +5
Voltsappears between
the
emmiter and the collector.This
+5 Volts is fed to the Pockel cellmaking
no change tothe
crystals.The
uniaxial crystals are now under a near-zerofieldstrength
making
no change. Hence the PolarizarandAnylazermaximizetheintensity
ofthe beam.
Nowwhena
0
bitleaves
theSender's
serial port(>-3V)
it is representedas a0
volt atthebase ofthe
transistor,
thereby turning
the transistoroff. Now250
Volts appears from thepower
supply
and between thecollector and emmiterto the Pockel cell.This250
Volts isthe half Wave
Voltage
requiredto
drive the Pockel cell.The
Uniaxial crystals inside thePockel cell
coming
underinfluence
of this electricfield rotate the plane of polarizationthrough
90
degrees and in essencebring
about a shift in Phase. Because of this incombination withtheorientations ofthe polarizerand analyzer/the
intensity
ofthe
beamgets cut.
2. 3. 4 The Pascal Switch (Laserswitch).
The
Pascal switch is a device forreceiving the
intensity
of the beam and thengenerating a pulse
depending
onthe intensity. The main component ofthe switch is aPhotodiode for receiving the beam. The Pascal switch has a +5 Volt supply attached.
When the
intensity
ofthe beam is maximized atthe diode the circuit drawn belowwillrp/ftgrem
smmx\
power
500kA
cmp
T
Light
Photon
entering
Photo-dfcxJe
iokn
O
Tncnsistor
5V
VDc
CXIpLf
{Goes
to
iiptf
of
ine
oifver
}
Grotnd
[image:30.517.32.436.99.341.2]T
Figure 2.6
If however the
intensity
is minimized0
volts is thrown at the output. Hence the Pascalswitch switches between
0
and +5 Volts (TTL). However the Macintosh must accept aRS-422 type signal. Hence thisoutputis fed into adifferential line driverofthe type made
by
Texas
lnstruments(UA9638
CP).The
otherend ofthe line driver is connected to the2.
3. 5
Data Transmission Summary.
Characters
are sentfrom
the serial port in theirbinary
form. A high bit or 1 bit isrepresented
by
a differentialvoltagegreaterthan +3 Voltsemerging
from theserial portfor a particular length of time
depending
on the bit rate set up. A low bit or a0
bit isrepresented
by
a differentialvoltage of less than -3 Volts. Theserial port when unused isalways in a high state. When transmission is to take place the port goes into a lowstate
before
transmission ofdata can take place. When a0
bit gets transmitted (-3 volts), itfirst gets converted to TTL
by
the line receiverchip.This
voltage is fed in atthe base ofthe transistor (as shown in figure
2.3)
which turns the transistoroffthereby throwing
250
volts between the base and the collector. This
250
volts is fed into the Pockel cell. Whenthe uniaxil crystals in the pockel cell come under influence of the electric field
generated
by
this voltage,they
change the plane of polarization of the laser beamwhich is incident on them. This brings about a phase and amplitude change. This
amplitude change is represented
by
adrop
inintensity
ofthe beam. Hence the Pockelcell behaves asa highspeed optical shutter. This
drop
inintensity
which ismonitoredby
the Pascal switch forces the circuit in the switch to pass
0
volts to the differential linedriver.
This
differential line driver now feeds a low to the receive ports in the ReceiverMacintosh. Hence a
0
bitsent outfrom the serial port ofthe Sender isreceived as a0
bitby
the receiver.Similarly
in the case of a 1 bit the reverse takes place whereby thePockel cell does not come under influence ofthe electric field
thereby
registering
nodrop
in intensity.Due
toequipment restrictionsonly forward transmission of data willtake place overthe
laser beam. That
is
transmissions from sender to receiver. However anytransmissions
CHAPTER
3
SOFTWARE
DESIGN
3. 0. 0
Introduction.
The protocol used in the transmission of data over the laser is based on the sliding
window protocol.
Sliding
window protocols are used to reduce roundtrip
propagationdelay.
This
chapter only deals with the basic design of the protocol. It states its uses,effectiveness and puts
forward
arguments in its favour. Most of the discussion in thischapter
has
beenimplemented
in thesupporting
program.Topics
discussedhere,
butnot implemented rises from the fact that there is an alternative or easier way to
implementthesamethought. Implementation details are discussed in chapter5.
3. 1.
0
Understanding
the need for sliding window protocols.Consider
a file of 10K Bytesbeing
transmitted through a serial port not using thesliding
window protocol. Let thesender senda packet. The receiver receives itandthen sends
an acknowledgment
(ack)
back. In both casesthere is a delay.Once
the sendersendsthe file itwaits for the ackto come
back,
andwhenthe receiversendsthe
ackitwaitstillthe nextfile is sent . This
delay
is called propagation delay. The sliding window protocolismeantto reducethis delay. If the propagation
delay
were known orcalculatedthenwe could transmit multiple buffers from the sender until itwas time to receive
the
ack.Say
for example the output buffer is broken up into 5 buffers of 1 K bytes each andNow
by
thetime the
last buffer is sent it should start receiving the ack for buffer 1. If itreceivesa positive ackfor that buffer itwillfree that bufferand loadthe next message. If
itreceivesa negativeackfor buffer 1 itwill retransmitthesame buffer. If buffer 1 timesout
or itreceives an ackfor
the
nextbuffer then itretransmitsthe old bufferagain.Similarly
itwill repeat itself throughall
the
buffersuntiltheentirefile issent.3. 1. 1 Higher Transmission Rates.
A
thing
to remember in communications over a laser is totry
and maximize thetransmission rate and reduce delays resulting in
processing
and propagation. Highspeed transmissions will also require very high speeds in processing. Consider the case
where packets arrive at two
GBits/sec.
The receiver must be in a position to eithertellthesendertoslowdown if itcannot
keep
polling
andchecking
the packetsthat fastor,itshould have large serial port input buffers to placethe information in as it comesin and
then pull out from this input buffer. I have gone with the latter (large serial port input
buffers)
as it creates lesstiming
problems and helps me make the system moreconcurrent. Also
having
this method does awaywith the need ofhaving
the
receivertell thesendertoslow
down,
which will be in the formofa negativeacknowledgment,asthe only way the receiver knows that it cannot
keep
up, is if it startsloosing
data. Adrawback with large buffers is when a Nack takes place. When this
happens
thereceiver may
have
in its buffer, packets sentby
the sender before the nack wasgenerated, but not yet accepted. These packets are now redundent.
However the
receiver willhave to gothrough its entire large input buffer tosearch outthe
header
forthat packet sequence number. This causes a problem. It
increases processing
which3.
1.2
Changes to the Protocol.
The
sliding
window Protocolhas
been modified to receive acknowledgments afterevery window offifteen packets, as opposed
to
every packet as defined underthe
reference model. This eases the overhead on the
processing
by
having
to do awaywith
timers
on every packet buffer.Also,
if the transmission is good then it does awaywith
the
overhead ofhaving
tosend anackfor everypacket for thereceiveraswellashaving
toreceive an ackfor everypacketfor thesender.The drawback here is that ifanack gets lost therewas noway of knowwhich buffers reachedthe receiver. Hence the
entirewindowoffifteen packetshas toretransmitted.
Other questions are, how many sequence numbers should one
have,
how manypacketsshould be ineachwindow, how dowe maintain a
sliding
windowprotocol, andhow does one calculate the time out. The number of sequence numbers, the number
of packets within a window and the size of the packet could be left up to the
programmer. The important consideration in
judging
these sizes would be transmissionspeeds, propogation
delay,
buffer space and the probability for the packet to getthrough in the minimum number of re-transmissions. The concept of how the
sliding
window protocol is maintained is explained in the 3 case scenarios explained in this
3.1.3.
Calculation
oftime
outs.Lei
ticks timeSent
item
=
the
numberofticksofthe CPU
clock/secondfor thatsystem. =
the
time the packet was sent out at.
= dataunit exmple:- character,integer. distanceTravelled = distance toreceiverinmeters.
errorFactor = a number which will allowfor tolerance.
Then
oneBuffTimeOut numberof itemsper packet * number of bitsperitem *
ticks transmission rate(in
bits)
orbaud ratepropogatioin
Delay
= distanceTravelled 3*108 meters/sec (speed of
light)
timeOut =
(
oneBuffTimeOut *numForPackets) +propagationdelay.
Hence
if
(
presenttime>= TimeSent+timeOut)
Raise Error.
There
could be otherfactors that could havebearing
on a time out period asis
the3.2.0
The
Protocol
Scenario.
A
file to be transferred
from oneterminalto
anotheris first broken upinto
small packets.Each packet orframe is broken up into a 5 byte header followed
by
data. The headerdescribes the
logistics ofthe packetfollowing
it (for example the size, packet number,etc).
Details
about the header are described in chapter 5. The packet itself containsdata
followed
by
an end of packet marker, Ifthe
endof packet markerexists asdata inthe packetthen another marker
is
putbefore
it toidentify
it from the real end of packetmarker. This processis called as byte
stuffing
and has been used in the implementation.Detailsaboutthe packetand headersare discussed in chapter5.
Client
orHost
serial port
buffer
of
Sender
serial
port
buffer
of
receiver
Client
orHost
3. 2.
1Scenario
#1 : Allframes
sent correctly.Consider
the scenariowhere no errortakesplacewhentransmitting
theentirefile.Letus assumethat
the
senderhas sentout15
(0..14)
frames.The
receiver will accept allframes
whose sequence itis
expecting. It expects these sequence numbersto
comein order. It accepts each frame
by
checking
the control character andcounting
thenumberof
bytes
in eachframe. When the receiver receives all 15 (0..14) frames
itsendsan ackback for the 14& frame. Itnowmovesitswindowdownanother 1 5 buffers
thereby
accepting
allframes
from 15..29. The
sender inthe
mean while does not wait for theN/ackof
the
previouswindow(0..14)
tocome in.While
transmitting
frames
15..29 it should receivean ackfor frame 14. It howeverstarts atimeratthe endof
sending
the last bufferof a window(in thiscaseat 14). Ifby
the timethe timeout periodisoverandit hasnot received an ack for the previouswindowitstops
its transmission and retransmits the previous window. If however it receives no acks or
timeouts it keeps receiving ackscorrectlyand then sends an end transmission header.
3. 2. 2 Scenario #2 : Negative acknowledgments received.
Now considerthe scenario where some ofthe frames have to be retransmitteddue to
errors. As an examplesay that all 15 frameswere sent out,0..14. Now the receiver sees
frame 11 as an error. It sends out a Nack forframe 1 1 and discards
everything
following
this
frame.The
sender gets the Nack for frame 11. Onreceiving
a Nack it stopstransmission and makes the lowerend of its newworkingwindowthe
frame
numberforwhichthe Nackwas received. The newworkingwindowfor the senderandthe receiver
rJlPEDQII
CDEQB&fJFS
@mri]^[7,
0
1
2 3
45
6 7
8 9
10
1 1
12
13
14
1
1
15
16
17
18
o
u
\/ \/ \s
t
u
<
\^ \/ \/
0
1
2
3
4;
5
6 7J3
9
10
1 1
12
13
14
1
1
15
16
17
18
EQfJQflWQCr1
--.
Old
Wlndov
0..14
Nev
vtndov1 1.. 25
Thesender now moves its windowfrom 1 1 to
25
and it transmits these buffersand thentransmits the next window(that is from 26..40). The receiverat itsenddoes asimilarthing.
It moves
its
window upby
sending all the buffers0..10
to the client. The receiverthendiscards all frames received after the frame for which the Nack was sent and gets
3. 2. 3
Scenario
#3
:Sender time
outs.Consider the
casewherethe
N/ackcoming
ingets lost.The
sender would be left waitingforever for theacknowledgment.
Therefore
the sender must be made to time out aftera certain time.
This
fixed.presettime is definedby
the timeoutcalculation as shown insection
3.1.3. For the
sake ofsimplicity
let us considerthis time to be a quarter second.Let
the
sender send out its first twowindows of30
frames (0..29). Let us assumethat thefirstwindowof 15 frames all arrivedsafely andthatan ack was sent back. The receiver
has now updated itswindow to receive frames 15.. 29. Theirack however gets lost.
The
sender keeps track of what time each window was sent out
by
means ofthe
systemclock. While the sender has the timer running, it is mean while
transmitting
its nextwindow. If the N/ack comes back within this time out period one of the above
two
scenarios
(
#1 and#2)
is engaged.If however an ack is not received within this time limit the sender times out and
retransmits all the frames for that previous window again. The Receiver receives
these
frames
and accepts themknowing
thatthey
are part ofthe previouswindow andthendiscards them, asit already has them. It howeversends an ackback for the last frame
received in orelsethe sender wouldtimeout again and again retransmit. The problem
ariseswhen a Nackgets lostand atimeouttakesplace.
Consideras an example: Letthe sendersend packets 0..14. Letthe packet number 1 1
generate a Nack. Let this Nack be lost. The sender sends packet 14,starts a timer and
expectsan ackfor 14 before the timer runs out. Howeverthe ackfor 14will nevercome
as receiver hasupdated itswindowtostartfrom the badpacket (packet
#11)
andthe
The
senderwilleventually
time
out and retransmit all packets0
through 14 again.This
time
however itreceivesanackforpacket#10. As 10 lieswithinits workingwindowitnowrealizesthat the Nackwaslostand updates itswindowtostart at 1 1 and endat
25.
3.2.4
Scenario
#4 : Receivertime
outs.Though Receiver
time
outs are not required as it is handledby
thesendertiming
out,itcould
be implemented
as an efficiency measure. For example, in the case where thesendersends packets0.. 14. Ifa Nack is generatedforpacket#1 but this Nack gets
lost,
thenthe Receiver has towaittill thesendertimesout before
hoping
fora retransmission.This
howevercan beavoidedby
the
receivertiming
out andsending
a Nackagain.3.2.5
Headers&
Errors
The acceptability of errors in communications depends on the content,the data and
the ultimateuse
to
whichthe data is to be put. Extreme high error rates are acceptablein manycasesforexample: incertain
forms
oftelecommunication,
as the human brainhas the
abilityto
understand evenhighly
corrupted data. However no errors areacceptable in things
like
missile guidance systems. Stronger error detection schemeswill slow down thetransmission rates and hence the user musteventually
justify
what sortof error detection and correction scheme should be applied. The one advantage of
laser communications
is
that it is neither susceptible to transient errors(
those that arisedue to electromagnetic effects) nor generation of noise due to
interference,
commonto
radio wave transmissions. Interference with thebeam, however,
will result inloss
ofThe
headeris
animportant
partinthe
detection oferrors.The
headermust be suchthatit could
easily be
recognized within chunks of data.This
is specially important in thecase of
this implementation
as allincomming
packets are buffered beforethey
areactuallyprocessed. It is important that the header explicitlystatethe packetsequence
number and
the
numberofbytes
in the packet.The
actual number ofdata charactersin
the
packetcould be left upto
the programmerto implementand I havechosen1023
as
the
numberofdatacharacters in thepacket. There isalsoan end of packet marker,bringing
the totalsizeofthe packet 1024 bytes (0..1023as represented in theprogram).Hence in the detectionoferrors,thepacketsequence numberis the first
thing
itlooks
forin
the
header. If it is the correct packetsequence number orthe one it expects then itcoulddo one oftwo things
1)
itcould goonlooking
fora end of packet markerand if itfinds one it could check
to
see if itis
has picked up the number of characters asspecified in the packet header. If it
has,
then it would know that it has picked up theentirepacket. If however ithas notpicked up enoughcharacters and it findsan end of
packet markerthen itknows that the marker
is to
be treated as data and moves on tofind
another one. If itdoes
notfind
the markerby
the time it pulls out the number ofcharacters as specified
by
the header, the receiver then knows thatsomething
hasgonewrong and sendsanackfor thesequence numberit is holding.
2)
Another wayofhandling
the same situation iswherethe receiverpicksup thenumberof characters specified in the headerfrom the large input port buffer, it then checksto
see if the lastcharacter picked up isequalto the end of packet marker. This
technique
As
afurther
measure indetecting
errors atechnique
more commonly known as bytestuffing
canbe
implemented.
Itis implemented
in the current version ofthe program I am running. Ifthe
end of packet marker exists as data within the packet itselfthen,
another marker is put in front or behind it
indicating
that this is data and must not betreated
asthe
end of packet. Hencewhen it encounters 2 such consecutive markers,and
the
number of characters pulled out for that packetis
less thanthe
number ofcharacters in the header , it realizes that the end of packet marker is partof
the
dataand hence accepts one of them and discards the other. As in the case of all error
checking
schemesthere are no guarantees, but at least thiswill reducethe
chance oferrors.
The error detection scheme mentioned here has worked
flawlessly
in all the testsconducted and has detected errors correctly. Another detection scheme
implemented is theactual counting of charactersafterthe byte
stuffing
andtheend ofpacket markerhas been strippedoff.
3. 3. 0 Conclusions.
In my opinion the perfect protocol, that is one thatwill tosuit all needs with maximum
optimization(if such a
thing
does exist) is still along
way frombeing
solved.There
aremany
constraintsinthis problem which addto makingan solution very difficult.None
the
lessthe
error detectionscheme and the time optimization scheme proposedby
thesliding
window protocol isgood and in lieuofanything better,
isa scheme I wouldpropose be used. I also feelthe modificationsto the
sliding
windowprotocolthat Ihave
putforward are alsovalid situations though I do have recommendations put
forward
inCHAPTER
4
PROGRAMMING
DESIGN
4.0.0
Introduction.
This
chapter will dealwiththepeculiarities ofthe language and thedisplay
environmentwhich playedanintegralpart in the designofthesoftware for thisprogram.
4.1.0 The Language.
The program to implement theprotocol
is
written in theC
language. The Compilerusedis called Lightspeed
C
developedby
Think Technologies. This compiler follows thesyntax as defined under ANSI C. There are advantages and disadvantages in this
compilerand a brief discussion ofthem willfollow. None the less this compiler
is
good inthe sense that it supports the entire ANSI
C
language and yet, is fast enough to useeffectively. Lightspeed
C
is fast and very easy to learn. The unusualthing
inusing
theMacintosh is how to adapt oneself to use the toolBox routines which are written in
Pascal. This is discussed in 3. 1.1 and its use can be seen extensively in the code.
4. 1. 1 The Think
C
Language.a) Under Think
C
pascal is a reserved word. An identifier which has beendeclared
aspascal must have type "function returning...". A pascal function is called
using
pascalb)
Under
C,
eachstring
is
terminated
by
a nullbyte
('\0'). The programscansthe string tillit
finds the
nullbyte
inorderfor it to know the endofstring. However the Macintosh toolbox routines are written in Pascal. Unlike
C,
the Pascal string is not terminatedby
a nullbyte.
Instead
itcontainsabyte
in thebeginning
which indicates the lengthofthestring.example:
C
version :-DrawStringC'HELLO
WORLDXO")
Pascal version :- DrawStringC"
11
HELLO
WORLD")
Passing
astring
ofC
type into a tool Box routine requiring a Pascal type will causegarbage to be printed on the screen
along
with parts of the string. To over come thisproblem Think
C
has a special identifierwhich convertsC
stringstoa Pascalstring
type.This is done
by
putting
either\p
or\Pasthe firstcharacterin thestring.Hence it appears
something
like this:-DrawString("\pHello
World").c) When passing parametersinto pascal routinesthe need to pass it
by
reference mayarise. Think
C
has rulesthatallowstheC
programmerto do the right thing.4.2.0
Events,
their use and howthey
have affected the software design.In the Macintosh,an event can begenerated
by
the user ofthe application, other toolbox routines,device
drivers,
orthe application itself.Macintosh events hold descriptions of these occurrences in a part of the
operating
system called the Event Manager. The Event Manager captures some important
An application can get
information
by
retrieving Event Records from the event queueone at a
time. The Event
queueis
aFIFO
queue.The
Event Managergets eventsfrom allthe different
sources, queues them up and passes them to your application one at atime.
The
type of event occurred is stored in the event record as an integer number.There
are 12 predefined events and 4 userdefined events that can occur. The eventsdescribed
are.EYent
Integer ValuenullEvent
0
mouseDown 1
mouseUp 2
keydown 3
keyUp
4autoKey 5
updateEvt 6
diskEvt 7
activateEvt
8
networkEvt 10
driverEvt 11
applEvt 12
app2Evt 13
app3Evt 14
Hence
whenthe
mouseis
pressed downthe EventRecord
field what contains 1.The
where
field
contains the position ofthe mouse in global coordinates at the timethe
event was posted.
The
message field ofthe
event record containsthe event message,which conveys additional information about the event. The type of information
conveyed will
depend
on the type of event. For example if I were to press down theletter
C
onthe
keyboard,
then the EventRecord.what =3
and EventRecord.message ='C.
All the above
three
have been used extensively in the supporting software protocol.Another
thing
used, though not quite in conjunction with events, is TickCountO. In theevent record whenever an event takes place the event time is stored in terms of
TickCounts.
TickCounts return a
long
number and representthe number of ticks taken placefromstartup. TickCounts get updated every 1/60of a second. This is an important fraction in
the calculation forTime outs and propagation
delay
and has been widely used in theprogram.
Examples of use of events within the program.
Module procedures. c.
procedure
EventHandler(event)
EventRecord
"event;{
switch(event->what)
{
case nullEvent:
break;
case mouseDown:
HandleMouseDownO;
break;
case 1:
Module
procedures. c.procedure EventHandlerO.
type
message event.case mouseDown:
HandleMouseDownO;
break;
case mouseUp:
break;
case keyDown:
putout((int) event->message
&
0x7f).
Module
display.
cprocedure
EventHandlerO
type
: where event.HandleMouseDownO
r
WindowPtr
whichWindow;short int
thePart;
long
int menuChoice,windSize;
thePart =
FindWindow(
myEvent.where, 8cwhichWindow ); /*"tool box"
*/
switch
(
thePart)
/*the part returns a numberdescribing
where*/
(
case inMenuBar:
4.3.0
Macintosh
Resources,
and its implementation in the program.A betterpresentationof
the
programto
theuser will always bean addedattrac