Professional Documents
Culture Documents
CONTROL SYSTEM
Group Members
Muhammad Uzair Khan
ECI-IT-11-084
Nasir Taj
ECI-IT-12-009
ECI-IT-11-???
Bilal Ahmad
ECI-IT-11-063
Project Supervisor
Engr. Asghar Khan
Submitted By
M.Uzair Khan, Nasir Taj, A.Saboor Abbasi & Bilal Ahmad
Towards partial fulfillment of requirement for the award of degree of
Bachelors of Electrical Engineering
CERTIFICATE
This is to certify that this project report entitled PLC & SCADA Wireless Control System by
Muhammad Uzair Khan, Nasir Taj, Abdul Saboor Abbasi and Bilal Ahmad submitted in partial
fulfillment of the Requirements for The Bachelors of Electrical Engineering from Hamdard
University Karachi, Islamabad Campus is the record of candidates own work carried out by them
under our supervision & guidance. In our opinion the work submitted has reached a level
required for being accepted for exam. The matter embodied in this project has not been
submitted to any other university or institute.
_________________________
Committee:
1. Project Supervisor
_________________________
2. Examiner 1
_________________________
3. Examiner 2
_________________________
Signature
_________________________
Signature
_________________________
Signature
_________________________
Table of Contents
List of Figures............................................................................................................................vii
List of Tables...............................................................................................................................ix
List of Abbreviations & Notations...............................................................................................x
Dedication..................................................................................................................................xii
Acknowledgements...................................................................................................................xiii
Abstract.....................................................................................................................................xiv
CHAPTER 1 INTRODUCTION
TO
1.1
1.2
1.3
Foundation........................................................................................................................2
1.4
Project Materials...............................................................................................................3
Capacitors..........................................................................................................................5
2.1.1 Function............................................................................................................................5
2.1.2 Capacitors in Parallel........................................................................................................6
2.1.3 Capacitors in Series...........................................................................................................7
2.2
Resistors............................................................................................................................7
2.2.1 Function............................................................................................................................7
2.2.2 Connecting and Soldering.................................................................................................7
2.2.3 Resistor Values The resistor color code.........................................................................7
2.2.4 Tolerance of resistors (4rth band of color code)...............................................................8
2.2.5 Power rating of resistors...................................................................................................9
2.3
Relay.................................................................................................................................9
CHAPTER 3 METHODOLOGY.................................................................................................32
3.1
Introduction.....................................................................................................................32
3.2
3.3
Development...................................................................................................................33
Boards.............................................................................................................................39
CHAPTER 4 VOICE.................................................................................................................46
4.1
Transmitter Coding.........................................................................................................87
5.2
Receiver Coding..............................................................................................................88
ZigBee Layers.................................................................................................................94
A-i)
Physical layer..................................................................................................................94
A-ii)
MAC Layer....................................................................................................................95
BIBLIOGRAPHY......................................................................................................98
vi
List of Figures
Figure 2.1
5
Capacitor Symbol.......
Figure 2.2
Figure 2.3
Figure 2.4
Figure 2.5
Resistor.. 8
Figure 2.6
Color Code..... 8
Figure 2.7
Relay Symbol.....10
Figure 2.8
Figure 2.9
Relay Configuration...11
Figure 2.10
Relay Operation..... 11
Figure 2.11
Diode Symbol 12
Figure 2.12
Figure 2.13
Figure 2.14
Bridge Rectifier......... 14
Figure 2.15
Transformer............... 17
Figure 2.16
Figure 2.17
Figure 2.18
Figure 2.19
Figure 2.20
Figure 2.21
Figure 2.22
Figure 2.23
Figure 2.24
Figure 3.1
Figure 3.2
Figure 3.3
PLC Connections............................... 45
Figure 4.1
Figure 4.2
Figure 4.3
Figure 4.4
Figure 4.5
Dictation Test................................. 75
List of Tables
Table 2.1
Summary of ATmega328. .. 3
I Current
V Voltage
R Resistance
RD Read AC
WR Write
Amp Amplifier
Sen Sensor
D Diode
C Capacitance
Enc Encoder
Dec Decoder
Osc Oscillator
VR Voltage Regulator
Fc Carrier Frequency
GND Ground
F Farad
L Inductance
G Conductance
P Power
K Co-efficient
Db Decibel
pF Pico Farad
f Frequency
Kb Kilo Byte
Mb Mega Byte
Dedication
First of all we would to like to thank Allah Almighty the most gracious and the most merciful.
Specially dedicated to our families for their support and encouragement throughout our life.
Acknowledgements
Our project has been a result of our own hard work but this project could not have become a
reality without the support and help of many of our friends and faculty members. We take this
opportunity to acknowledge their help and thank them for their good will.
We would also like to express our special thanks of gratitude to Sir Asghar Khan for his support
and conceptual help at various technical problems. The very concept of the project as well as its
realization would not have been possible without him.
Lastly we would like to thank all the faculty members of Hamdard Institute of Engineering and
Technology (HIET) for their support throughout the Degree.
Apart from our faculty members we would also like to thank our classmates and friends for being
with us in this journey and making it memorable.
Abstract
Human necessities are increasing day by day whereas the factories are running out of resources.
To meet these demands industries need to improve the quality and quantity of their production.
Programmable logic controllers (PLCs) have been used for many decades for standard control in
industrial and factory environments. Over the years, PLCs have become computational efficient
and powerful, and a robust platform with applications beyond the standard control and factory
automation. This project deals with a hardboard industry designed automatic with the help of
PLC. This project focuses on an innovative and intelligent monitoring system of process using
SCADA (Supervisory control and data acquisition).
The project design a smart wireless industrial automation system (WIAS). This is fueled by the
Need to provide supporting systems for the industry. The automation centers on recognition of
Voice commands and uses low power RF ZigBee wireless communication modules which are
Relatively cheap. The home automation system is intended to control all lights and electrical
Appliances in an industry using voice commands.
Wireless industrial automation systems have drawn considerable attentions of the researchers for
More than a decade. The major technologies used to implement these systems include PLC,
SCADA & ZigBee.
Among these technologies the PLC & SCADA based systems have become very popular because
Of its low cost and low power consumption. In this proposal ZigBee based wireless home
Automation systems have been addressed.
The work through this project covered Programmable logic controllers and automated systems,
Supervisory control and data acquisition system (SCADA), Implementation of practical setup,
Results analysis and conclusions.
.2
The term SCADA stands for Supervisory Control and Data Acquisition. A SCADA system is a
common process automation system which is used to gather data from sensors and instruments
located at remote sites and to transmit and display this data at a central site for control or
monitoring purposes. The collected data is usually viewed on one or more SCADA Host
computers located at the central or master site.
PLC & SCADA Wireless Control System
A real world SCADA system can monitor and control hundreds to hundreds of thousands of I/O
points. A typical Water SCADA application would be to monitor water levels at various water
sources like reservoirs and tanks and when the water level exceeds a preset threshold, activate
the system of pumps to move water to tanks with low tank levels.
Common analog signals that SCADA systems monitor and control are levels, temperatures,
pressures, flow rate and motor speed. Typical digital signals to monitor and control are level
switches, pressure switches, generator status, relays & motors.
There is typically another layer of equipment between the remote sensors and instruments and
the central computer. This intermediate equipment exists on the remote side and connects to the
sensors and field instruments. Sensors typically have digital or analog I/O and these signals are
not in a form that can be easily communicated over long distances. The intermediate equipment
is used to digitize then packetize the sensor signals so that they can be digitally transmitted via
an industrial communications protocol over long distances to the central site.
.3 Foundation
Home/ Industrial automation is one of the major growing industries that can change the way
people live. Some of these home/Industrial automation systems target those seeking luxury and
sophisticated home/Industrial automation platforms; others target those with special needs like
the elderly and the disabled. The aim of the reported PLC AND SCADA BASED WIRELESS
VOICE COMMANDS CONTROLLED SYSTEM is to provide those with special needs with a
system that can respond to voice commands and control the on/off status of electrical
devices/machines, such as lamps, fans, television etc., in the home/Industry. The system should
be reasonably cheap, easy to configure, and easy to run.
The proposed project is based on the concept of home/factory automation and monitoring. In this
project, we are going to develop a project basically dependent on rf tx/tx, Microcontroller, relay,
voice recognition through computer etc. Here microcontroller is the heart of this project, Firstly
the power supply of 12v DC is very essential for this set up, this power supply trigger the
microcontroller atmega328, then the controller is directly connected with device control, rf at
receiver side gives the information regarding devices that can be operated by microcontroller &
device control here acting as a switch with the help of relays.
.4 Project Materials
The project consists of the following circuits:1.
2.
3.
4.
Transmitter circuit
Receiver circuit
PLC
Relays circuit
Computer
With voice
application
Computer
Scada
PLC & SCADA Wireless Control System
Interface circuit
Wireless
transmitter
Receiver and
Control circuit
Power
PLC
12Vdc
Load1
Load2
Load3
Load4
5 Theoretical Background
C HAPTER 2
THEORETICAL BACKGROUND
.1 Capacitors
Capacitors store electric charge. They are used with resistors in timing circuits because it takes
time for a capacitor to fill with charge
2.11 Function
Capacitors store electric charge. They are used with resistors in timing circuits because it takes
time for a capacitor to fill with charge. They are used to smooth varying DC supplies by acting as
a reservoir of charge. They are also used in filter circuits because capacitors easily pass AC
(changing) signals but they block DC (constant) signals.
6 Theoretical Background
2.11.2
Capacitors in Parallel
Capacitors in a parallel configuration each have the same applied voltage. Their capacitances add
up. Charge is apportioned among them by size. Using the schematic diagram to visualize parallel
Plates, it is apparent that each capacitor contributes to the total surface area.
2.11.3
Capacitors in Series
PLC & SCADA Wireless Control System
7 Theoretical Background
Connected in series, the schematic diagram reveals that the separation distance, not the plate
area, adds up. The capacitors each store instantaneous charge build-up equal to that of every
other capacitor in the series. The total voltage difference from end to end is apportioned to each
capacitor according to the inverse of its capacitance. The entire series acts as a
capacitor smaller than any of its components.
.2 Resistors
2.21 Function
Resistors restrict the flow of electric current, for example a resistor is placed in series with a
light-emitting diode (LED) to limit the current passing through the LED.
and M . 1 k
= 1000
1M
= 1000000 .
The fourth band is used to shows the tolerance (precision) of the resistor, this may be
ignored for almost all circuits but further details are given below.
PLC & SCADA Wireless Control System
8 Theoretical Background
The Resistor
Color Code
Number
Black
small values
Brown
two special
Red
Orange
Yellow
Green
Blue
Violet
Grey
White
show these
colors are
used for the
third band:
gold which
means 0.1
and silver
which means
0.01. The
first and
second bands
represent the
digits as normal.
For example:
red, violet, gold bands represent 27 0.1 = 2.7
green, blue, silver bands represent 56 0.01 = 0.56
PLC & SCADA Wireless Control System
9 Theoretical Background
resistor with a
tolerance of 10% will have a value within 10% of 390 , between 390 - 39 = 351
39 = 429
and 390 +
A special colour code is used for the fourth band tolerance: silver 10%, gold 5%, red 2%,
brown 1%. If no fourth band is shown the tolerance is 20%.
Tolerance may be ignored for almost all circuits because precise resistor values are rarely
required.
P =
or
P = V / R
power
current
developed
through
resistance
of
in
the
the
the
resistor
resistor
resistor
in
in
in
watts
(W)
amps
(A)
ohms
( )
10 Theoretical Background
.3 Relay
A relay is an electrically operated switch. Current flowing through the coil of the relay creates a
magnetic field which attracts a lever and changes the switch contacts. The coil current can be on
or off so relays have two switch positions and they are double throw (changeover) switches.
Relays allow one circuit to switch a second circuit which can be completely separate from the
first. For example a low voltage battery circuit can use a relay to switch a 230V AC mains
circuit. There is no electrical connection inside the relay between the two circuits; the link is
magnetic and mechanical.
The coil of a relay passes a relatively large current, typically 30mA for a 12V relay, but it can be
as much as 100mA for relays designed to operate from lower voltages. Most ICs (chips) cannot
provide this current and a transistor is usually used to amplify the small IC current to the larger
value required for the relay coil. The maximum output current for the popular 555 timer IC is
200mA so these devices can supply relay coils directly without amplification.
11 Theoretical Background
Relays can switch AC and DC, transistors can only switch DC.
Relays can switch high voltages, transistors cannot.
Relays are a better choice for switching large currents (> 5A).
Relays can switch many contacts at once.
For Relays are bulkier than transistors for switching small currents.
Relays cannot switch rapidly (except reed relays), transistors can switch many times per
second.
Relays use more power due to the current flowing through their coil.
Relays require more current than many ICs can provide, so a low power transistor
may be needed to switch the current the relay's coil.
12 Theoretical Background
2.4 Microphone
In order to speak to larger groups of people, there was a desire to increase the volume of the
spoken word. The earliest known device to achieve this dates to 600 BC with the invention of
masks with specially designed mouth openings that acoustically augmented the voice in
amphitheatres. In 1665, the English physicist Robert Hooke was the first to experiment with a
medium other than air with the invention of the "lovers' telephone" made of stretched wire with a
cup attached at each end.
German inventor Johann Philipp Reis designed an early sound transmitter that used a metallic
strip attached to a vibrating membrane that would produce intermittent current. Better results
were achieved with the 'liquid transmitter' design in Scottish-American Alexander Graham Bell's
telephone of 1876 the diaphragm was attached to a conductive rod in an acid solution. These
systems, however, gave a very poor sound quality.
2.5 Diode
The most basic property of a junction diode is that it conducts an electric current in one
direction and blocks it in the other. This behavior arises from the electrical characteristics
of a junction, called a p-n junction. Fabricated within a semiconductor crystal. The most
commonly used semiconductor material is silicon. The junction diode is useful in a wide
variety of applications including the rectification of ac signals (producing dc from ac), the
detection of radio signals, the conversion of solar power to electricity, and in the
generation and detection of light. It also finds use in a variety of electronic circuits as a
switch, as a voltage reference or even as a tunable capacitor. The p-n junction is also the
basic building block of a host of other electronic devices, of which the most well-known
is the junction transistor.
In our project we have used a diode as a rectifier basically it is a full wave rectifier used
to convert ac in to dc in the power supply portion of the project.
13 Theoretical Background
14 Theoretical Background
bridge arrangement to
achieve
rectification. It is called
because
the
are
it
uses
full-wave
rated
full-wave
rectifier
by
the
maximum current they can pass and the maximum reverse voltage they can withstand (this must
be at least three times the supply RMS voltage so the rectifier can withstand the peak voltages).
This is a widely used configuration, both with individual diodes wired as shown and with single
component bridges where the diode bridge is wired internally.
15 Theoretical Background
16 Theoretical Background
One advantage of a bridge rectifier over a conventional full-wave rectifier is that with a given
transformer the bridge rectifier produces a voltage output that is nearly twice that of the
conventional full-wave circuit.
2.7.2 Applications
The primary application of rectifiers is to derive DC power from an AC supply. Virtually all
electronics require a DC supply but mains power is AC so rectifiers find uses inside the power
supplies of virtually all electronic equipment.
2.8 Transformer
A transformer is a device that transfers electrical energy from one circuit to another through
inductively coupled electrical conductors. A changing current in the first circuit (the primary)
creates a changing magnetic field. This changing magnetic field induces a changing voltage in
the second circuit (the secondary). This effect is called mutual induction.
Transformers are passive electrical devices that transform alternating or intermittent electric
energy in one circuit into energy of a similar type in another circuit, commonly with altered
values of voltage and current. It typically contains two or more electrical circuits comprising
primary and secondary windings, each made of a multi-turn coil of electrical conductors with
one or more magnetic cores coupling the coils by transferring a magnetic flux there between.
Increasingly, modern day appliances are constructed using low voltage transformers for many
purposes including as lighting transformers or to supply power to electronic components.
17 Theoretical Background
A transformer is based on a very simple fact about electricity: when a fluctuating electric current
flows through a wire, it generates a magnetic field (an invisible pattern of magnetism) or
"magnetic flux" all around it. The strength of the magnetism (which has the rather technical
name of magnetic flux density) is directly related to the size of the electric current. So the bigger
the current, the stronger the magnetic field. Now there's another interesting fact about electricity
too. When a magnetic field fluctuates around a piece of wire, it generates an electric current in
the wire. So if we put a second coil of wire next to the first one, and send a fluctuating electric
current into the first coil, we will create an electric current in the second wire. This is called
electromagnetic induction because the current in the first coil causes (or "induces") a current in
the second coil. The current in the first coil is usually called the primary current and the current
in the second wire is (surprise, surprise) the secondary current. What we've done here is pass an
electric current through empty space from one coil of wire to another. This phenomenon is called
electromagnetic induction. We can make electrical energy pass more efficiently from one coil to
the other by wrapping them around a soft iron bar (sometimes called a core):
18 Theoretical Background
One important thing to note is that this trick works only if the electric current is fluctuating in
some way. In other words, you have to use a type of constantly reversing electricity called
alternating current (AC) with a transformer. Transformers do not work with direct current (DC),
where the current constantly flows in the same direction.
19 Theoretical Background
same as the power in the primary coil. (In reality, there is some loss of power between the
primary and the secondary because some of the "magnetic flux" leaks out of the core; some
energy is lost because the core heats up, and so on.)
Ideal power equation
Pin = IPVP = Pout = ISVS
Ideal transformer equation
2.9
7812 is a famous IC which is being widely used in 12V voltage regulator circuits. Truly speaking
it is a complete standalone voltage regulator. We only need to use two capacitors, one on the
input and second one on the output of 7812 in order to achieve clean voltage output and even
these capacitors are optional to use. To achieve 12V 1A current, 7812 should be mounted on a
good heat sink plate. Thanks to the transistor like shape of 7812 which makes it easy to mount on
a heat sink plate. 7812 has built in over heat and short circuit protection which makes it a good
choice for making power supplies.
20 Theoretical Background
In electronics markets, 7812 is sold under various names such as 7812a, 7812act, 7812t and
lm7812. All of them are almost identical with a little to no differences at all. 7812 input voltage
range is 14V to 35V. Exceeding the voltage range may damage the IC. Given bellow is 7812
pin diagram to make the pinout connections clear in case you want to do some experiments.
21 Theoretical Background
resistor
on
its
output.
Following is the link to a simple but complete power supply circuit diagram developed using
7812.
22 Theoretical Background
The Uno differs from all preceding boards in that it does not use the FTDI USB-to-serial driver
chip. Instead, it features the Atmega16U2 (Atmega8U2 up to version R2) programmed as a
USB-to-serial converter.
Revision 2 of the Uno board has a resistor pulling the 8U2 HWB line to ground, making it easier
to put into DFU mode Revision 3 of the board has the following new features:
1.0 pinout: added SDA and SCL pins that are near to the AREF pin and two other new pins
placed near to the RESET pin, the IOREF that allow the shields to adapt to the voltage provided
from the board. In future, shields will be compatible with both the board that uses the AVR,
which operates with 5V and with the Arduino Due that operates with 3.3V. The second one is a
not connected pin that is reserved for future purposes.
Stronger RESET circuit.
At mega 16U2 replace the 8U2.
"Uno" means one in Italian and is named to mark the upcoming release of Arduino 1.0. The Uno
and version 1.0 will be the reference versions of Arduino, moving forward. The Uno is the latest
in a series of USB Arduino boards, and the reference model for the Arduino platform;
23 Theoretical Background
2.10.1 Synopsis
Table 2.1 Summary of ATmega328
Microcontroller
ATmega328
Operating Voltage
5V
7-12V
6-20V
40 mA
50 mA
Flash Memory
SRAM
2 KB (ATmega328)
PLC & SCADA Wireless Control System
24 Theoretical Background
EEPROM
1 KB (ATmega328)
Clock Speed
16 MHz
2.10.3 Power
The Arduino Uno can be powered via the USB connection or with an external power supply. The
power source is selected automatically.
External (non-USB) power can come either from an AC-to-DC adapter (wall-wart) or battery.
The adapter can be connected by plugging a 2.1mm center-positive plug into the board's power
jack. Leads from a battery can be inserted in the GND and Vin pin headers of the POWER
connector.
The board can operate on an external supply of 6 to 20 volts. If supplied with less than 7V,
however, the 5V pin may supply less than five volts and the board may be unstable. If using
more than 12V, the voltage regulator may overheat and damage the board. The recommended
range is 7 to 12 volts.
The power pins are as follows:
VIN. The input voltage to the Arduino board when it's using an external power source (as
opposed to 5 volts from the USB connection or other regulated power source). You can supply
voltage through this pin, or, if supplying voltage via the power jack, access it through this pin.
5V.This pin outputs a regulated 5V from the regulator on the board. The board can be supplied
with power either from the DC power jack (7 - 12V), the USB connector (5V), or the VIN pin of
the board (7-12V). Supplying voltage via the 5V or 3.3V pins bypasses the regulator, and can
damage your board. We don't advise it.
PLC & SCADA Wireless Control System
25 Theoretical Background
3V3. A 3.3 volt supply generated by the on-board regulator. Maximum current draw is 50 mA.
GND. Ground pins.
IOREF. This pin on the Arduino board provides the voltage reference with which the
microcontroller operates. A properly configured shield can read the IOREF pin voltage and select
the appropriate power source or enable voltage translators on the outputs for working with the
5V or 3.3V.
2.10.4 Memory
The ATmega328 has 32 KB (with 0.5 KB used for the boot loader). It also has 2 KB of SRAM
and 1 KB of EEPROM (which can be read and written with the EEPROM library).
26 Theoretical Background
to change the upper end of their range using the AREF pin and the analog Reference() function.
Additionally, some pins have specialized functionality:
TWI: A4 or SDA pin and A5 or SCL pin. Support TWI communication using the Wire library.
There are a couple of other pins on the board:
AREF. Reference voltage for the analog inputs. Used with analogReference().
Reset. Bring this line LOW to reset the microcontroller. Typically used to add a reset button to
shields which block the one on the board.
See also the mapping between Arduino pins and ATmega328 ports. The mapping for the
Atmega8, 168, and 328 is identical.
2.10.6 Communication
The Arduino Uno has a number of facilities for communicating with a computer, another
Arduino, or other microcontrollers. The ATmega328 provides UART TTL (5V) serial
communication, which is available on digital pins 0 (RX) and 1 (TX). An ATmega16U2 on the
board channels this serial communication over USB and appears as a virtual com port to
software on the computer. The '16U2 firmware uses the standard USB COM drivers, and no
external driver is needed. However, on Windows, an .inf file is required. The Arduino software
includes a serial monitor which allows simple textual data to be sent to and from the Arduino
board. The RX and TX LEDs on the board will flash when data is being transmitted via the USBto-serial chip and USB connection to the computer (but not for serial communication on pins 0
and 1).
A Software Serial library allows for serial communication on any of the Uno's digital pins.
The ATmega328 also supports I2C (TWI) and SPI communication. The Arduino software
includes a Wire library to simplify use of the I2C bus; see the documentation for details. For SPI
communication, use the SPI library.
2.10.7 Programming
27 Theoretical Background
The Arduino Uno can be programmed with the Arduino software (download). Select "Arduino
Uno from the Tools > Board menu (according to the microcontroller on your board). For details,
see the reference and tutorials.
The ATmega328 on the Arduino Uno comes pre burned with a boot loader that allows you to
upload new code to it without the use of an external hardware programmer. It communicates
using the original STK500 protocol (reference, C header files).
You can also bypass the boot loader and program the microcontroller through the ICSP (InCircuit Serial Programming) header using Arduino ISP or similar; see these instructions for
details.
The ATmega16U2 (or 8U2 in the rev1 and rev2 boards) firmware source code is available.
The ATmega16U2/8U2 is loaded with a DFU boot loader, which can be activated by:
On Rev1 boards: connecting the solder jumper on the back of the board (near the map of Italy)
and then resetting the 8U2.
On Rev2 or later boards: there is a resistor that pulling the 8U2/16U2 HWB line to ground,
making it easier to put into DFU mode.
You can then use Atmel's FLIP software (Windows) or the DFU programmer (Mac OS X and
Linux) to load a new firmware. Or you can use the ISP header with an external programmer
(overwriting the DFU boot loader). See this user-contributed tutorial for more information.
28 Theoretical Background
This setup has other implications. When the Uno is connected to either a computer running Mac
OS X or Linux, it resets each time a connection is made to it from software (via USB). For the
following half-second or so, the boot loader is running on the Uno. While it is programmed to
ignore malformed data (i.e. anything besides an upload of new code), it will intercept the first
few bytes of data sent to the board after a connection is opened. If a sketch running on the board
receives one-time configuration or other data when it first starts, make sure that the software with
which it communicates waits a second after opening the connection and before sending this data.
The Uno contains a trace that can be cut to disable the auto-reset. The pads on either side of the
trace can be soldered together to re-enable it. It's labeled "RESET-EN". You may also be able to
disable the auto-reset by connecting a 110 ohm resistor from 5V to the reset line; see this forum
thread for details.
29 Theoretical Background
30 Theoretical Background
31 Theoretical Background
32 Theoretical Background
12) I/O output expansion header cover [units of 20 points or beyond only], with esthetic purpose
and capable of securing expansion cable.
13) FBS-CB22 Communication Board (CB).
14) FBS-CB22 CB cover plate (each CB has its own specific cover plate)
33 Industrial Scope
C HAPTER 3
METHODOLOGY
3.1 Introduction
In our project we have used Arduino IDE for Atmega328 programming, and Eagle for PCB
designing. Before we explain our project code lets first discus some basic principles of the
Arduino IDE.
setup(): a function run once at the start of a program that can initialize settings
A typical first program for a microcontroller simply blinks an LED on and off. In the Arduino
environment, the user might write a program like this:
#define LED_PIN 13
void setup () {
pinMode (LED_PIN, OUTPUT); // Enable pin 13 for digital output
}
34 Industrial Scope
void loop () {
digitalWrite (LED_PIN, HIGH); // Turn on the LED
delay (1000); // Wait one second (1000 milliseconds)
digitalWrite (LED_PIN, LOW); // Turn off the LED
delay (1000); // Wait one second
}
It is a feature of most Arduino boards that they have an LED and load resistor connected
between pin 13 and ground; a convenient feature for many simple tests. The previous code would
not be seen by a standard C++ compiler as a valid program, so when the user clicks the "Upload
to I/O board" button in the IDE, a copy of the code is written to a temporary file with an extra
include header at the top and a very simple main() function at the bottom, to make it a valid C++
program.
The Arduino IDE uses the GNU tool chain and AVR Libc to compile programs, and uses avrdude
to upload programs to the board.
As the Arduino platform uses Atmel microcontrollers, Atmel's development environment, AVR
Studio or the newer Atmel Studio, may also be used to develop software for the Arduino.
.3 Development
Arduino is open source hardware: the Arduino hardware reference designs are distributed under
a Creative Commons Attribution Share-Alike 2.5 license and are available on the Arduino Web
site. Layout and production files for some versions of the Arduino hardware are also available.
The source code for the IDE is available and released under the GNU General Public License,
version 2.
Although the hardware and software designs are freely available under copy left licenses, the
developers have requested that the name "Arduino" be exclusive to the official product and not
be used for derivative works without permission. The official policy document on the use of the
Arduino name emphasizes that the project is open to incorporating work by others into the
official product. Several Arduino-compatible products commercially released have avoided the
"Arduino" name by using "-duino" name variants.
3.31.1
35 Industrial Scope
The Arduino development environment contains a text editor for writing code, a message area, a
text console, a toolbar with buttons for common functions, and a series of menus. It connects to
the Arduino hardware to upload programs and communicate with them.
36 Industrial Scope
Save
Saves your sketch.
Serial
Monitor
37 Industrial Scope
This formats your code nicely: i.e. indents it so that opening and closing curly braces line up,
and that the statements inside curly braces are indented more.
Archive Sketch
Archives a copy of the current sketch in .zip format. The archive is placed in the same directory
as the sketch.
Board
Select the board that you're using. See below for descriptions of the various boards.
Serial Port
This menu contains all the serial devices (real or virtual) on your machine. It should
automatically refresh every time you open the top-level tools menu.
Programmer
For selecting a hardware programmer when programming a board or chip and not using the
onboard USB-serial connection. Normally you won't need this, but if you're burning a boot
loader to a new microcontroller, you will use this.
Burn-Boot loader
the items in this menu allow you to burn a boot loader onto the microcontroller on an Arduino
board. This is not required for normal use of an Arduino board but is useful if you purchase a
new ATmega microcontroller (which normally come without a boot loader). Ensure that you've
selected the correct board from the Boards menu before burning the boot loader.
3.31.3
Sketch Book
The Arduino environment uses the concept of a sketchbook: a standard place to store your
programs (or sketches). The sketches in your sketchbook can be opened from the File >
Sketchbook menu or from the Open button on the toolbar. The first time you run the Arduino
software, it will automatically create a directory for your sketchbook. You can view or change
the location of the sketchbook location from with the Preferences dialog.
'''Beginning with version 1.0, files are saved with an .ino file extension. Previous versions use the
.pde extension. You may still open .pde named files in version 1.0 and later, the software will
automatically rename the extension to .ino.
38 Industrial Scope
Allows you to manage sketches with more than one file (each of which appears in its own tab).
These can be normal Arduino code files (no extension), C files (.c extension), C++ files (.cpp), or
header files (.h).
3.3.3.2 Uploading
Before uploading your sketch, you need to select the correct items from the Tools >
Board and Tools > Serial Port menus. The boards are described below. On the Mac, the serial
port is probably something like /dev/tty.usbmodem241 (for a Uno or Mega2560 or Leonardo)
or /dev/tty.usbserial-1B1 (for
Duemilanove
or
earlier
USB
board),
or
/dev
/tty.
3.3.3.3 Libraries
Libraries provide extra functionality for use in sketches, e.g. working with hardware or
manipulating data. To use a library in a sketch, select it from the Sketch > Import Library menu.
This will insert one or more #include statements at the top of the sketch and compile the library
PLC & SCADA Wireless Control System
39 Industrial Scope
with your sketch. Because libraries are uploaded to the board with your sketch, they increase the
amount of space it takes up. If a sketch no longer needs a library, simply delete its #include
statements from the top of your code.
There is a list of libraries in the reference. Some libraries are included with the Arduino software.
Others can be downloaded from a variety of sources. Starting with version 1.0.5 of the IDE, you
do can import a library from a zip file and use it in an open sketch. See these instructions for
installing a third-party library.
.4 Boards
The board selection has two effects: it sets the parameters (e.g. CPU speed and baud rate) used
when compiling and uploading sketches; and sets and the file and fuse settings used by the burn
bootloader command. Some of the board definitions differ only in the latter, so even if you've
been uploading successfully with a particular selection you'll want to check it before burning the
boot loader.
Arduino Uno
PLC & SCADA Wireless Control System
40 Industrial Scope
An ATmega328 running at 16 MHz with auto-reset, using the optiboot boot loader (115200 baud,
0.5 KB).
Arduino Duemilanove w/ ATmega328
An ATmega328 running at 16 MHz with auto-reset.
Arduino Diecimila or Duemilanove w/ ATmega168
An ATmega168 running at 16 MHz with auto-reset. Compilation and upload is equivalent to
Arduino NG or older w/ ATmega168, but the boot loader burned has a faster timeout (and blinks
the pin 13 LED only once on reset).
Arduino Nano w/ ATmega328
An ATmega328 running at 16 MHz with auto-reset. Has eight analog inputs.
Arduino Nano w/ ATmega168
An ATmega168 running at 16 MHz with auto-reset. Compilation and upload is equivalent to
Arduino NG or older w/ ATmega168, but the bootloader burned has a faster timeout (and blinks
the pin 13 LED only once on reset). Has eight analog inputs.
Arduino Mega 2560 or Mega ADK
An ATmega2560 running at 16 MHz with auto-reset, using a stk500v2 bootloader.
Arduino Mega (ATmega1280)
An ATmega1280 running at 16 MHz with auto-reset.
Arduino Leonardo
An ATmega32u4 running at 16 MHz with auto-reset.
Arduino Mini w/ ATmega328
An ATmega328 running at 16 MHz with auto-reset, using the optiboot bootloader (115200 baud,
0.5 KB). Has eight analog inputs.
Arduino Mini w/ ATmega168
41 Industrial Scope
Equivalent to Arduino NG
16 MHz without auto-reset).
or
older
w/ ATmega168 (i.e.
an ATmega168 running
at
Arduino Ethernet
Equivalent to Arduino UNO with an Ethernet shield.
Arduino Fio
An ATmega328 running at 8 MHz with auto-reset. Equivalent to Arduino Pro or Pro Mini (3.3V,
8 MHz) w/ ATmega328.
Arduino BT w/ ATmega328
ATmega328 running at 16 MHz The bootloader burned (4 KB) includes codes to initialize the
on-board Bluetooth module.
Arduino BT w/ ATmega168
ATmega168 running at 16 MHz the bootloader burned includes codes to initialize the on-board
Bluetooth module.
Lily Pad Arduino w/ ATmega328
An ATmega328 running at 8 MHz (3.3V) with auto-reset. Equivalent to Arduino Pro or Pro Mini
(3.3V, 8 MHz) w/ ATmega328.
Lily Pad Arduino w/ ATmega168
An ATmega168 running at 8 MHz Compilation and upload is equivalent to the Arduino Pro or
Pro Mini (8 MHz) w/ ATmega168. The bootloader burned, however, has a slower timeout (and
blinks the pin 13 LED three times on reset) because the original versions of the Lily Pad didn't
support auto-reset. They also didn't include an external clock, so the burn bootloader command
configures the fuses of ATmega168 for an internal 8 MHz clock.
If you have a recent version of the Lily Pad, (w/ a 6-pin programming header), you'll want to
select Arduino Pro or Pro Mini (8MHz) w/ ATmega168 before burning the bootloader.
Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328
An ATmega328 running at 16 MHz with auto-reset. Equivalent to Arduino Duemilanove or Nano
w/ ATmega328.
42 Industrial Scope
43 Industrial Scope
44 Industrial Scope
45 Industrial Scope
C HAPTER 4
VOICE
implements
You
can
find
abundant
Readymade SAPI 5.1 packages containing Automation components for Delphi 5, 6 and 7 can be
found in appropriately named subdirectories under SAPI 5.1 in the accompanying files.
If you are using Delphi 6 you will encounter a problem that is still present even with Update
Pack 2 installed. The type library importer has a bug where the parameters to Automation events
are incorrectly dispatched (they are sent in reverse order) meaning that all the Automation events
operate incorrectly (if at all). You can avoid this by importing the type library in Delphi 5 or 7
and using the generated type library import unit in Delphi 6. A Delphi 6 compatible package is
supplied with this article's files (it uses a Delphi 5 generated type library import unit).
The Delphi 7 type library importer has been improved to produce more accurate Pascal
representations of items in the type library than Delphi 5 did (and than Delphi 6 tried to). As a
result of this, the event handlers will often have different parameter lists in the Delphi 7 imported
type library. This means that the sample programs won't compile with Delphi 7 with the true
Delphi 7 SAPI type library import unit.
If you wish, you can write late bound Automation that calls CreateOleObject to instantiate the
Automation objects. In the case of the SpVoice interface, you would execute:
var
SpVoice: Variant;
...
SpVoice := CreateOleObject('SAPI.SpVoice')
begin
SpVoice1.Speak(memText.Text, SVSFDefault)
end;
And there you have it: a speaking application. The call to Speak takes a number of parameters
that we should examine:
The first is the text to speak, passed as a PChar. Because of the second parameter, this
call will be synchronous and so will not return until the text has been spoken.
The second parameter represents some flags that indicate how to use the first
parameter (you can combine multiple flags with the or operator). For example:
o SVSFDefault means the Speak method will be synchronous
o SVSFlagAsync makes the Speak method asynchronous and so it returns
immediately (you can use events to find out when speech terminates, or call
the WaitUntilDone method, or call SpeakCompleteEvent to receive a Win32
event
handle,
which
can
be
passed
to WaitForSingleObject).
Note that the Speak method returns a stream number. When queuing several
asynchronous voice streams, the stream number allows you to identify them;
each voice event passes the stream number to which it relates as a parameter.
o SVSFPurgeBeforeSpeak means any text being spoken and any text queued to
speak will be immediately cancelled.
o SVSFNLPSpeakPunc means punctuation marks are read out by their names,
rather than being used as punctuation (so ? is read out as question mark)
o SVSFIsFilename means the first parameter is a file name containing text to
speak.
o SVSFIsXML means the text includes XML tags to alter attributes of the
spoken text. For example this text controls the pitch, rate, volume, emphasis
and pronunciation of the spoken text:
o <EMPH>Hello</EMPH>
o <PRON SYM="d eh l f y">Delphi</PRON> developers!
o <VOLUME LEVEL="70">
o I can speak <PITCH MIDDLE="+10">high</PITCH> and <PITCH
MIDDLE="-10">low</PITCH>.
o I can speak <RATE SPEED="+10">very quickly</RATE> and <RATE
SPEED="-10">very slowly</RATE>.
o I can speak <VOLUME LEVEL="40">quietly</VOLUME> and <VOLUME
LEVEL="100">loudly</VOLUME>.
</VOLUME>
When the program executes it lets you type in some text in a memo and a button renders it into
the spoken word.
notice that as the text is spoken, the current sentence is italicized and the current word is
displayed selected and also the phonemes spoken are written to a memo.
The On Destroy event handler tidies up these descriptor objects by decrementing their reference
counts, thereby allowing them to be destroyed.
procedure TfrmTextToSpeech.FormDestroy(Sender: TObject);
var
I: Integer;
begin
//Release all the voice descriptors
for I := 0 to cbVoices.Items.Count - 1 do
ISpeechObjectToken(Pointer(cbVoices.Items.Objects[I]))._Release;
end;
When the user selects a different voice from the combobox, the OnChange event handler selects
the new voice and displays the voice attributes (including the path in the Windows registry where
the voice attributes are stored).
procedure TfrmTextToSpeech.cbVoicesChange(Sender: TObject);
var
SOToken: ISpeechObjectToken;
begin
with lstEngineInfo.Items do
begin
Clear;
SOToken := ISpeechObjectToken(Pointer(
cbVoices.Items.Objects[cbVoices.ItemIndex]));
SpVoice.Voice := SOToken;
Add(Format('Name: %s', [SOToken.GetAttribute('Name')]));
Add(Format('Vendor: %s', [SOToken.GetAttribute('Vendor')]));
Add(Format('Age: %s', [SOToken.GetAttribute('Age')]));
Add(Format('Gender: %s', [SOToken.GetAttribute('Gender')]));
Add(Format('Language: %s', [SOToken.GetAttribute('Language')]));
Add(Format('Reg key: %s', [SOToken.Id]));
end
end;
SpVoice.Resume;
BeenPaused := False
end
end;
procedure TfrmTextToSpeech.btnPauseClick(Sender: TObject);
begin
SpVoice.Pause;
BeenPaused := True
end;
procedure TfrmTextToSpeech.btnStopClick(Sender: TObject);
begin
SpVoice.Skip('Sentence', MaxInt)
end;
There
is
another speech
demo in
the
same
directory
in
the
project
TextToSpeechReadWordDoc.dpr. As the name suggests, this sample reads out loud from a Word
document. It uses Automation to control Microsoft Word (as well as the SAPI voice object).
type
TfrmVTxtAutoLateBound = class(TForm)
...
private
MSWord: Variant;
PLC & SCADA Wireless Control System
end;
...
procedure TfrmTextToSpeechReadWordDoc.FormCreate(Sender: TObject);
begin
MSWord := CreateOleObject('Word.Application');
end;
begin
MSWord.Documents.Open(FileName := dlgOpenDoc.FileName);
Moved := 2;
while (Moved > 1) and not Stopped do
begin
//Select next paragraph
Moved := MSWord.Selection.EndOf(Unit:=wdParagraph, Extend:=wdExtend);
if Moved > 1 then
begin
Txt := Trim(MSWord.Selection.Text);
if Length(Txt) > 0 then
SpVoice.Speak(Txt, SVSFlagsAsync);
Application.ProcessMessages;
//Move to start of next paragraph
MSWord.Selection.MoveRight(Unit := wdCharacter);
end
end;
end;
MSWord.ActiveDocument.Close;
TButton(Sender).Enabled := True;
end;
PLC & SCADA Wireless Control System
const
Phonemes: array[1..49] of String = (
'-', '!', '&', ',', '.', '?', '_',
'1', '2', 'aa', 'ae', 'ah', 'ao', 'aw',
'ax', 'ay', 'b', 'ch', 'd', 'dh', 'eh',
'er', 'ey', 'f', 'g', 'h', 'ih', 'iy',
'jh', 'k', 'l', 'm', 'n', 'ng', 'ow',
'oy', 'p', 'r', 's', 'sh', 't', 'th',
'uh', 'uw', 'v', 'w', 'y', 'z', 'zh'
);
procedure TfrmTextToSpeech.SpVoicePhoneme(Sender: TObject;
StreamNumber: Integer; StreamPosition: OleVariant; Duration: Integer;
NextPhoneId: Smallint; Feature: TOleEnum; CurrentPhoneId: Smallint);
begin
if CurrentPhoneId <> 7 then //Display phonemes, except silence
memEnginePhonemes.Text :=
memEnginePhonemes.Text + Phonemes[CurrentPhoneId] +'-'
end;
English speech and these are based on the Disney 13 visemes (cartoons have less granularity and
Disney animators discovered many years ago that only 13 cartoon mouth shapes are required to
represent all English phonemes).
If you have some artistic flair and can draw a mouth in each position represented by the visemes
you could use this event to provide a simple animated representation of speech.
The SAPI 5.1 SDK comes with a C++ example called TTSApp, which displays an animated
cartoon microphone whose mouth is drawn to represent each viseme. The microphone is made
up from a number of separate images that can all be loaded into an image list. The
additional demo program TextToSpeechAnimated.dpr makes use of these images to show how
the effect can be achieved.
const
Visemes: array[0..21] of Byte = (
0, // SP_VISEME_0 = 0,
// Silence
11, // SP_VISEME_1,
// AE, AX, AH
11, // SP_VISEME_2,
// AA
11, // SP_VISEME_3,
// AO
10, // SP_VISEME_4,
// EY, EH, UH
11, // SP_VISEME_5,
// ER
9, // SP_VISEME_6,
// y, IY, IH, IX
2, // SP_VISEME_7,
// w, UW
13, // SP_VISEME_8,
// OW
9, // SP_VISEME_9,
// AW
12, // SP_VISEME_10,
// OY
PLC & SCADA Wireless Control System
11, // SP_VISEME_11,
// AY
9, // SP_VISEME_12,
// h
3, // SP_VISEME_13,
// r
6, // SP_VISEME_14,
// l
7, // SP_VISEME_15,
// s, z
8, // SP_VISEME_16,
5, // SP_VISEME_17,
// TH, DH
4, // SP_VISEME_18,
// f, v
7, // SP_VISEME_19,
// d, t, n
9, // SP_VISEME_20,
// k, g, NG
1 // SP_VISEME_21,
// p, b, m
);
end;
procedure
TfrmTextToSpeech.SetTextStyle(FirstChar,
Len:
Integer;
Styles:
TFontStyles);
begin
with reText do
begin
Lines.BeginUpdate;
try
SelStart := FirstChar; //highlight word
SelLength := Len;
SelAttributes.Style := Styles; //apply requested style
SelLength := 0; //unhighlight word
finally
Lines.EndUpdate
end
end
end;
Length: Integer);
begin
Log('OnSentence: stream %d, position: %s, char. pos. %d, length %d',
[StreamNumber, String(StreamPosition), CharacterPosition, Length]);
SetTextStyle(OldSentencePos, OldSentenceLen, []);
if Length > 0 then
begin
SetTextStyle(CharacterPosition, Length, [fsItalic]);
OldSentencePos := CharacterPosition;
OldSentenceLen := Length;
end;
if not StreamJustStarted then
memEnginePhonemes.Text := memEnginePhonemes.Text + #13#10;
StreamJustStarted := False;
end;
var
Voice: Variant;
Screen.OnActiveFormChange := ScreenFormChange;
end;
DialogText := Format('%s.%s%s.%s%s',
[Form.Caption, sLineBreak, LabelCaption, sLineBreak, ButtonCaptions]);
Memo1.Text := DialogText;
Voice.Speak(DialogText, SVSFlagsAsync)
except
//pretend everything is okay
end
end;
Recognition contexts enable you to start and stop recognition, set up the grammar and receive
important recognition notifications.
4.9.1 Grammars
Part of the process of speech recognition involves deciding what words have actually been
spoken. Recognisers use a grammar to decide what has been said, where possible. SAPI 5.x
represents grammars in XML.
In the case of dictation, a grammar can be used to indicate some words that are likely to be
spoken. It is not feasible to try and represent the entire spoken English language as a grammar so
the recogniser uses its own rules and context analysis, with any help from a grammar you might
supply.
With Command and Control, the words that are understood are limited to the supported
commands defined in the grammar. The grammar defines various rules that dictate what will be
said and this makes the recogniser's job much easier. Rather than trying to understand anything
spoken, it only needs to recognise speech that follows the supplied rules. A simple grammar that
recognises three colours might look like this:
<GRAMMAR LANGID="809">
colour red
colour blue
colour green
<GRAMMAR LANGID="809">
<DEFINE>
<ID NAME="RID_start" VAL="1"/>
</DEFINE>
<RULE NAME="colour">
<L>
<P>red</P>
<P>blue</P>
<P>green</P>
</L>
</RULE>
</GRAMMAR>
You can find more details about the supported grammar syntax in the SAPI documentation
Delphi events in the Delphi Automation object component wrappers. This greatly simplifies the
job of responding to the notifications.
The main event is OnRecognition, which is called when the SR engine has decided what has
been spoken. Whilst working it out, it will likely call theOnHypothesis event several times.
Finished phrases are added to a memo on the form and whilst a phrase is being worked out the
hypotheses are added to a list box so you can see how the SR engine made its decision. Each
time a new phrase is started, the hypothesis list is cleared.
You can see the list of hypotheses building up in this screenshot of the program running.
object.
In
passed
Delphi
a Result parameter;
7
this
is
declared
this
is
using
the
correct ISpeechRecoResult interface type, but in earlier versions this was just declared as
an OleVariant (which contained the ISpeechRecoResult interface).
This code can be used in Delphi 6 and earlier to access the text that was recognised:
procedure TfrmContinuousDictation.SpSharedRecoContextHypothesis(
Sender: TObject; StreamNumber: Integer; StreamPosition: OleVariant;
var Result: OleVariant);
begin
lstHypotheses.Items.Add(Result.PhraseInfo.GetText);
lstHypotheses.ItemIndex := lstHypotheses.Items.Count - 1
end;
procedure TfrmContinuousDictation.SpSharedRecoContextRecognition(
Sender: TObject; StreamNumber: Integer; StreamPosition: OleVariant;
RecognitionType: TOleEnum; var Result: OleVariant);
begin
memText.SelText := Result.PhraseInfo.GetText + #32
end;
This code uses late bound Automation on the results object (so no Code Completion or Code
Parameters), but you could use early bound Automation with:
PLC & SCADA Wireless Control System
procedure TfrmContinuousDictation.SpSharedRecoContextHypothesis(
Sender: TObject; StreamNumber: Integer; StreamPosition: OleVariant;
var Result: OleVariant);
var
SRResult: ISpeechRecoResult;
begin
SRResult := IDispatch(Result) as ISpeechRecoResult;
lstHypotheses.Items.Add(SRResult.PhraseInfo.GetText(0, -1, True));
lstHypotheses.ItemIndex := lstHypotheses.Items.Count - 1
end;
procedure TfrmContinuousDictation.SpSharedRecoContextRecognition(
Sender: TObject; StreamNumber: Integer; StreamPosition: OleVariant;
RecognitionType: TOleEnum; var Result: OleVariant);
var
SRResult: ISpeechRecoResult;
begin
SRResult := IDispatch(Result) as ISpeechRecoResult;
memText.SelText := SRResult.PhraseInfo.GetText(0, -1, True) + #32
end;
The code here does not check if a valid IDispatch reference is in the Variant but probably should.
PLC & SCADA Wireless Control System
procedure TfrmContinuousDictation.SpSharedRecoContextRecognition(
ASender: TObject; StreamNumber: Integer; StreamPosition: OleVariant;
RecognitionType: TOleEnum; const Result: ISpeechRecoResult);
begin
memText.SelText := Result.PhraseInfo.GetText(0, -1, True) + #32
end;
SPDUI_AddRemoveWord = 'AddRemoveWord';
SPDUI_UserTraining = 'UserTraining';
SPDUI_MicTraining = 'MicTraining';
SPDUI_RecoProfileProperties = 'RecoProfileProperties';
SPDUI_AudioProperties = 'AudioProperties';
SPDUI_AudioVolume = 'AudioVolume';
procedure
TfrmContinuousDictation.InvokeUI(const
TypeOfUI,
Caption:
WideString);
var
U: OleVariant;
begin
U := Unassigned;
if SpSharedRecoContext.Recognizer.IsUISupported(TypeOfUI, U) then
SpSharedRecoContext.Recognizer.DisplayUI(Handle, Caption, TypeOfUI, U)
end;
the
commands.
This
grammar
is
used
by
sample
project
called
<DEFINE>
<ID NAME="RID_start" VAL="1"/>
<ID NAME="PID_chosencolour" VAL="2"/>
<ID NAME="PID_colourvalue" VAL="3"/>
</DEFINE>
NAME="colour"
PROPNAME="chosencolour"
PROPID="PID_chosencolour" />
<O>please</O>
</RULE>
<RULE NAME="colour">
<L PROPNAME="colourvalue" PROPID="PID_colourvalue">
<P VAL="1">red</P>
<P VAL="2">blue</P>
<P VAL="3">green</P>
</L>
</RULE>
</GRAMMAR>
After defining some constants the rules are laid out next. The top level rule (start, which is just
an arbitrarily chosen name) is defined as the optional word colour, a value from another rule
(also called colour) and the optional word please. The value from the colour rule can be
PLC & SCADA Wireless Control System
identified programmatically (rather than by scanning the recognised text) thanks to it being
defined as a property (chosencolour).
The colour rule defines one of three colours that can be spoken, each of which has a value
defined for it. Again, this value will be accessible thanks to the list being defined as a property
(colourvalue).
This grammar is stored in an XML file and loaded in the OnCreate event handler.
procedure TfrmCommandAndControl.FormCreate(Sender: TObject);
begin
//OnAudioLevel event is not fired by default - this changes that
SpSharedRecoContext.EventInterests := SREAllEvents;
SRGrammar := SpSharedRecoContext.CreateGrammar(0);
SRGrammar.CmdLoadFromFile('C and C Grammar.xml', SLODynamic);
SRGrammar.CmdSetRuleIdState(0, SGDSActive)
end;
Notice that two different ISpeechRecoGrammar methods are used to instigate command and
control
grammar
from
an
XML
file
and CmdSetRuleIdState activates all top level rules when the first parameter is zero (you can
activate individual rules by passing their rule ID).
The OnRecognition event handler does the work of locating the chosencolour property and then
finding the nested colourvalue property. Its value is used to change the form colour at the user's
request, for example with phrases such as:
red please
colour green
red
procedure TfrmCommandAndControl.SpSharedRecoContextRecognition(
ASender: TObject; StreamNumber: Integer; StreamPosition: OleVariant;
RecognitionType: TOleEnum; const Result: ISpeechRecoResult);
begin
with Result.PhraseInfo do
begin
Log('OnRecognition: %s', [GetText(0, -1, True)]);
case GetPropValue(Result, ['chosencolour', 'colourvalue']) of
1: Color := clRed;
2: Color := clBlue;
3: Color := clGreen;
end
end
end;
This code uses a helper routine, GetPropValue whose task is to locate the appropriate property in
the result object, by following the property path specified in the string array parameter. The code
for GetPropValue and its own helper routine, GetProp, looks like this:
Prop: ISpeechPhraseProperty;
PathLoop: Integer;
begin
for PathLoop := Low(Path) to High(Path) do
begin
if PathLoop = Low(Path) then //top level property
Prop := GetProp(SRResult.PhraseInfo.Properties, Path[PathLoop])
else //nested property
Prop := GetProp(Prop.Children, Path[PathLoop]);
if not Assigned(Prop) then
begin
Result := Unassigned;
Exit;
end
end;
Result := Prop.Value
end;
C HAPTER 5
PROGRAMMING & CODING
.1 Transmitter Coding
#include <VirtualWire.h>
#include <String.h>
const int led_pin = 11;
const int transmit_pin = 12;
const int transmit_en_pin = 3;
int ldr = A0;
String str;
char cstr[27];
void setup()
{
// Initialise the IO and ISR
vw_set_tx_pin(transmit_pin);
Serial.begin(9600);
vw_setup(2000);
pinMode(led_pin, OUTPUT)
pinMode(ldr, INPUT);}
byte count = 1;
void loop()
{
if(Serial.available()>0)
{
char message = Serial.read();
str = String(message);
str.toCharArray(cstr,27);
//char msg[7] = {'h','e','l','l','o',' ','#'};
//char msg1[27] = "fahad i love you ";
// msg[6] = count;
digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
vw_send((uint8_t *)cstr, 1); // change this number according to the sensor values
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(led_pin, LOW);
count = count + 1;}
}
int load1 = 2;
PLC & SCADA Wireless Control System
int load2 = 3;
int load3 = 4;
int load4 = 5;
int load5 = 6;
int load6 = 7;
void setup()
{
delay(1000);
Serial.begin(9600);
// Debugging only
Serial.println("setup");
// Initialise the IO and ISR
vw_set_rx_pin(receive_pin);
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000);
vw_rx_start();
pinMode(load1, OUTPUT);
pinMode(load2, OUTPUT);
pinMode(load3, OUTPUT);
pinMode(load4, OUTPUT)
pinMode(load5, OUTPUT);
pinMode(load6 , OUTPUT);
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;
for (i = 0; i < buflen; i++)
{
char c = (buf[i]);
Serial.print(c);
if( c == 'a')
digitalWrite(load1, HIGH);
if( c == 'b')
digitalWrite(load1, LOW);
if( c == 'c')
digitalWrite(load2, HIGH);
if( c == 'd')
digitalWrite(load2, LOW)
if( c == 'e')
digitalWrite(load3, HIGH);
if( c == 'f')
digitalWrite(load3, LOW);
if( c == 'g')
digitalWrite(load4, HIGH);
if( c == 'h')
digitalWrite(load4, LOW);
if( c == 'i')
digitalWrite(load5, HIGH);
if( c == 'j')
digitalWrite(load5, LOW);
if( c == 'k')
digitalWrite(load6, HIGH);
if( c == 'l')
digitalWrite(load6, LOW);}}
}
C HAPTER 6
INDUSTRIAL SCOPE
93
APPENDICES
94 Appendix A
Appendix A
A)
ZigBee Layers
The 5 layers can be divided into three groups, Customer, IEEE and ZigBee Alliance.
95 Appendix A
915MHz band which using 10 channels and 868MHz band using 1 channel. All three using
Direct Spread Spectrum Sequencing (DSSS) access mode.
PHY Packet Fields
96 Appendix A
and allows low power devices to maximize their battery life. From the basic topologies, there are
three network topologies are considered in IEEE802.15.4 are star, tree Network and mesh.
97 Appendix A
The Application Support (APS) sub layer provides an interface between the NWK and the APL
layers through a general set of services provided by APS data and management entities. The APS
sub layer processes outgoing/incoming frames in order to securely transmit/receive the frames
and establish/manage the cryptographic keys. The upper layers issue primitives to APS sub layer
to use its services. APS Layer Security includes the following services: Establish Key, Transport
Key, Update Device, Remove Device, Request Key, Switch Key, Entity Authentication, and
Permissions Configuration Table.
Security service provider:
ZigBee provides security mechanism for network layer and application support layers, each of
which is responsible for securing their frames. Security services include methods for key
establishment, key transport, frame protection and device management.
98 Bibliography
BIBLIOGRAPHY
[1]. Kevin Collins, PLC programming for industrial automation;AuthorsChance Ltd
Haselmere/GB-Feb 2007
[2] Ashutosh Singh, Debajit Tapadar, Sitanshu Sekhar Mondal, soumyaroop sengupta,
Automation of bolt galvanization plant using PLCInternational Conference on Process
Automation ,Control and Computing-PACC,2011
[3] Haider Ali & Ahmed Ali, Riaz Ul Hassnain Syed & Ajmal Khan & Ihsanullah Khan,
SCADA implementation of industrial temperature automation IJCSNS International Journal
of Computer Science and Network Security, VOL.11 No.8, August 2011
[4] Marek Laciak, Peter Fazekas, Jan Kacur, Monitoring and control of temperatures in electric
furnace in promotic system, 2011 12th International Carpathian Control Conference (ICCC).
[5] US patent NO:4227965 dtd Oct,14,1980 Production of Hard board
[6] US patent NO:3880975 dtd Apr 29,1975 Continous Hardboard Production
[7] J. W. Webb and R. A. Reis, Programmable Logic Controllers: Principles and Applications.
Engelwood Cliffs, NJ: Prentice-Hall, 1999.
[8] 020-745 Data Pack D Data Sheet RS Allen-Bradley MicroLogix 1000
[9] Rinaldi, et al., Identifying, Understanding, and Analyzing Critical Infrastructure
Interdependencies, IEEE Control Systems Magazine, 2001,
http://www.ce.cmu.edu/~hsm/im2004/readings/CII-Rinaldi.pdf.
[10] GAO-04-354, Critical Infrastructure Protection: Challenges and Efforts to Secure Control
Systems, U.S. GAO, 2004, http://www.gao.gov/new.items/d04354.pdf.
[11] Weiss, Joseph, Current Status of Cyber Security of Control Systems, Presentation to
Georgia Tech Protective Relay Conference, May 8, 2003.
[12] Keeney, Michelle et al., Insider Threat Study: Computer System Sabotage in Critical
Infrastructure Sectors, United States Secret Service and Carnegie Mellon Software Institute,
2005, http://www.cert.org/archive/pdf/insidercross051105.pdf.
[13] Federal Information Security Management Act of 2002, Section 301: Information Security,
http://csrc.nist.gov/policies/FISMA-final.pdf.
99 Bibliography
100 Bibliography