Chapter 1 Introduction - Universidad de...

104
--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville 1 Chapter 1 Introduction Recently, significant advances in Internet and computer technology have made it possible to develop an Internet-based control and monitoring systems for industrial applications. The quadruple tanks plant, located in the laboratories of the University of Seville, has been upgraded with the Internet-based technology using the proposed solution discussed in this project. The Internet brings many new features to SCADA (Supervisory Control and Data Acquisition) systems, which were previously difficult or costly to implement in traditional control systems, such as remote accessibility to the plant, information sharing, and software standardization. [7] Traditional SCADA systems are similar to Distributed Control Systems (DCS) in that they both use process control and monitoring. However, they differentiate each other in that, with DCS systems of gathering or control units are usually located within more confined area (e.g. factory or power plant) and the communication is usually done via a reliable and speed Local area network (LAN). On the other hand the SCADA systems generally deal with units that cover wide geographical areas (e.g. pipeline, power lines) where variety of communication technologies are used. [7] The key goal of implementing Internet–based SCADA is to utilize internationally accepted standards and technologies to achieve the monitoring and control functions that a traditional SCADA system provides but at a lower cost and easy remote accessibility. The Internet-based SCADA system may also include embedded smart devices (such as drivers, motors, servos, actuators, gauges, pumps and flow meters), which has built-in embedded web servers that can transfer data from the plant floor all the way up to the enterprise web browsers, thus allowing remote control, diagnostics, management, and supply chain management. The web browser also acts as a unified human-machine interface which combines the geographical operators interface, data acquisition, and alarm functions, with the capability of real time enterprise integration and external data communication. Advantages of Internet SCADA The main advantage of implementing an internet-based SCADA system is , that it is a standard based system which uses the existing computer and communications technologies to achieve optimum system functionality with minimum cost. The cost of implementing an Internet-based SCADA system will generally be lower than of a traditional system. This is due to the facts that: The Internet SCADA systems use standard hardware and software requires. The Internet SCADA systems need lower training costs for the operation of the maintenance technicians. The Internet SCADA systems require lower preventions and corrective maintenance costs.

Transcript of Chapter 1 Introduction - Universidad de...

Page 1: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

1

Chapter 1 Introduction Recently, significant advances in Internet and computer technology have made it possible to develop an Internet-based control and monitoring systems for industrial applications. The quadruple tanks plant, located in the laboratories of the University of Seville, has been upgraded with the Internet-based technology using the proposed solution discussed in this project.

The Internet brings many new features to SCADA (Supervisory Control and Data Acquisition) systems, which were previously difficult or costly to implement in traditional control systems, such as remote accessibility to the plant, information sharing, and software standardization. [7]

Traditional SCADA systems are similar to Distributed Control Systems (DCS) in that they both use process control and monitoring. However, they differentiate each other in that, with DCS systems of gathering or control units are usually located within more confined area (e.g. factory or power plant) and the communication is usually done via a reliable and speed Local area network (LAN). On the other hand the SCADA systems generally deal with units that cover wide geographical areas (e.g. pipeline, power lines) where variety of communication technologies are used. [7]

The key goal of implementing Internet–based SCADA is to utilize internationally accepted standards and technologies to achieve the monitoring and control functions that a traditional SCADA system provides but at a lower cost and easy remote accessibility.

The Internet-based SCADA system may also include embedded smart devices (such as drivers, motors, servos, actuators, gauges, pumps and flow meters), which has built-in embedded web servers that can transfer data from the plant floor all the way up to the enterprise web browsers, thus allowing remote control, diagnostics, management, and supply chain management. The web browser also acts as a unified human-machine interface which combines the geographical operators interface, data acquisition, and alarm functions, with the capability of real time enterprise integration and external data communication. Advantages of Internet SCADA The main advantage of implementing an internet-based SCADA system is , that it is a standard based system which uses the existing computer and communications technologies to achieve optimum system functionality with minimum cost. The cost of implementing an Internet-based SCADA system will generally be lower than of a traditional system. This is due to the facts that:

� The Internet SCADA systems use standard hardware and software requires. � The Internet SCADA systems need lower training costs for the operation of the

maintenance technicians. � The Internet SCADA systems require lower preventions and corrective

maintenance costs.

Page 2: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

2

1.1 Problem Formulation The Objective of this project is to design and to develop a Java-based control system that will enable the control of some laboratory equipments from remote locations and independent from the private communication protocol of the controlled plant. This project proposes an effective solution for such that projects that suffers from a lot of problems like:

� Choosing a suitable OPC (Ole for Process Control) server. � DCOM (Distributed Component Object Model) configurations. � The networks groups’ security and Microsoft Windows Company constrains.

The main used products in this project are:

� The OPC DataHub: that offers the OPC server and also its own web server. � Java programming language: The Programming language used to communicate

with the OPC server. � Broad Cam v1.0: web cam video server which is used to transmit the captured

online video to any of the logging users.

1.2 Background The system architecture consists of a server computer, called the lab station ( Central PC ), and several remote clients computers, called the remote user PCs. The lab Station server is connected to the lab equipment using PLC Siemens and the RS-232 communication protocol. The central PC provides access to the remote users through Java applets running through the standard web browser interface; Figure 1.1 shows the system block diagram.

Fig. 1.1: System Block Diagram

In order to achieve the project objectives the first thing should be taken in account is that the design system should work with the quadruple tanks plant and with the other plants as well, starting from this idea, the usage of OPC server ( Ole for process Control protocol ) could solve such that problems. OPC is a software interface standard that allows Windows programs to communicate with industrial hardware devices. The OPC server is a software program that converts the hardware communication protocol used by a PLC (Programmable Logic Control) into the OPC protocol. The OPC client software is any program that needs to connect to the hardware, such as an

Central PC

Page 3: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

3

HMI. The OPC client uses the OPC server to get data from or to send commands to the hardware.

Fig. 1.2: OPC Server with Real System The value of OPC is that it is an open standard, which means lower costs for manufacturers and more options for users. Hardware manufacturers need only to provide a single OPC server for their devices to communicate with any OPC client.

Software vendors simply include OPC client capabilities in their products and they become instantly compatible with thousands of hardware devices. Users can choose any OPC client software they need, resting assured that it will communicate seamlessly with their OPC-enabled hardware, and vice-versa. [8] Why Quadruple Tanks Plant? The Quadruple tanks plant exists at the laboratories of the university of Seville so that all the experiments could be tested in real in addition to that the Quadruple Tanks Plant is a well known educational plant in the field of Control Engineering and has a variety of control problems. This project builds the bases for all the next experiments that could be tested, In order to study the control algorithms via the networks, and to test their functionality with the special cases that the QTP provides such as:

� The Nonlinearity of the system. � The Minimum and Non-minimum phase cases of the system. � The MIMO controller design.

1.3 Methods and Technologies

The main technologies used in this project are:

� OPC server to unify the communication between the central PC and the controlled plant.

� Java programming language, which is used to build all the applets that connect to the OPC server and to modify its elements.

� The OPC DataHub own web server to host the entire programmed applet. � One of the commercial video servers that transmits the captures online video to

the logging users.

Page 4: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

4

1.4 Chapters Description

The report starts with chapter 2 discussing the OPC server, definition, components and the importance of using OPC server in the industry.

Then chapter 3 discusses the usage of Java programming language in building up the programs that deals with the OPC servers showing the importance of using Java in the web-based control systems and the technique of how Java deals with the OPC server, at the end of this chapter the commercial products that offers those capabilities will be shown. Chapter 4 discusses the capabilities of the proposed web-based control system and also discusses the applets designed that enable the remote user to:

� Connect to the central PC OPC server. � Show the water level of the four tanks. � Monitor the system behaviour and the alarm status. � Control the system either by sending the controller parameters or by sending the

controller signal remotely. � View an online video that shows the process actions on live.

At the end of this chapter the encountered problems will be shown with the proposed solution. Chapter 5 describes the steps of how to get started with OPC DataHub to prepare the OPC server. Chapter 6 shows the nature of the quadruple tanks process, the control objective of that system and the PI controller design for one of the cases that the system has which is minimum phase case.

Page 5: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

5

Chapter 2 OPC Server This chapter discusses the OPC server in brief the definitions of an OPC Server, the importance of using OPC servers and the scenarios of connecting OPC server.

OPC is a communication standard based on the OLE/COM technology. This technology is the information-exchange medium recommended by Microsoft for use between MS-Windows applications. The COM model ensures interoperability between independently developed software components from different publishers.

2.1 Introduction The OPC server is a software program that converts the hardware communication protocol used by a PLC into the OPC protocol. The OPC client software is any program that needs to connect to the hardware, such as an HMI. The OPC client uses the OPC server to get data from or to send commands to the hardware.

OPC is, in fact, simply the specification for a standard. This standard describes the set of objects and interfaces that any "OPC server" will have to implement in order to ensure maximum possible interoperability between control/command/supervisory applications, industrial hardware (PLCs, sensors, activators) and desktop management applications which are installed under the windows environment.

The OPC Foundation™, which is a nonprofit organization that created the specifications , is currently working on future releases of the OPC specification. This organization is chartered with the expansion of the standard into those areas deferred from the initial release. These areas are:

� Alarm handling. � Event handling. � Security and historical data access.

2.2 Benefits of OPC Server OLE for Process Control (OPC™) is designed to allow client applications access to plant floor data in a consistent manner. With wide industry acceptance OPC will provide many benefits:

� Hardware manufacturers only have to make one set of software components for

customers to utilize in their applications. � Software developers will not have to rewrite drivers because of feature changes

or additions in a new hardware release. � Customers will have more choices with which to develop World Class integrated

manufacturing systems. With OPC, system integration in a multiple computing environments will become simple, and combining various equipments will be easier as indicated on the Figure 2.1

Page 6: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

6

Fig. 2.1: OPC Server Complete Application

What is needed is a common way for applications to access data from any data source like a device or a database. There are many client applications that have been developed that require data from a data source and access that data by independently developing “Drivers” for their own packages. This leads to the problems that follow:

� Everyone must write a driver for a particular vendor’s hardware. � Inconsistencies between vendor’s drivers: Hardware features not supported

by all driver developers. � Support for hardware feature changes: A change in the hardware’s

capabilities may break some drivers � Access Conflicts: Two packages generally cannot access the same device

simultaneously since they each contain independent drivers. � Hardware manufacturers attempt to resolve these problems by developing

drivers, but are hindered by differences in client protocols. � Providers and software developers: It provides a mechanism to provide

data from a data source and communicate the data to any client application in a standard way. A vendor can now develop a reusable, highly optimized server to communicate to the data source, and maintain the mechanism to access data from the data source device efficiently. Providing the server with an OPC interface allows any client to access their devices, easily [10].

2.3 OPC Server Goals

A primary goal for OPC is to deliver specifications to the industry as quickly as possible. And in the following points are shown some of the basic goals:

Page 7: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

7

• Online Data Access, i.e., the efficient reading and writing of data between an application and a process control device flexibly and efficiently.

• Alarm and Event Handling, i.e., the mechanisms for OPC Clients to be notified

of the occurrence of specified events and alarm conditions. • Historical Data Access, i.e., the reading, processing and editing of data of a

historian engine. The architecture of OPC leverages the advantages of the COM interface, which

provides a convenient mechanism to extend the functionality of OPC. Other goals for the design of OPC were as follows:

� Simple to implement � Flexible to accommodate multiple vendor needs � Provide a high level of functionality.

2.4 OPC Server Components The OPC Standard defines several objects with associated properties and methods. These objects are used to expose process data from a process control device in a standard manner. Every OPC server will make data available to clients using this model. The first OPC object is the OPC server. The OPC server is responsible for acquiring the data requested by a client from the process control device. Each server contains OPC groups, which are logical collections of data to be gathered. The groups in a server may be shared by many clients or be private to a single client. The relationship between servers and groups is shown in Figure 2.2. The OPC group object holds the OPC items that contain the values retrieved from the process control device. The client adds items to groups. The client may want to group all process temperature values into a group. It might make sense for the client to have all the data from a

Fig. 2.2: OPC Server and Groups

Page 8: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

8

Process unit be organized into a group. The client can specify to the server the update rate for the group that defines the rate at which the server will check to see if the exception limit for a value has changed. The client also specifies the exception limit used for items in the group to

Determine if the value should be reported back to the client. The relationship between groups and items is shown in Figure 2.3.

Fig. 2.3: Groups and Items

Items contain the actual value received from the process control device. The client specifies the item to the server through the item ID. The item ID is server specific. It uniquely identifies to the server how to locate the value in the process control device. For a DCS system this might resemble TIC-200.PV. For a PLC system the item ID might be a register number. The items typically return a single value. The server may optionally returns a timestamp and quality flag with the value.

2.5 OPC Connection Scenarios The typical OPC connection scenario is a single server-client connection on a single computer, there are more possibilities. For example, you might need to:

• Connect an OPC client to several OPC servers. This is called OPC aggregation. • Connect an OPC client to an OPC server over a network. This can be done with

OPC tunneling. • Connect an OPC server to another OPC server to share data. This is known as

OPC bridging.

2.5.1 OPC Aggregation OPC aggregation means collecting data from several OPC servers into one common point of access. Why use OPC Aggregation?

• Save money on OPC Client connections by accessing data from all of your OPC Servers through a single client connection to the DataHub.

Page 9: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

9

Fig. 2.4: OPC Aggregation

• Bringing data from multiple sources together into one location allows you to easily bridge between different OPC Servers so that data from one server can be accessed in another server.

• Collect data from all of your OPC Servers and present it to the user as a shared common data set.

• Writing custom applications is much easier when you can access data from multiple servers through a common interface.

2.5.2 OPC Tunneling

OPC Tunneling is a method of networking data between an OPC Server and an OPC Client, and this is one of the mostly industrial used scenarios since most of the applications needs exchange the data remotely, as the case study that this project discusses the client program should exchange the data with the server remotely.

Fig. 2.5: OPC Tunneling

2.5.3 OPC Bridging

Using bridge between OPC Servers to integrate data from different systems. The OPC bridging enables you to change data between PLC, DCS, HMI, databases and other program supports the OPC connectivity. That is why building a complete system will be easier with the OPC servers.

Page 10: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

10

This page has been intentionally left blank.

Page 11: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

11

Chapter 3 OPC DataHub Product

3.1 Java in Real time Applications, Why Java? As the global Internet continues to grow, Java is one of the suitable programs to build the next generation of network applications, it provides solutions to a number of problems, which are difficult to address in other programming languages.

The level of safety with Java applets (programs which adhere to a set of conventions that allow them to run within a Java-compatible browser) is greater than what can be obtained from other software. Java makes writing networking programs easy, it is relatively straightforward for Java applications and applet to send and receive data and to communicate across the Internet, limited only by security constrains.

These features are especially suited to some of the SCADA system, which is typically deployed over a large geographical area.

In the past, software developers had to work with a specific native instruction set that locked them into a specific hardware and operating environment. Unlike other programming languages, Java executes in a run time environment called a virtual machine. The Java virtual machine executes byte code (platform independent code) that a Java compiler generates and it can be incorporated or embedded in Web browsers, or the kernel of the operating system. Java virtual machines and Java API’s (Application Program Interfaces) insulate the Java program from hardware dependencies.

For all of that Java’s byte code can run on a wide range of platforms so Java’s byte code helps to make the “write once, run anywhere” possible. [1] So using Java as a programming language in the SCADA systems offers unique and powerful features, such as [2]:

� Zero client installation. � On-demand client access. � Platform independence. � The ability to design an attractive interface using Java. � Easy internetworking applications programming. � Easy to integrate the other services such that: web-cam application and to

connect with scientific programs like Matlab that offers a lot of facilities especially in the control Engineering applications.

3.2 Connecting to OPC with Java

This section discusses the mechanism of how Java as a programming language connects and deals with the OPC server protocol and also shows different products that provide this solution, ending with the differences between these products.

Page 12: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

12

How Java connects with OPC, In general? Programming in Java is easy since no knowledge is needed about the conversion process on the C side.

The OPC access is realized through the OPC Custom Interface by means of a Dynamic Link Library (DLL). Java uses the Java Native Interface (JNI) to access the methods and data of this DLL files which is written in C. What is JNI?

Java Native Interface (JNI) is a programming framework that allows Java code running in the Java virtual machine (JVM) to call and be called by native applications (programs specific to a hardware and operating system platform) and libraries written in other languages, such as C, C++ and assembly.

The JNI is used to write native methods to handle situations when an application cannot be written entirely in the Java programming language such as when the standard Java class library does not support the platform-specific features.

It is also used to modify an existing application, written in another programming language, to be accessible to Java applications. Many of the standard library classes depend on the JNI to provide functionality to the developer and the user, e.g. I/O files reading and sound capabilities and the TCP/IP protocol application.

The JNI is not trivial and requires a considerable effort to learn, and some people recommend that only advanced programmers should use the JNI. However, the capability for Java to communicate with C++ and assembly removes any limitations on what function Java programs can perform, because in addition to what Java offers the C++ abilities can also be used. [3]

3.3 Java Products that Connect to OPC

3.3.1 OPI JOPCClient [4]

Odense Production Information (OPI) of Denmark takes designed a libraries that enables the programmer to build his application easily.

JOPCClient is restricted to the Windows platform only, and uses Sun's Java Native Interface (JNI). This technique allows Java developers to access the functionality of OPC using only Java calls and without needing knowledge of COM and DCOM. JNI is supported by most Java Virtual Machines (excluding the Microsoft JVM), and JOPCClient is compatible with JDK 1.1, 1.2 and 1.3.

JOPCClient consists of a Java Jar library file and an accompanying Java Native Interface DLL. The DLL file has been built in C++, which ensure very efficient execution, thus allowing you to monitor many IO registers with a minimum CPU load.

Page 13: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

13

JOPCClient Characteristics

The demo version of JOPCClient has the exact same feature set as the registered version, however with a limitation on the number of connections, groups and items that can be made. The table 3.1 shows the limitations exist for the demo and the registered version respectively.

Fig. 3.1: JOPCClient Dynamic Explorer

Product Description and Benefits

Table 3.1: JOPCClient Characteristics

In the first phases of this project this product was used order to study the abilities of connecting Java with the OPC servers, its an easy way to create your own program not only to connect with OPC server but also to transmit their values using TCP/IP protocol, but when all the created applets reached the time to be uploaded on a web server a lot of problem were encountered such that:

� The Applet security issues like these type of applets that contains hardware listeners e.g. TCP/IP listener, OPC protocol, reading witting on the local hard drive are considered as dangerous actions and will never accepted by the browsers.

Feature JOPCClient demo version

JOPCClient registered version

Allowed number of simultaneous server connections 1 per computer 100 per process Allowed number of added groups per process 1 300 Allowed number of added items per process 3 1500

Note

Page 14: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

14

� The demo version of the JOPCclient enables only to connect with 3 server elements at the same time, that is what makes using this product in this project limited.

The solution of such that problems will be discussed in more details in the following chapters.

3.3.2 Net Module JOPC-Bridge [5]

With the JOPC-Bridge OPC clients can be developed in Java or existing applications can be joined to OPC servers. Java classes are provided that mirror the OPC specific server objects. Thereby the programming in Java is made easy, for no knowledge is needed about the type conversion on the C side.

Fig. 3.2: Architecture of JOPC-Bridge System

JOPC-Bridge currently supports the OPC specifications Data Access 1.0, 2.0, 3.0 and Alarms & Events 1.1. It provides tested compatibility with servers from Siemens, Rockwell, B&R and K&W but may work with many more as long these servers follow the OPC standard. The scope of supply includes the Java classes, the JOPC-Bridge dynamic link library (DLL).

Finally, as a conclusion we can connect the OPC with Java either by using one of the libraries that enables us to do that or to learn how to program with JNI that enables us to deal with the .DLL files directly that is already written in C or C++ and that is so difficult for the beginners.

Page 15: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

15

In any way a lot of Java-COM bridges are listed in [6], the DataHub product features will be shown the following section.

3.3.3 OPC DataHub

OPC DataHub is one of the products of Cogent, which was formed in 1995 to provide software and consulting services in real-time and embedded systems. The OPC DataHub is an OPC tool that provides OPC tunneling, bridging, and aggregation, as well as data connectivity across DDE and TCP. It acts as a central hub to simultaneously send and receive data between any number of OPC servers and clients, as well as Excel worksheets, web browsers, and ODBC-compliant databases.

Fig. 3.3: OPC Data Hub features

This product is the main product used in this project which contains a lot of features some of them are the followings:

� OPC DataHub: In addition to its own Java library it provides its own web server that makes building the web based application easier.

� OPC DataHub: Provides simple configurations that makes from building your system easier.

� OPC DataHub: Provides tools that make dealing the sensor values easier, i.e. transformation tool to convert the sensor value (the registers value), which is in bytes to the logical element, value which may be in centimeters, kilograms, Kelvin. Etc.

� OPC DataHub: Provides the solution of remote OPC connection easily, so you should not be worry about remote connecting to the OPC server and the problems that usually encountered such that: Firewall problem, network groups, Microsoft widow’s configurations etc.

� OPC Data Hub: Provides strong and easy solution to build your own web application in order to connect, modify and monitor the OPC server elements in any place over the LANs or the WANs.

� OPC DataHub: Provides an already designed applet that can be integrated on your application.

� OPC DataHub: Can be used to connect with the Excel sheets, the Microsoft Access applications and a group of famous databases such that:

Page 16: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

16

• Microsoft Access. • Oracle Database. • Microsoft SQL Server.

� OPC DataHub provides the ability of generating and sending Emails and SMS in case of emergency.

� OPC DataHub can be connected to Matlab.

In the following section some of those features will be shown in some details.

OPC DataHub features [7]

1. OPC Tunneling with DataHub

As mentioned previously that the OPC tunneling is a method of networking data between an OPC Server and an OPC Client, without using the problematic DCOM protocol offered by Microsoft, DataHub provides the solution.

Fig. 3.4: Tunneling with OPC DataHub

DCOM configuration is a problem, why? DCOM is a Microsoft networking protocol used by OPC servers and clients to communicate over a network. It was not designed for use in modern industrial control applications and has a number of issues, most notably:

� DCOM is difficult to configure, even for the experienced user and getting DCOM to work between different networks can sometimes be impossible.

� Sometimes integrators try to get around these problems by defining very broad access permissions on all computers. However, in an industrial setting, you typically don't want the server and client computers to have the same login permissions, which means using DCOM can actually compromise your network security standards.

� When a DCOM connection is broken, there are very long timeout delays before each side is notified of the problem. In a production environment, these long delays without warning can be a very real problem.

It could be said that in simple configurations the clients and the server can be connected easily without problems.

Page 17: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

17

2. OPC DataHub Logging

Using the OPC DataHub you can write data from any OPC Server to any ODBC compliant database such as Access, SQL Server, Oracle or MySQL. You can also read data from an ODBC database and write it out to any number of different OPC Servers or Clients.

Fig. 3.5: The structure of the DataHub logging system

The OPC DataHub logging provides a tool, which enables the programmer to:

� A step-by-step interface guides you through the process of:

o Choosing which database to connect to. o Choosing an existing database table, or creating a new table. o Specifying which data items gets written to which columns in the table. o Defining a trigger event and conditions to control when the data is

written to the database.

� The OPC server and ODBC database can be on the same computer or connected over a network. The OPC DataHub makes it easy for you to tunnel your data to a networked database server, without having to deal with DCOM problems and different permissions on the two machines.

� You can combine data from other sources, such as Excel spreadsheets and include this in the data you write to the database.

� The DataHub will automatically reconnect if the link to the database is interrupted for any reason.

3. Bridging with OPC DataHub Using the OPC DataHub you can bridge between OPC Servers to integrate data from different systems. The OPC DataHub also adds the following advanced features:

� You can connect OPC Servers on the same computer or over a network connection (Bridging and Tunnelling at the same time).

Page 18: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

18

Fig. 3.6: OPC Bridging with OPC DataHub

� Point and click interface makes bridge configuration quick and easy. � Built-in linear transformations allow you to scale, convert or normalize the

data while it is bridged from one server to the other. � The powerful built-in scripting language lets you define even more complex

relationships between points in code for even more power and flexibility. � You have the ability to bridge between multiple OPC Servers, both locally

on the same computer and over multiple network connections.

4. OPC DataHub to Email and SMS Text Messages The OPC DataHub can be configured to send email and SMS text messages whenever an alarm, or specified timer event occurs. The messages are completely customizable and can include embedded values for any point in the DataHub, including data from OPC servers, ODBC databases or Excel spreadsheets. You can easily create simple plain text messages or design more elaborate emails with full HTML formatting.

Fig. 3.7: OPC DataHub Mailing service

OPC DataHub mailing offers to the customer the following facilities:

� Send SMS text messages to cell phones when an alarm event is triggered. � Design end-of-day reports that are delivered to managers' email accounts

each morning. � Provide managers with regular email updates of production targets. � Emails can contain data from OPC servers, ODBC databases and other

sources. � Eliminate the errors and delays associated with writing production reports by

hand. � Have the DataHub collect vital report information, format it as an Excel

spreadsheet and then email the file to key people for review.

Page 19: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

19

5. System Monitor

OPC DataHub enables you to monitor the performance of computers anywhere in your organization using the OPC DataHub. You decide what system parameters to monitor, such as CPU usage, free disk space, available memory and whether critical processes are still running. The DataHub as regular point data that can be shared across a network or the Internet in real-time collects this information.

Fig. 3.8: OPC DataHub System Monitoring System

Using System monitoring you can:

� Monitor the CPU load and free memory of critical systems in your plant and send email or text messages when performance levels drop too low.

� Monitor important programs in your system and use a DataHub script to automatically restart them if they terminate unexpectedly.

� Collect system data from multiple networked computers and display it in a real-time web display.

6. OPC to Web

DataHub provides its own web server and also provides its own web application so without having to write any code, or to configure any web server settings, you can build your own web application and integrate it with the others. Server-side Benefits

� The DataHub comes with its own built-in web server. � Point and click configuration makes installation quick and easy. � No server side programming is required for DDE and OPC data sources. � The DataHub also connects to TCP/IP, MATLAB, ODBC and text file

sources of data. � Web sites can be password protected and data connections secured. � There are effectively no limits on the number of data points.

Browser-side Benefits

� Supports embedded Java applets for unbeatable performance when displaying real-time data on the web.

� AJAX and ASP web pages work with any web browser.

Page 20: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

20

� Java applets use the standard Sun Java engine, which is supported by most desktop web browsers.

� Fully bi-directional data flow, so you can read and write data in the web page.

� Supports an unlimited number of web users.

3.3.1 OPC DataHub getting started

In this section the basics of using OPC DataHub in order to be ready and the steps of preparing the OPC DataHub for the OPC tunneling, aggregation and OPC clients will be shown briefly for more details you can follow the instruction listed in [7].

To run the DataHub, select the program using the Windows Start menu, or double click the desktop icon.

Fig. 3.9: Getting Started

Once the DataHub is started, it runs in the background and puts a DataHub icon in the system tray at the bottom right-hand corner of the screen.

If you right-click on that icon, you will get a small pop-up menu with several options that let you open the window shown in figure 3.10.

Working with OPC Points

Now the system is ready to be used the next step is to build up the OPC server elements structure, building OPC elements in OPC DataHub can be achieved using scripting file.

Each value stored in the OPC DataHub is called a point. A point has the following attributes:

� Name: a character string. Currently the only limit on length is internal buffer size, about 1000 bytes by default.

� Value: an integer, floating-point number, or character string.

� Time: the date and time of the last significant change to the point’s value, confidence, quality or other status information.

� Quality: the quality of the connection, assigned by the OPC DataHub for this point, such as Good, Bad, Last known, Local override, etc.

Page 21: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

21

Fig. 3.10: OPC DataHub Program

The OPC DataHub automatically creates a point whenever a connecting program tries to read, write, or create a point that doesn’t exist. When the point is created, the OPC DataHub assigns its value, time, quality and confidence.

It is possible to have the OPC DataHub create points and assign values to them at startup. Sometimes referred to as seeding, this is done with configuration files and should be linked on the first time. All the commands should be stored in a file that should be declared and stored as shown in figure 3.13.

In order to construct the following OPC point hierarchy the file *.cfg file should contains the commands in Figure 3.11.

Page 22: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

22

Fig. 3.11: Server Elements File Location

Fig. 3.12: OPC Server Elements

Page 23: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

23

Here is the configuration file that is used to build up the project points.

Fig. 3.13: Script of the OPS Server Elements

Where the create command is to create new point followed by the domain name and then the point name, e.g. the command

Create QTP: TtankLevel1

Is to create new point called TankLevel1 in the domain QTP (Quadruple Tanks Process), in order to assign the default values at start up the following code is used:

Set QTP: TankLevel1 10.4 100

Where 10.4 is the TankLevel1 value, note that this configuration will be loaded at any time the program starts.

Page 24: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

24

This page has been intentionally left blank.

Page 25: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

25

Chapter 4 Java with OPC DataHub Server The main idea of this chapter is to show the basic steps of using Java to connect the locally installed OPC server. The OPC DataHub product provide three libraries that enables the programmer to choose one of them in order to build his system according to requirements that the project imposes and here are the three libraries:

� The DataHub API for C++: lets you write programs in C++ that connect to the DataHub over TCP, namely LAN, WAN, or the Internet.

� The DataHub API for Java: lets you write programs in Java that connect to the

DataHub over TCP, namely LAN, WAN, or the Internet. In addition, it lets you create web browser applications that receive and display live data from the DataHub.

� The DataHub API for .NET: lets you write programs in .NET that connect to

the DataHub over TCP, namely LAN, WAN, or the Internet. This API is implemented in C#, but can be used with any .NET language.

4.1 Web Programming with Java The DataHub lets you put live data into Java applets that are embedded in a web page. When someone visits the web page, the Java applet attaches to the DataHub and the applet starts to receive live data updates without refreshing the page.

Fig. 4.1: Java Applet Model

Here is an overview of how your code gets live data from the DataHub to a web page.

1. The Browser Loads the HTML

� The web browser follows the URL to the web server. � The web server returns the HTML code for the page.

Page 26: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

26

Fig. 4.2: HTML and the Browser

2. The Browser Loads the Java code

� The browser reads the HTML code and encounters the embedded APPLET code.

� The APPLET code instructs the browser to go back to the web server and loads the Java code.

� The web server provides the Java code.

Fig. 4.3: Java Applet Model 3. The Browser runs the Java code

� The browser runs the Java code (in the Java Virtual Machine). � The Java code instructs the Java VM to connect to the DataHub running on the server computer. From that point on, all communication is between the Java applet and the DataHub only. The web server is not involved. � In the browser, the Java code tells the Java plug-in how to display the information coming from the DataHub.

Fig. 4.4: Applet and DataHub Communication

4.2 Working with Java Applets

The DataHub offers a mechanism for displaying live data in a web browser through Sun’s Java plug-in. The DataHub API defines a number of Java applets, each of which can display one or more data points.

An applet can be as simple as a text field, or as complex as a data table. Web pages typically contain more than one applet, each displaying a specific item of information, and later on we will show how that defined applets works together in order to show a group of OPC server elements.

Page 27: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

27

DataHub Provided Applets

OPC DataHub provides already designed applets that can be divided into two groups:

� Basic Applets: Which are important to be integrated on any application such that: o DataHubLink: Makes a TCP connection to the DataHub and the current loaded applets. o DataHubListener: A base class for all applets that send and receive data, any applet should implement the DataHubListener applet.

� Secondary Applets: Which are used in order to show the data in text field, labels, and check box. o DataHubButton - a push button that sends a value for a DataHub point. o DataHubCheckBox - a check box that toggles a DataHub point between two values. o DataHubEntryField - an entry field for changing the value of a DataHub point. o DataHubGauge - a gauge for displaying DataHub point values. o DataHubLabel - displays the value of a DataHub point in a text field. o DataHubLineChart - displays a real-time trend of DataHub data. o DataHubProgressBar - a horizontal or vertical progress bar for displaying DataHub data. o DataHubRadioGroup - a group of radio buttons for assigning a value to a DataHub point. o DataHubSlider - a slider that assigns a numeric value to a DataHub point. o DataHubSpinner - sets the value of a DataHub point using up and down arrows. o DataHubToggleButton - toggles a DataHub point between two values. o DataHubTrend - a dynamically updating graphical display of DataHub values.

4.3 Configuring the DataHub Web Server

To configure the Data Hub’s web server, follow these steps:

� With the DataHub running, right click on the DataHub system-tray icon and choose Properties.

� In the Properties window, select Web Server. � Check the Act as web server box.

To get a list of which ports are in use on your machine, follow these steps:

� From the Windows Start menu, choose Run. � Enter the executable name cmd.exe and click OK. � At the command prompt, type:

Page 28: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

28

Using this command let you to show the used port then to choose your port according to the provided ones.

Fig. 4.5: Configuring Data Hub

The result is a table showing the TCP protocol and executable name of all programs in use. There are two columns of interest: Local Address and State. In Local Address, the numbers at the end (after the colon) are the port number that the process is using. The State column shows the state of that process. The only state we are interested in is LISTENING. Whatever port you are using for the DataHub web server, it should be the only process on that port. If you have one or more programs established or listening on the same port as the Cascade DataHub, you have two choices:

� Change the port number for the DataHub web server (as illustrated above), or � Change the port number for every other program that is using that port.

Port numbers 1 through 1024 are reserved. Port 80, for example, is reserved for HTTP, which is why we make it the default for the DataHub web server. If you change the DataHub web server from port 80, it is suggested to set it to a number between 1025 and 65535.

Page 29: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

29

Fig. 4.6: Port Test

4.4 Testing the DataHub Web Server

After all of the port configurations are already adjusted the web server can be tested by calling the local host and to see what the standard web page shows. The DataHub distribution comes with a collection of Java applets, which can be viewed from the Data Hub’s Web Server demo page.

To view a page served by the DataHub, open a web browser and type in the page URL. As a default web page there is a demo page that comes with your DataHub installation where you can view data coming from DataSim which is small software simulates a group of OPC sever points here is how to access the page:

� Ensure that the DataHub is running and is configured to act as a web server. � Type the IP address of the DataHub into the Address field at the top of your

web browser. � If you are running the DataHub and web browser on the same machine, type

localhost.

Page 30: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

30

Fig. 4.7: OPC DataHub as a Web Server

� Otherwise, type the IP address or computer name of the computer running the DataHub.

� The welcome page should appear. You can follow the links to see the various demos. The demos use data from DataSim, which is a program to generate simulated data.

The DataHub model for displaying dynamic data in a web page uses a BaseApplet.Java and ListenerApplet.Java to reduce network bandwidth requirements and increase the speed of updates in the page. BaseApplet.Java The Base applet makes the connection to the DataHub and receives the live data from the DataHub. In addition to displaying data, Base applets also send dynamic data to other applets in the web page, which we call Listener applets.

Page 31: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

31

Fig. 4.8: Web server Test

Fig. 4.9: Web Server with OPC DataHub

You can have as many Base applets as you like in a page, but each one will require a separate connection to the DataHub. Listener Applets Listener applets also connect to the DataHub, but they do so through the Base applet connection. The data coming from the DataHub goes to the Base applet first. From there it is transferred to all Listener applets on the same web page. This dramatically improves the speed of the connection and reduces network traffic. You can add as many Listener applets to the page as you like with little impact on data transfer rates. The recommended data model is to have one Base applet per page, feeding multiple Listener applets.

4.5 Example HTML Coding

Applet Configuration Java applets are configured through parameters in the HTML source for the web page. Different applets can accept different arguments. No argument may appear more than

Page 32: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

32

once per applet. So every HTML code corresponding to an applet contains rather that the applet declaration also contains a group of parameter like: the OPC server point, the color of the back ground in case of the charts drawing applet, the colors of the drawn lines.

Embedding Java applets in a web page successfully can be complicated by inconsistencies between different browsers.

Internet Explorer requires a Java plug-in to recognize and correctly display the APPLET tag. To have IE (Internet Explorer) download and install the Java plug-in you must ensure it has the correct information about what version of the plug-in to install, and where to go to download it. This information is provided in the following OBJECT tag:

If the Java plug-in has already been installed in the browser, then IE will simply load the DataHub.Java Dummy code and execute it. The code does nothing but to be sure that the Java pug-in is correctly installed if not, then this OBJECT code instructs IE where to go to download the plug-in. After the plug-in is installed, the Java code is run and control is once again returned to the browser. Using a Base applet To make a connection to the DataHub, you need to use a Base applet, such as DataHubViewer.class or DataHubLink.class, somewhere in your page. Here is an annotated version of the code using DataHubLink.class :

And here is the code explanation line-line: 1. Instructs the browser to reserve space in the page for the applet. 2. Calls the code of the widget class. 3. Tells the web server where the DataHub.jar file for the code is located. 4. Identifies the DataHub.jar file that contains the code. This same DataHub.jar file is used for all the classes in this API. 5. Identifies the port number of the connection. 6. Identifies the DataHub domain where the data resides.

Page 33: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

33

7. Assigns a name to this base applet. This name is used by any DataHubListener applets Embedded in the same web page. 8. Message displayed if the browser does not have Java enabled. The browser will attempt to download the appropriate Java plug-in. We use the OBJECT tag shortcut described above to instruct the browser where to find the Java plug-in. Using Listener applets Once a connection has been established with a DataHubBaseApplet, you connect DataHubListener applets to it to display and interact with your data. Here is an example of a Listener applet, DataHubEntryField applet that is an applet that sets the value of the OPC server elements with the entered value.

The DataHubEntryField.Java is an applet that implements the DataHubListener applet that adds to the DataHubEntryField.Java applet the ability to write and to read on the OPC server elements. The main parameters should be declared on the HTML code are:

� Java_code: The applet name. � Points: which is PID1.Sp the point name the applet deals with. � Parent: BaseAppleT1, which is the connection name between the bas applet

and the other, listening applets. � And other parameters to set the layout of the tax field.

Browser Limitations

Internet Explorer versions 6 and 7 cannot display a large number of Java applets on a single page. The limit is variable, but is in the vicinity of 15 applets per page. Mozilla Firefox can reliably display around 200 applets per page, but it may crash with larger numbers of applets on a page.

Page 34: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

34

You can work around browser limitations by using the DataHubTable applet, or by designing your own applets to display more information per applet, thereby reducing the total number of applets on a page.

Page 35: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

35

Chapter 5

Developing the Web-based Control

System As mentioned previously that the main objective of this project is to create a flexible system that enables any user in any place in the world to control, monitor and the see the currents actions on live of any connected plant with the central PC, in this project the quadruple tanks plant was chosen.

In order to start with such that projects the idea of using OPC servers is considered a very strong solution which makes from the designed application applicable for all the connected plant to that server.

Using OPC server overcomes the problem of witting special protocol between the web server and every single connected plant that will make the application difficult to port to different systems.

5.1 Project Components This project as stated previously aims to enable any user over the Wide World Web to control, monitor and to see an online video of the laboratory process due to group of programmed HTML pages, The OPC DataHub server is installed on the central PC that is connected to the quadruple tanks plant using the PPI/PC protocol.

Fig. 5.1: System Components

This system as shown in Figure 5.1 Consists of the QTP ( quadruple tanks plant ) which is controlled by Programmable Logic Controller of type Siemens S7 and also conected to a predefined KEPserver OPC server that controls the plant parameters, the valves values and controller coefficients.

Using the Broad Cam software installed on the central PC the plant process can be seen online by integrating the video server with the web server pages.

A TCP/IP switch should be used then in order to publish the web server that exists on the central PC, then any connected user can log on the central PC web server and to control the plant.

Page 36: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

36

The overall system components shown in the following table: # Component Functions 1 The Quadruple Tanks System The system to be controlled 2 S7 200 Siemens PLC The controller of the system 3 Central PC Contains

• OPC DataHub server, with its Web server. • KEPserver, that connects the PLC due to

the protocol PPI/PC

• The webcam broadcasting program. 4 Switch The enables the users to connect with the central

PC using the TCP/IP protocol. 6 Broad Cam Program Web-Cam video server 5 Web-Camera To monitor the actions of the system. 6 Users PCs The PC of the user who likes to login the system.

Table 5.1: Components Description

5.2 Plant Control Structure The control structure of the system is shown in figure 2.2, this figure describes how the major part of the system are connected to each other. PC

Figure 5.2: Plant Control Structure A cable of PC / PPI and a free communication protocol based on RS 232 exists between the PC and the PLC that contains a data base of the system water levels, sensor values, PID controller coefficients and so on. The Cable PC / PPI makes the RS 232 protocol in the appropriate RS 485 protocol of the PLC Siemens that performs all the controller calculations.

The application which is installed on the central PC must be an OPC server which should define the PLC communication protocol and also to have its own OPC server that enables us to connect the system with Win CC or any application that support the OPC server like: Matlab, Labview and also the OPC DataHub product in order to be able to perform the supervision, management and the data history applications easily.

Plant PLC Data Base

PC/PPI

Kepserver

Page 37: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

37

How the overall system works? The following diagram show the protocols used in this project and how they are communicated with each other.

Fig. 5.3: Data Communication Protocol

The communication between the plant and the end user can be described in the following seven steps:

1) A small data base consists of the location memories that contains information about the plant are stored in the PLC Siemens and varies in real time, that

PPI/PC PC/PPI

PCn

TCP/IP

PLC

TCP/IP TCP/IP

PLC Siemens Database

KespServer

OPC OPC

OPC DataHub WebServer A group of HTML pages embed

Java applets

DataHub OPC server

OPC/ data converter using JNI technique that communicates with

the dlls files

Data Data

Data/OPC converter using JNI technique that communicates with

the dlls files

The

Cen

tral

PC

PC2

PC1

PC3

PC4

PC5

ROUTER The

out

er w

orld

1

2

3

4

5

6

7

Page 38: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

38

information could be water level values, the valves values, the motor speed and also the PID coefficients that controls the water levels of the lower two tanks. In order to communicate with those memory locations the PPI/PC protocol is used to convert the PC Rs232 serial communication protocol with the RS 485 protocol of the PLC Siemens.

2) The predefined OPC server (KEPserver) deals with the definition of PPI/PC

protocol so all the database in the PLC can be expressed by a group of OPC elements, then its easy deal with them.

3) As the KEPserver and the OPC DataHub have been already installed, the

Bridging step between the OPC DataHub server and the KEPserver is essentially to provide the DataHub server wit the real data then to be accessed by the remote user.

4) The own web server of the OPC DataHub, the server contains the programmed

HTML pages that embed the Java applets, and here the technique of JNI programming plays its role to connect the OPC server using the already DLLs files programmed in C.

5) Read and write on the OPC server elements using the OPC DataHub Java

Library.

6) All the information has already been converted from the PLC Siemens protocol into the TCP/IP protocol and then can be distributed using the router connected to the central PC.

7) The user will use the current installed Java plug-in to be able to use the applets.

5.2 Web Server Contents

The server contains two main components the part of connecting to the OPC server and the part of broadcasting the online video. The main page consists of an introduction and links for the four pages which are:

� Process Diagram: That enables the user to show the water levels in the four tanks and also to switch the motor ON/OFF.

� Live Monitoring: An applet that enables the user to show the online system status.

� Control Modes: An applet that enables the user to choose between sending the parameters of the controller or to calculate the controller signal remotely.

� Live Camera: This page links to the video server that exists on the central PC.

Page 39: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

39

5.3 OPC DataHub Server Preparation

After installing the OPC DataHub we should identify the OPC element needed starting from the water levels and PID coefficients all the other OPC server elements are listed in the following table. # OPC Element Function 1 QTP:TankLevel1 The water level in tank 1 2 QTP:TankLevel2 The water level in tank 2 3 QTP:TankLevel3 The water level in tank 3 4 QTP:TankLevel4 The water level in tank 4 5 QTP:StateByte To change the plant status of the motor, valves and the internal PID

Controllers 6 QTP:Ref1 The value of the water flow in branch 1 ( q1 ) 7 QTP:Ref2 The value of the water flow in branch 2 ( q2 ) 8 QTP:Ref3 The value of the water flow in branch 3 ( q3 ) 9 QTP:Ref4 The value of the water flow in branch 4 ( q4 )

Table 5.2: OPC Server Elements

Now the OPC elements have already defined and also the OPC DataHub is configured to work as web server in addition of being OPC server, so the next step is to configure the DataHub in order the OPC elements could represent the physical measurement correctly.

Configuring OPC DataHub

From all of defined OPC servers the OPC DataHub elements are only the elements to be used, because of the Bridging feature that can be configured as follows:

1) Indicate the configuration files that contains the OPC elements definition, as indicated in figure 5.

2) Configure the DataHub to work as an OPC server, as indicated in figure 5.4 3) Configure the OPC DataHub to connect between KEPserver and the OPC DataHub elements, and it can be done easily by the following steps:

• Prepare the OPC DataHub to create a new domain that contains the KEPserver elements, with its name and location as follows: From general under the declare these data domains click on add, as indicated down:

Fig. 5.4: OPC Data Hub Configuration

Page 40: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

40

Fig. 5.5: OPC Data Hub as a Web server

Fig. 5.6: Creating OPC Server Groups

• Then to define the new Domain name, the elements to be chosen and another details listed in figure 5.6 and figure 5.7

Page 41: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

41

Fig. 5.7: Adding Groups

Fig. 5.8: Characteristics of an OPC Group

• Now the project contains two group of OPC domains which are :

� QTP (Quadruple Tanks Process): Represents the selected KEPserever that this project deals with.

Connection Name

Server Locationction

Domain Name

Page 42: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

42

� QTPVariable: Represents all the KEPserver elements, and the next step is to connect between them using the bridging feature that can be performed easily as follows:

Fig. 5.9: Characteristics of an OPC Group

The following tool can be used in order to configure the bridging between the two servers, from Bridging � Point to Point transformation. OPC DataHub not only provides the direct copy bridging but also a transformation tool that stores transformed data on the destination DataHub elements that represents the water levels, motor speed and the water flow in each branch.

Fig. 5.10: OPC Elements Bridging

Page 43: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

43

The provided transformation methods could be:

� Direct Copy: To copy the data directly without any transformation. � Linear Range Mapping: In order to map source data into another range. � Load a stored Transformation: To load a predefined file script that applies a

complex transformation. Example:

It had chosen the second transformation type in order to convert the variable

4321 ,,, hhhh which are in the KEPserver and represent the water level sensors values.

The following table shows the real ranges of the sensor register and the desired marked value:

Sensor Value Water level( M) 6130 0 31612 1.36

Table 5.3: Elements Transformation

5.4 Web Server Preparation

As stated previously the OPC DataHub has its own web server and it can be founded normally in the following directory: C:\Archivos de programa\Cogent\OPC DataHub\Plugin

Fig. 5.11: OPC Data Hub Web Server This folder contains all the necessary files that the server needs: the HTML, pictures, Java libraries, the Ajax files.

Page 44: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

44

The main web page consists looks like the following:

Fig. 5.12: Web Page Start Up

5.4.1 Water Level Diagrams Page This page contains four diagrams to show real time readings for the water levels in the four tanks in addition it contains an applet that summarizes the OPC server elements characteristics.

The four level diagram applet that is used in this project are already provided with the OPC DataHub product, as shown in figure 5.13.

In addition to all the process diagrams applets that are already provided with the OPC DataHub , this page contains the SystemOnOff applet which has been designed in order to:

� Change the four water references used by the controller. � To turn on/off the motor. � To turn on/off the valves of the system.

Figure 5.14 shows the graphical user interface of that applet.

System prgrams

Page 45: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

45

Fig. 5.13: Water level Diagrams

How to use the DataHubTrend? The following steps summarize the steps necessary to deal with the DataHubTrends applet which is:

• To show the real time values of the OPC server element. • Already provided with the product.

� First, Modify the domain parameter match the domain defined in the server side

which is QTP, the name parameter that represents the name of the applet-OPC server connection, the next code segment shows the details.

Page 46: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

46

� Use the following HTML code which declares that DataHubTrend applet that, the parameters to be used are the following:

• The Parent parameter that represent the name of the connection to the OPC server.

• The point parameter which represents any OPC value should be drawn,

• And other parameters such that: the orientation, the background Image and the

Min. Max value of the charts.

How SystemOnOff applet works? This applet is designed in this project contains:

• Four slides bar to modify the value of the four water flow rates. • Two check box to change the status of the motor and the valves.

This applet depends greatly on implementing the DataHubListener applet that DataHublink applet (that initializes the communication object between the Java applets and the OPC sever). The applet looks like the figure 5.14

Page 47: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

47

Fig. 5.14: Turn ONOFF Applet Basic hints in order to build your own applet. Every new applet should be packaged at the same library package which is cogent package in order to use all the provided classes that are indicated in the following code fragment.

� Also the new applets should extends the DataHubListener which add the ability to the to add, delete, change and to access to the OPC server elements.

• Implementing DataHubListener applet

In order to change the value of any existing OPC element the method writes Value () which is extended from the DataHubListener applet and it can be used as indicated in the following code fragment:

Variable Function

Href1 The water flow in branch 1

Href2 The water flow in branch 2

Href3 The water flow in branch 3 Href4 The water flow in branch 4

Table 5.4: Addition Elements Description

Page 48: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

48

The command this.m_parent.getPoint(¨href1¨) is to extract the OPC element called href1 in order to write the data href1.getText() which is the entered data by the remote user.

5.4.2 Monitoring Screen Page This page contains a screen that monitors the quadruple tanks system with an attractive look out the main idea of building that applet is to draw an updatable Java drawing objects over an image that shows the QTP (quadruple tanks plant), thereby we can create a screen that monitors all the actions of the system. The over all page design shown in the following figure.

Fig. 15: Tanks Monitoring Applet

This applet reads data from the OPC server not exactly as the previous applet that reads OPC server elements, so in order to create such that applet it should be taken in accounts the followings hints:

� The following libraries should be imported to enable us to show the designed image and also to draw those rectangles.

Page 49: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

49

� The DataHubListener contain the method setValue() which is called at every

moment the server updates its information, so we can redefine it in our applet and to write all the codes necessary inside this function, as indicated in the following code fragment :

The constants shown in the code fragment are experimental numbers and could

be varied with other applications. The t1y,t1l are variables defined locally to define the positions of the rectangles

to represent the real water levels values. Finally, we should call the repait() variable in order to update the drawings, the

complete codes for more details are in the Appendix

5.4.3 Controller Page

This page contains one applet and its also self designed, it offers to change the

PI controller parameter located in the Central PC server and also to generate the controller signal and to send it to the Plant i.e. do the controller calculation remotely.

As a first step the controller which is performed is a PI controller because it easier to be calculated remotely but as a target of this project another types of controller will be tested such that the Model predictive controller.

Figure 5.16 shows the Interface designed in order to perform the controller with its two modes.

Page 50: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

50

Fig. 5.16: Controller Applet

As stated that the first phase of experiments in this part is to apply the PI controller, i.e. to calculate the PI controller out signal and then to send it to the plant.

The basic idea here is to read the OPC server elements that present the water levels and to calculate the corresponding value of the output controller every sampling time which is determined by the applet, and here are the equations that are going to be programmed.

The output of the continuous PID controller can be presented by the following equation [3]:

And by using the Laplace and Z transform we can get the following expressions .

Pseudo Code previous_error = 0 start: error = setpoint - actual_position P = Kp * error I = I + Ki * error * dt D = (Kd / dt) * (error - previous_error) output = P + I + D previous_error = error wait(dt) goto star

Page 51: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

51

And then the following algorithm could be applied in order to calculate the control signal:

Fig. 5.17: Controller Algorithm Description

This applet has no additional idea, all of to do is to implements that algorithm in java and to use the discussed procedures of how to write on the OPC server to change the inputs of the system according to the PI controller algorithm.

More details regarding to the code could be found in the appendix, the controller results are discussed in chapter 6.

5.4.4 Online Video Webpage

5.4.4.1 Using Java Multimedia FrameWork

The well known solution proposed in order to add the service of online video transmission that enables the user to see the current live process actions is the

Start

Read the water level 2 Read the water level 1

Calculate

( ) ( ) ( )2,1, 222 −− tetete

Read the Controller 2 Coeff. From the applet

Calculate ( )tu2

Calculate

( ) ( ) ( )2,1, 111 −− tetete

Read the Controller 1 Coeff. From the applet

Calculate ( )tu1

Send ( )tu1 , ( )tu 2

To the corresponding OPC Elements

Wait Ts

Page 52: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

52

technology of JMF (Java Multimedia FrameWork), which is a library enables the programmer to deal with the audio, video and other time-based media applications.

This optional package, which can capture, playback, stream, and convert multiple media formats, extends the Java 2 Platform, Standard Edition (J2SE) for multimedia developers by providing a powerful toolkit to develop scalable, cross-platform technology [4].

In addition, the JMF provides already programmed tools that receives, transmit and to captures audio and video Medias which is indicated in the following figure.

Fig. 5.18: JM Studio In order to use this tool to build the video transmission system the followings should be used: JMStudio AVReceive2.Java

The program which transmits the video session over The network.

An applet that receives the transmitted sessions

JMStudio

JMStudio is software package programmed by Java and uses the JMF library in order to deal with the video and audio applications, rather than capturing, playing and storing video Medias. In order to use the video transmission feature, the following steps should be followed:

� Click on , file � transmit:

Page 53: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

53

Fig. 5.19: JM Studio Start up

� Follow the next direct steps until to reach to the following settings , put the IP address of the remote user PC, and the port number which the video session will be transmitted on, as shown in Fig. 5.20

Fig. 5.20: Video Transmission Settings The date needed here is divided in three parts:

� Session address: which is the IP of the remote user’s PC. � Port: which is the port number that the session will be received on. � The TTL: which is a number to identify the session transmitted, since you can

transmit more than one session on the same port number.

Page 54: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

54

Here are the transmission settings:

Session address 172.16.1.2 Port 22224 TTL 1

Table 5.5: Transmission Characteristics

AVReceive2 Now the captures video session is transmitted to the determined IP, so in order to receive that video the AVReceieve2 applet should be used.

AVReceieve2 is an applet provided by the same library, but in order to use it correctly the following hints should be taken in account.

1. On the serve side your receiver applet should be modified in order to receive the transmitted video by the following code that get the current PC IP then to call the AVRecieve applet with the new configuration.

Where the 22224 is the port address and the 1 is the number of the transmitted session. Note:

� This solution provided only One-to-One video transmission, because of the pre-configured IP address, i.e. the video will not be transmitted to all of the connected users.

� One of the problems commonly encountered is the security problems of the

IE (internet explorer), since the applet that writes listens or reads any data are considered as dangerous applets and will be prevented directly.

The solution for that problem is to sign the applet; signing applet is a step to let the explorer to understand that the actions of that applet are guaranteed and secure.

5.4.4.2 Signing Applet

Signing applet is a very important step for that applet that deals with the hardware data such that: listening to the Ethernet port and reading file from hard disk. The importance of signing applets is that you can register the desired guaranteed actions in order to let the browser to understand that those actions are guaranteed and to prevent them.

Page 55: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

55

The following are the summarized steps that show how to sign you applet

1. Package the applet into a JAR file.

The applet must be in a JAR file before a certificate can be attached to it. Use the jar JDK utility. If the applet was previously referenced with the help of a code base attribute in <applet> tag, replace the code base attribute with the archive attribute. The value of the archive attribute is a URL of a JAR file.

To use the 'jar' command, open an MS-DOS window and navigate to the directory where your classes are stored. Notice that this assumes you have already set up a Path on your machine which allows you to use Java SDK commands from anywhere.

For example:

C:\My Documents\Baruch\4150\Day14\EmailApplet\class es>

Then use a jar command which specifies the options, output file name and the files to include:

>jar cfv EmailApplet.jar User.class UserIO.class UserEmailPanel.class EmailApplet.class

Fig. 5.21: Packaging Java Classes

If you run your HTML file now, you will get a security exception (look in the Java console), and the read/write operations will not be carried out. You need to sign it. But before you can sign it, you need a key.

2. Create a public/private key pair. The command for this is

keytool -genkey

keytool is another SDK utility. It will prompt you for a password to your keystore. The keystore is a file that contains your public/private key-pairs, and the public-keys of others with whom you exchange information.

Page 56: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

56

Write the following commands:

keytool -genkey -alias <yourAlias>

Fig. 5.22: Creating Public Key Pair

3. Create a certificate for the key you created in the previous step

keytool -selfcert -alias <yourAlias>

Use key tool in order to generate the certificate file that will be used by the applet in order to let the browser to identify that applet.

4. Run jarsigner to associate this certificate with the JAR file that contains your applet. You will need to give the name of the public key of the certificate you just created. This creates a digest for each file in your JAR and signs them with your private key. These digests or hashes, the public key, and the certificate will all be included in the "WEB-INF" directory of the JAR.

jarsigner -signedjar EmailApplet2.jar EmailApplet.j ar mykey

You can then check to see that the applet is signed by using the -verify option. It's a good idea also to add the -verbose option, so you can see all the details:

jarsigner -verbose -verify EmailApplet2.jar

Page 57: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

57

The applet is now signed. The next time you or someone else downloads it in its page the browser will present a dialog box displaying the credentials you just created for it and asking the user permission to run it.

If chosen not to apply the certificate, the applet will throw the same AccessControlException that we saw in the Java Console window the first time we tried to run it in our browser.

The last and the most important step is to write the following line to the HTML code that will makes the explorer to identify the applet and the corresponding certificate, as follows:

With out this step the applet will not identify the certificate file, then the same problem will occurred, this HTML code defines the CODBASE parameter which is suresh.cab the certificate file.

After all of those steps the exception that was thrown will no ever be thrown because the generated certificate on this section will guarantee all the defined actions.

2 Using BroadCam Software

As noticed previously that the solution proposed offers only the one to one video transmission, because it does not contain a video server. BroadCam product is a video server that provides any logging user to see the webcam video, the followings show the steps to prepare the video server:

� After installing the product, click on the icon:

Fig. 5.22: Using Broad Cam Getting Started

Page 58: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

58

� Click on Broad cam � options � live , to configure the webcam connected to the central PC as shown in Figure 5.23

Fig. 5.23: Setting the Camera Features

� After that press on connect and wait until the video server to be ready. � The last step is to connect the web server with the installed video server and it

can be connected by directory to the following link:

http://10.101.2.251/broadcamjpg.html?src=1&speed=1 The IP should be replaced by the IP of the central PC.

5.4.6 Connecting to OPC Server using OPCClient

This section discusses another way of connecting to the OPC server using Java programming language. As discussed previously that this product connects only to 3 elements at the time of connection for its demo mode, that is what makes using OPC DataHub better than using JOPCClient.

JOPCClient provides just a library that contains a lot of function which enables the programmer to build the system from A to Z knowing every single step of the program processes, such that:

� Connecting the OPC server. � Defining groups.

Page 59: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

59

� Adding OPC server elements and defining their characteristics. � Navigating on the PC to look for the existing OPC server. � Releasing the connection with the OPC server.

Programming with OPCClient Hints

In the first phases of this project the OPCClient library was used in order to test the ability and the difficulties of connecting the OPC servers with application of Java, the following steps discusses the main steps of initializing the connection, defining groups, defining elements, reading the variables, writing on the OPC server elements and releasing the connection.

The following example is an applet that connects with the Tankleve1 and TankLevel2 elements in the OPC DataHub server.

1. Create IOServer object by creating an OpcClientApi object. Use third party OPC client browser in order to find the server name, here is the OPCDataHub server name:

new OpcClientApi("Cogent.OPCDataHub.1");

2. Create an OpcGroup object (implements the IOGroup interface). The name you choose is up to you, and it has no relation with the OPC group on the server. The name must be distinct between groups in the same application. The update rate specified tells the OPC server how often it may call the onValueChanged() method of the IOListener interface.

OpcGroup og1 = oa1.addGroup("testgrp", true, 500, 0 f);

3. Add a listener to the group. As a result JOPCClient will call the onValueChanged(IOItem) of the interface every time an IOItem change value. Example:

og1.addIOListener(iol);

4. Add the IOItems you want to monitor to the already created group. For each IOItem you specify the 'itemId'. This id is the name you get by using the OPC Client browser. For each item you must also specify a data type. The data type decides what Java object type is returned when you call the IOItem.getOldValue() method. If you for instance specify datatype IOItem.DATATYPE_BOOL then a Boolean object will be returned.

Finally you also specify an actionCmd name for the item. This is your logical name for the item which can be used later for retrieving it:

TankLevel1 = og1.addItem("QTP.TankLevel1", null, tr ue, IOItem.DATATYPE_DOUBLE, "my DoubleItem");

Page 60: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

60

5. Add the application specific code to the onValueChanged() method. The IOItem.getOldValue() is used to obtain the new value of the item. The name getOldValue() may seem a little odd, but this actually indicate that this is the last cached value available in JOPCClient, the actual value of the monitored device may actually be

// Called when a data value has changed public void onValueChanged(IOItem i) {

System.out.println("onValueChanged action=" + i.get ActionCommand() + " " + i + "=" + i.getOldValue());}

NOTE: All the complete code can be found in the attached appendix.

Results

1) Running the Applet

Fig. 5.24: Java with OPCClient Library

2) Connecting to the OPC DataHub server

To connect the OPC DataHub Server press on connect , and wait until the confirmation message appears on the text field, the following message appears because of the demo used library.

Fig. 5.25: OPCClient Library Evaluation Version

Page 61: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

61

Fig. 5.26: Server Connected

3) Changing the OPC DataHub Server Elements

Fig. 5.27: Program Changes the OPC Server Elements Values

5.4.7 Comparison between JOPCClient and OPC Data Hub

The following table shows the major differences between using OPCClient and using OPC DataHub in building your project.

Connected succesfully

Page 62: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

62

Criteria JOPCClient OPC DataHub OPC Server Not exists Contains own OPC server Web Server Not exists Contains own web server

Java Library Is a Java library Has also its own library GUI No exists yes

DCOM problems

Exists and needs to be solved There is no DCOM configuration problems

Demo limitations

3 elements at the time of connections

Only one hour of continuous working

Diagram Applets

You should use another libraries in order to build the diagrams applets

Provides a collection of already programmed applets diagrams, gauges

and tables Explorer Security Problems

You should assign the generated applets

There is no security problems, the solution is provided with the product

Table 5.6: OPC Data Hub and JOPCClient Comparison

The problem with DCOM One of the feature that the OPC DataHub provides is the solution of the DCOM configuration problems, so why DCOM configuration is a problem? . DCOM is a Microsoft networking protocol used by OPC servers and clients to communicate over a network. It was not designed for use in modern industrial control applications so it has a number of issues, most notably:

1. DCOM is difficult to configure, even for the experienced user and getting DCOM to work between different networks can sometimes be impossible.

2. Sometimes integrators try to get around these problems by defining very broad access permissions on all computers. However, in an industrial setting, you typically don't want the server and client computers to have the same login permissions, which mean using DCOM; can actually compromise your network security standards.

3. When a DCOM connection is broken, there are very long timeout delays before each side is notified of the problem. In a production environment, these long delays without warning can be a very real problem.

4. Recently, DCOM networking has been show to have serious security flaws that make it vulnerable to hackers and viruses. This is particularly worrying to companies who network data across Internet connections or other links outside the company.

Summary:

� Using DataHub product makes building the web-based control system easier, since it provides: the OPC server, the web server, the solution of DCOM configuration problems and the solution of web browser problems.

� Using DataHub makes building your own applets with the ideas that you would like easier.

Page 63: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

63

� Using OPCClient enables you to test all the process of OPC server steps: connecting to the OPC server, defining groups, adding the elements and searching for the installed OPC servers.

5.5 OPC Data Hub and OPCClient Licensing

1. OPC DataHub

� A web page that uses Java applets to display live data from the DataHub will establish a TCP/IP connection directly to the DataHub; this means that you will need a DataHub TCP Link License for each simultaneous web page connection. For example, if you have 5 people viewing your Java applet page at the same time, then you will need 5 x DataHub TCP Link Licenses (installed on the DataHub computer).

Fig. 5.28: Characteristics of an OPC Group

• You can choose to serve the Java applet pages using the DataHub Web Server, or you can install a third party web server on the same computer as the DataHub. If you choose to use the DataHub Web Server, then you will need a DataHub Web Server License in addition to your DataHub TCP Link Licenses.

• For the Unlimited TCP Link License which enables unlimited TCP/IP connections to the DataHub. This unlimited license is used by customers who want to make their Java applet pages available to everyone on the web.

Table 5.7 shows the list of the licenses and the price of each license.

License Description Price OPC DataHub Node License - provides all functionality of OPC Data Hub for use on a single computer running Windows NT, 2000, XP, 2003 or Vista. Example: Need to use OPC with Excel on same PC as your OPC

US$995

OPC DataHub TCP Link License (Windows - NT/2000/XP/2003/Vista) - used for OPC to Web applications using Java Applets.

US$595

OPC DataHub Web server (XP/2003) - if you want to serve OPC data to web pages

US$3750

Page 64: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

64

using ASP or AJAX. There are no limits on the number of concurrent clients that can connect using this license. No 3rd-party web servers (i.e. IIS or Apache) are required.

Table. 5.7: Licenses Prices

2. JOPCClient

The demo version of JOPCClient has the exact same feature set as the registered version, however with a limitation on the number of connections, groups and items that can be made. The following limitations exist for the demo and the registered version respectively:

Table 5.8: Free and Licensed Copy Comparison

The registered version of JOPCClient is available at a price of EUR 500.

Page 65: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

65

Chapter 6 The Quadruple Tanks System, Description and Controller Design As stated previously the plant chosen to apply the web-based control system is the quadruple tanks plant, In this chapter will be discussed the nature of the QTP and the PI controller design and finally the result of the remote controller designed in chapter 5.

The Quadruple-Tank Process was developed and built 1996 at Lund Institute of Technology, Sweden, in order to illustrate the importance of multivariable zero location for control design. [13] The following reasons makes from the systems good system for both the research and the educational courses.

1. Understanding control limitations due to interactions, model uncertainties, Minimum and no minimum phase behavior.

2. Designing decentralized (often called “multiloop”) controllers, and understanding their limitations

3. Implementing decouples to reduce the effect of interactions, and understanding their limitations

5. Implementing a fully multivariable control system. 6. Changing only in variable that is the valve value that makes change totally the

state of the system from minimum phase to nonmunimum . 7. The controlled variables are coupled strongly. [12]

6.1 System Process and Control Objective The system consists of four interconnected tanks and two motors as indicated in Figure 6.1, Pump extracts water from the tank below to tank 1 and 4, while pump B feeds tank 2 and 3. The relationship between the flow of the water to tank 1 and tank 4 depends on a factor with which is varies from 0 to 1 that is the value of the valves between tank 4 and the feeding line.

The object of the controller here is to control the level of the water in tank 1 and tank 2 taking in account the effect of tank 4 on tank 2 due to the water from the motor 1 and also the effect of tank 3 on tank 1 due to the water from the motor 2.

6.1.1 Differential Equations of the Quadruple Tanks The system behavior can be described using the equation 6.1 to 6.4 and they are nonlinear equations describing the altitude of the water in each tank.

Page 66: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

66

Fig.6.1 the Physical Components of the Four Tanks System

............. (6.1) ............. (6.2) ............. (6.3) ............. (6.4)

Where:

iA : The cross sectional area of each tanks.

ia : The area of the small holes in the bottom of each tank.

ih : The water level in each tank. g : The gravity.

iγ The valve value and its value from 1 to zero. The system is a nonlinear system with two inputs and two outputs, the inputs are the

water flow in each ram 21 qandq and the outputs are the water level in tank one and tank two. The physical dimensions of the system that are listed in table 6.1.

Page 67: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

67

6.1.2 Equations Linearization Using the nonlinear equations shown above and the Taylor series equation that is shown in equation 6, we can derive the linear equations as follows: [12].

Variable Units Value

4321 ,,, AAAA 2m 32

Kc V/cm 0.5

g 2sm 9.81

Table 6.1: Physical Parameter

............. (6.5)

........... (6.6)

........... (6.7) ........... (6.8) ........... (6.9) ........... (6.10) The linear equations:

........... (6.11) ........... (6.12) ........... (6.13) ........... (6.14)

Page 68: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

68

Where: The linearization conditions in case of our system are the following:

........... (6.15)

........... (6.16)

........... (6.17)

........... (6.18)

So in order to calculate the initial conditions of our system we should determine the initial values the pumps water capacity then using equations 6.15 to 6.18 to calculate the corresponding initial water levels in each tank, After that by substituting on the linear model equations we can determine the transfer function and the general transfer function is the following.

........... (6.19)

Since And ........... (6.20)

6.1.3 Transfer Function Characteristics Zeros Locations In order to calculate the zeros position of the MIMO system the following equations should be solved and note here that it is not the case of SISO. The poles and the zeros of the quadruple tanks system can be calculated from equation 6.21

Page 69: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

69

......... (6.21)

The zeros of the QTS are the zeros of the transfer function in equation 6.21 and the poles are the poles the same transfer function. The poles can be calculated as follows: Poles

......... (6.22)

From equation 6.22 we can note that the poles are negatives and the system is stable without any relationship with the valve value. The zeros location can be determined from the second part, so:

Where 43 ττ and are the time constants i.e. the inverse of T3 and T4. So the system has two zeros and in order to study the behavior of the system the roots of the previous equations should be calculated.

� If 10 <+≤ ba γγ , the system has two real zeros. One of them has the real part positive and therefore instable zero (so the system is non minimum phase).

� If 21 ≤+< ba γγ , the system has two zeros with real part negative (minimum phase).

� If 1=+ ba γγ , the system has double zero in the origin.

� The four poles are stable for all the values of aγ and bγ . [13]

6.2 PI Controller Design Controller

In this section steps of designing the PI controller for quadruple tanks system using the CDM (Coefficient Diagram Method) will be shown, after that the controller will be verified using Matlab, at last the practical results of the controller designed in this and implemented in chapter 5 will be shown. Note: In this project only the controller will be designed for the minimum phase case.

6.23) ( .........0)1)(1(

1).( 432

43 =−−

−+++ba

bassγγ

γγττττ

Page 70: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

70

6.2.1 System Initial Conditions Depending on the linear model of the system and the on the equations 6.15 to 6.18 the initial condition could be calculated easily. Minimum phase System zeros in the left side.

The condition that makes of the system is in minimum phase is 10 <+≤ ba γγ , and the valve values should be chosen in order to satisfy that condition as follow:

6.07.0 11 == γγ and

So, the initial conditions are:

Variable Value

10h 0.68 m

20h 0.68 m

30h 0.65 m

40h 0.65 m

( 20

10 ,qq ) (2, 2.0415) h

m3

Table 6.2: Initial Conditions

From the equilibrium points it could be calculated the required areas of the holes in each tanks from equations 6.15 to 6.18, and they are listed in table 6.3.

Variable Value m3

1a -510 9.8604×

2a -510 6.952×

3a -510 2.4762×

4a -510 1.3952×

Table 6.3: Areas of the holes inside each tank Using equations 6.19 and 6.20 we can determine the transfer function, and is shown in equation 6.24.

......... (6.24)

6.2.2 Relative Gain Array The relative gain array (RGA) was introduced by Bristol as a measure of interaction in multivariable control systems. The RGA, noted as A is defined as: [13]

+++

+++=

1512.321

1.3215

)1512.321()13.1566(

6.1607)15.882()168.226(

2.1511

168.226

6.2644

)(

sss

ssssG

Page 71: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

71

Where the asterisk denotes the Schur product (element-by-element matrix multiplication) and -T inverse transpose.

The RGA is used as a tool mainly in the process industry to decide on control structure issues such as input output pair coefficient

In case of the quadruple tanks process the A can be calculated from the following relation: And then the Aw the relative gain factor is the following matrix:

In case of minimum phase the A matrix value is:

Then the transfer functions that affects greatly on the behavior of the outputs are G11, and G22 and then two controllers will be designed in order to modify the behavior of the both transfer functions.

6.2.3 Controller Design using the Coefficient Diagram Method

Most industrial processes have employed PID-family controllers since several decades ago due to their simplicity and their sufficiency in process control applications. It is reported lately that more than 90% of the industrial controllers used nowadays are PI controllers. However, its parameters must be tuned for acceptable responses. The most popular tuning formula is Ziegler-Nichols' tuning formula, which is designed to have quarterly decayed overshoot characteristic in the step response.

The fine tune is needed for over-damped characteristic. S. Manabe has proposed a new design approach called the coefficient diagram method (CDM) for assigning the parameters of controllers. It is an algebraic design algorithm utilizing polynomial form structure.

In CDM, the closed-loop characteristic polynomial is designed based on stability index and equivalent time constant, which are used to determine stability and speed of the closed-loop response. Hence, the unknown controller parameters of the controllers resulting for over-damped response can be obtained [14].

Rules of the CDM Technique in the PI Controller Design Any closed loop nominator polynomial equation can be written as follows:

TGGA −= )0(*)0(

......... (6.25)

Page 72: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

72

And using the group of equations that gives the CDM technique we can determine the coefficients

021 ....,,,, aaaa nnn −−

The stability index, the equivalent time constant and the stability limit are defined as follows:

11

2

−+

=ii

i

i aa

aγ 0

1

a

a=τ

5.2st=τ

5.2,2...... 1331 =====− γγγγ n

Note that the variables indices are constants for all the cases for more information in [15].

Depending on the relative gain factor that indicates the great affect of the G11 and G22 on the behavior of the outputs so the controller with the system will take the following block diagram.

Fig.6.2 the Interconnection of the System the PI Controller

The first closed loop transfer function is:

111111

11

1

1

..1

.1

GGGG

GG

R

Y

kc

c

++=

......... (6.26)

Page 73: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

73

In order to determine the control objective we should see the behavior of the first loop, which is

Represented by the T.F. 11G , the step response of the system is shown in figure 6.3. From figure 6.3 it can be noticed that the settling time is about 877 seconds, so

the objective of the controller will be to decrease that settling time up to 300 seconds. After substituting with the corresponding transfer functions the polynomial of

the denominator is:

12

1 6.2644)6.26441(68.226)( ipi kskssP +++=

So using the equations that the CDM states on that we can determine the corresponding coefficient then the values of the controller coefficients.

As shown in the figure 6.3 that the settling time of the 11G = is about 877 sec. and the desired settling time is 300 sec. then using the following group of equations we can determine the controllers coefficients:

Step Response

Time (sec)

Am

plitu

de

0 500 1000 15000

500

1000

1500

2000

2500

3000

Fig.6.3 the Step Response of the G11 Transfer Function

And from the CDM equations the parameters 012 ,, aaa can be calculated as follows: Since the desired settling time is: 300 sec. so the

0

1

5.2

300

5.2 a

ats ===τ

0212

01

..3

012

aaa

aa

=

=

168.226

6.2644

+s

Page 74: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

74

Since, 2a = 226.68, so By comparing the calculated polynomial from the CDM with the real polynomial so we can calculate the PI parameter.

012

2)( asasasP ++=

The same procedures are repeated but with the second loop, and the second transfer function G22, the following table summaries the controllers designed for the QTP in case of minimum phase.

Parameter Value Parameter Value

1pk 30.85 2pk 60

1ik 70.3 2ik 1.3

Table 6.4 Controller 1 and Controller 2 Parameters

The resulted controllers T.F. are:

30.85)(

70.3)(

1

1

=

=

sGs

sG

k

c

60)(

3.1)(

1

1

=

=

sGs

sG

k

c

Experiments Results The followings are the simulation results and the affect of the controller on the system, figure 6.3 shows the water level in tank 1 and figure 6.3 shows the water level in tank 2.

Fig. 6.3 Water Level in Tank 1

68.226

1016.8

1078.9

2

41

60

=×=

×=

a

a

a

Page 75: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

75

Fig. 6.4 Water Level in Tank 2 Experiment Results In this section the real behavior of the designed controller will be shown, the PI controller was implemented by the code part discussed in chapter 5 due to the web-based control system under the control mode option.

After setting the initial values starting from the initial water values, the valves values and the areas of the holes inside each tank the controller will be ready to be turned on, the following charts were captured from installed software programmed by labview. Test 1:

0,8

0,0

0,1

0,2

0,3

0,4

0,5

0,6

0,7

1180157

hsf1

hsf2

hsf3

hsf4

hf1

hf2

hf3

hf4

Fig. 6.5 Test 1 Water Levels

Fig. 6.6 Test 1 Control Signals

1,0

0,0

0,1

0,2

0,3

0,4

0,5

0,6

0,7

0,8

0,9

1206183

q1

q2

q3

q4

ref1

ref2

ref3

ref4

Page 76: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

76

Note: On the previous figures , the line yellow is the water level at tank one and in blue is the water level in tank two, the same for the controller signals in yellow is the control signal of valve one and in blue is the control signal of valve two. In this experiment the initial conditions of the two water levels were: 0.62 meters and 0.75 meters for tank1 and tank2 respectively.

The control objective was to let the water levels in tank 1 and tank 2: 0.5 and 0.7 respectively. Comments: The settling time was achieved in test 1 and it was found near to 200 seconds, Regarding to the maximum overshot it was near to the 15 cm. Test 2:

Fig. 6.7 Test 2 Water Levels

Fig. 6.8 Test 2 Control Signals In this experiment the initial conditions of the two water levels were: 0.6 meters and 0.67 meters for tank1 and tank2 respectively, The control objective was to let the water levels in tank 1 and tank 2: 0.5 and 0.7 respectively.

Page 77: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

77

Comments: The settling time was achieved in test 1 and it was found near to 320 seconds, Regarding to the maximum overshoots it was near to the 20 cm for tank1 and 25 Cm. Test 3:

Fig. 6.9 Test 3 Water Levels

Fig. 6.10 Test 3 Control Signals

In this experiment the initial conditions of the two water levels were: 0.6 meters and 0.6 meters for tank1 and tank2 respectively. The control objective was to let the water levels in tank 1 and tank 2: 0.3 and 0.4 respectively. Comments: The settling time was achieved in test 1 and it was found near to 420 seconds, Regarding to the maximum overshoots it was near to the 20 cm for tank1 and 15 Cm. Summary From the three experiments shown above we can conclude the followings:

� The PI controller designed at the beginning of the chapter works goof enough. � The Settling time, which was the control objective of the Controller, has been

achieved during the three experiments shown, with as average of: 313 seconds taking in account that the original settling time was about 870 seconds.

The PI controller was implemented by Java programming and those results were the result of the remote PI controller, which is a part of the web-based control system.

Page 78: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

78

This page has been intentionally left blank.

Page 79: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

79

7. Future work A solution of building web-based control system has been shown in this project and the solutions of the problems that could be encountered also have been shown. At the end of this project one of the famous controller has been implemented in order to test the ability of controlling the plant remotely by designing PI controller. As a future work we could do the following:

� Implement another control algorithm such that the Model Predictive Controller algorithm and to study the best controller that could be used to control the plant remotely.

� To study the affect of the networks on the behavior of the controller.

Page 80: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

80

This page has been intentionally left blank.

Page 81: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

81

8.References [ 1 ] B. Qiu and H. B. Gooi, Web-Based SCADA Display Systems (WSDS) for Access via Internet, IEEE TRANSACTIONS ON POWER SYSTEMS, VOL. 15, NO. 2, MAY 2000. [ 2 ] Bin Qiu, Hoay Beng Gooi,Yilu Liu, Eng Kiat Chan, Internet Based SCADA System, IEEE Computer Applications in Power, 2002. [ 3 ] http://en.wikipedia.org/wiki/Java_Native_Interface. [ 4 ] http://www.opi.dk/index.php?id=261. [ 5 ] http://www.netmodule.com/en/solutions/embeddedjava/index.shtml. [ 6 ] http://www.opcconnect.com/java.php. [ 7 ] R.Fan, L. Cheded and O.Toker, Internet based SCADA a new approach using Java and XML, IEEE computer and control Engineering, OCT/NOV 2005. [ 8 ] http://www.opcdatahub.com/WhatIsOPC.html [9]http://www.matrikonopc.com/training/opcmultimediatutorial/opc_tutorial_printable_version.pdf. [10] OPC Overview, OPC Foundation, October 27, 1998. [11] Yoh Shimanuki, OLE for Process Control (OPC) for New Industrial Automation Systems, 1999, IEEE. [ 12 ] A Quadruple Tank Process Control Experiment by/ Effendi Rusli, Siong Ang, and Richard D. Braatz Department of Chemical and Biomolecular Engineering. [ 13 ] Teaching Multivariable Control Using the Quadruple-Tank Process, Karl Henrik Johanssont , Alexander Horcht, Olle Wijkt, and Anders Hanssont 1999. [ 14 ] Appendix B Designing of the four Tanks System. [ 15 ] I-P Controller design for Quadruple Tank System, by Arjin Numsomran,Kritchai Witheephanich Thanit Trisuwannawat and Kitti Tirasesth. [ 16 ] Simplified Design of PI Controller Based on CDM, by Jongkol Ngamwiwit1 and Noriyuki Komine International Joint Conference 2006. [ 17 ] Application of Coefficient Diagram Method for Rotational Inverted Pendulum Control, by A, I. Cahyadi', D. Isarakorn', T. Benjanarasuth', J. Ngamwiwit' and N. Komine, 2004.

Page 82: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

82

This page has been intentionally left blank.

Page 83: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

83

9. Appendix Java Applet Codes

1. Monitoring Applet

This is the code of the applet that monitors the water levels of the four tanks system and the alarm status. In this applet the idea of using the OPC Datahub Java library to build your own applet will be shown. The main ideas used here in this applet are.

• Converting the OPC elements values to a dynamic graph, that reflects the currents actions of the system.

• Using the simple Java 2D skills such that: Importing Image and drawing dynamic triangles to be able to design the graphical user interface.

JAVA CODE

2. package cogent; 3. import java.awt.*; 4. import java.awt.Graphics; 5. import java.awt.Image; 6. public class Monitoring extends DataHubListener { 7. Image image; 8. int t1y=0; 9. int t1l=0; 10. int t2y=0; 11. int t2l=0; 12. int t3y=0; 13. int t3l=0; 14. int t4y=0;

Page 84: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

84

15. int t4l=0; 16. boolean t1=false; 17. boolean t2=false; 18. boolean t3=false; 19. boolean t4=false; 20. public void init() { 21. try { 22. java.awt.EventQueue.invokeAndWait(new Runnable() { 23. public void run() { 24. initComponents(); 25. } 26. }); 27. } catch (Exception ex) { 28. ex.printStackTrace(); 29. } 30. // Displaying the Image 31. image = getImage(getDocumentBase(), "QTPDiagram.GIF "); 32. // is soo esential in order to let the applet to id entify the 33. // outer listener i.e. to exchage the inoformation in between 34. super.init(); 35. } 36. // paint is the method that draws all the rectangle s 37. // in real time depending on the changing in the co ordination of the

rectangles 38. public void paint (Graphics g2) 39. { 40. Graphics2D g = (Graphics2D) g2; 41. g.drawImage(image, 10, 10, this); 42. GradientPaint redtowhite = new

GradientPaint(0,0,Color.blue,100,0,Color.WHITE,true ); 43. g.setPaint(redtowhite); 44. // the four tanks 45. g.fillRect(194,t1y,144,t1l); 46. g.fillRect(389,t2y,145,t2l); 47. g.fillRect(199,t3y,144,t3l); 48. g.fillRect(391,t4y,144,t4l); 49. g.setColor(Color.RED); 50. // Alarms 51. if (t1==true) 52. {g.fillOval(124, 497, 16 , 16 );} 53. if (t2==true){ 54. g.fillOval(559, 510, 17 , 17 );} 55. if (t4==true){ 56. g.fillOval(554, 127, 16 , 16 );} 57. if (t3==true){ 58. g.fillOval(123, 132, 16 , 16 );} 59. } 60. /** This method is called from within the init() me thod to 61. initialize the form. 62. WARNING: Do NOT modify this code. The content of th is method is 63. always regenerated by the Form Editor. 64. */ 65. // <editor-fold defaultstate="collapsed" desc="Gene rated Code"> 66. private void initComponents() { 67. setLayout(null); 68. } 69. // this is the value inherited from the DataHub lis tener class 70. // and updates its self with every time the element s of the 71. // OPC Server change 72. public void setValue(DataHubPoint point, boolean is _echo) 73. { 74. //Note every order of read should be called from se tValue() 75. double temp = this.m_parent.getPoint("TankLevel3"). getDoubleValue(); 76. t1y = (int)(236-112.307*temp)+1; 77. t1l = (int)((147/1.3)*temp); 78. if (temp>=1.3) 79. { 80. t3=true;

Page 85: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

85

81. }else 82. { 83. t3=false; 84. } 85. temp = this.m_parent.getPoint("TankLevel4").getDoub leValue(); 86. t2y = (int)(236-112.307*temp)+1; 87. t2l = (int)((147/1.3)*temp); 88. if (temp>=1.3) 89. { 90. t4=true; 91. }else 92. { 93. t4=false; 94. } 95. temp = this.m_parent.getPoint("TankLevel1").getDoub leValue(); 96. t3y = (int)(574-152.2058823*temp); 97. t3l = (int)((208/1.36)*temp); 98. if (temp>=1.36) 99. { 100. t1=true; 101. }else 102. { 103. t1=false; 104. } 105. temp = this.m_parent.getPoint("TankLevel2").getDoub leValue(); 106. t4y = (int)(574-152.2058823*temp); 107. t4l = (int)((208/1.36)*temp); 108. if (temp>=1.36) 109. { 110. t2=true; 111. }else 112. { 113. t2=false; 114. } 115. // calling repaint to update the rectangles accordi ng to the real values 116. // got from the setValue method 117. repaint(); 118. } }

2. System On Off Applet

This is the code of the applet that enables us to turn On-Off the motor connected and also to change the valves values. The main idea of this applet is how to use the OPC Java library to write on the OPC server remotely.

Page 86: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

86

JAVA CODE

5. package cogent; 6. public class controllerSender extends DataHubListen er { 7. /** Initializes the applet SystemOnOff */ 8. public void init() { 9. try {

� java.awt.EventQueue.invokeAndWait(new Runnable() { � public void run() {

� initComponents(); � } � });

3. } catch (Exception ex) { � ex.printStackTrace();

4. } 10. super.init(); 11. } 12. private void initComponents() { 13. jPanel1 = new javax.swing.JPanel(); 14. jPanel2 = new javax.swing.JPanel(); 15. href4Value = new javax.swing.JTextField(); 16. href3Value = new javax.swing.JTextField(); 17. href4 = new javax.swing.JSlider(); 18. href1Value = new javax.swing.JTextField(); 19. href2Value = new javax.swing.JTextField(); 20. jLabel1 = new javax.swing.JLabel(); 21. jLabel2 = new javax.swing.JLabel(); 22. jLabel3 = new javax.swing.JLabel(); 23. jLabel4 = new javax.swing.JLabel(); 24. href1 = new javax.swing.JSlider(); 25. href2 = new javax.swing.JSlider(); 26. href3 = new javax.swing.JSlider(); 27. valvesOnOff = new javax.swing.JCheckBox(); 28. motorOnOff = new javax.swing.JCheckBox(); 29. jButton1 = new javax.swing.JButton(); 30. jButton2 = new javax.swing.JButton(); 31. setLayout(null); 32. jPanel1.setLayout(null); 33. jPanel2.setBorder(javax.swing.BorderFactory.createT itledBorder("L

evel References")); 34. jPanel2.setLayout(null); 35. href4Value.addActionListener(new java.awt.event.Act ionListener()

{

Page 87: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

87

36. public void actionPerformed(java.awt.event.ActionEv ent evt) { 37. href4ValueActionPerformed(evt); 38. } 39. }); 40. jPanel2.add(href4Value); 41. href4Value.setBounds(210, 110, 40, 20); 42. href3Value.addActionListener(new java.awt.event.Act ionListener()

{ 43. public void actionPerformed(java.awt.event.ActionEv ent evt) { 44. href3ValueActionPerformed(evt); 45. } 46. }); 47. jPanel2.add(href3Value); 48. href3Value.setBounds(160, 110, 40, 20); 49. href4.setMajorTickSpacing(10); 50. href4.setMinorTickSpacing(1); 51. href4.setOrientation(javax.swing.JSlider.VERTICAL); 52. href4.setPaintTicks(true); 53. href4.setSnapToTicks(true); 54. href4.addChangeListener(new javax.swing.event.Chang eListener() { 55. public void stateChanged(javax.swing.event.ChangeEv ent evt) { 56. href4StateChanged(evt); 57. } 58. }); 59. jPanel2.add(href4); 60. href4.setBounds(210, 20, 40, 90); 61. href1Value.addActionListener(new java.awt.event.Act ionListener()

{ 62. public void actionPerformed(java.awt.event.ActionEv ent evt) { 63. href1ValueActionPerformed(evt); 64. } 65. }); 66. jPanel2.add(href1Value); 67. href1Value.setBounds(10, 110, 40, 20); 68. href2Value.addActionListener(new java.awt.event.Act ionListener()

{ 69. public void actionPerformed(java.awt.event.ActionEv ent evt) { 70. href2ValueActionPerformed(evt); 71. } 72. }); 73. jPanel2.add(href2Value); 74. href2Value.setBounds(60, 110, 40, 20); 75. jLabel1.setText("href4"); 76. jPanel2.add(jLabel1); 77. jLabel1.setBounds(210, 140, 40, 14); 78. jLabel2.setText("href1"); 79. jPanel2.add(jLabel2); 80. jLabel2.setBounds(10, 140, 40, 14); 81. jLabel3.setText("href2"); 82. jPanel2.add(jLabel3); 83. jLabel3.setBounds(60, 140, 60, 14); 84. jLabel4.setText("href3"); 85. jPanel2.add(jLabel4); 86. jLabel4.setBounds(160, 140, 50, 14); 87. href1.setMajorTickSpacing(10); 88. href1.setMinorTickSpacing(1); 89. href1.setOrientation(javax.swing.JSlider.VERTICAL); 90. href1.setPaintTicks(true); 91. href1.setSnapToTicks(true); 92. href1.addChangeListener(new javax.swing.event.Chang eListener() { 93. public void stateChanged(javax.swing.event.ChangeEv ent evt) { 94. href1StateChanged(evt); 95. }

Page 88: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

88

96. }); 97. jPanel2.add(href1); 98. href1.setBounds(10, 20, 40, 90); 99. href2.setMajorTickSpacing(10); 100. href2.setMinorTickSpacing(1); 101. href2.setOrientation(javax.swing.JSlider.VERTICAL); 102. href2.setPaintTicks(true); 103. href2.setSnapToTicks(true); 104. href2.addChangeListener(new javax.swing.event.Chang eListener() { 105. public void stateChanged(javax.swing.event.ChangeEv ent evt) { 106. href2StateChanged(evt); 107. } 108. }); 109. jPanel2.add(href2); 110. href2.setBounds(60, 20, 40, 90); 111. href3.setMajorTickSpacing(10); 112. href3.setMinorTickSpacing(1); 113. href3.setOrientation(javax.swing.JSlider.VERTICAL); 114. href3.setPaintTicks(true); 115. href3.setSnapToTicks(true); 116. href3.addChangeListener(new javax.swing.event.Chang eListener() { 117. public void stateChanged(javax.swing.event.ChangeEv ent evt) { 118. href3StateChanged(evt); 119. } 120. }); 121. jPanel2.add(href3); 122. href3.setBounds(160, 20, 40, 90); 123. jPanel1.add(jPanel2); 124. jPanel2.setBounds(30, 20, 260, 180); 125. valvesOnOff.setText("Close Valves"); 126. valvesOnOff.setActionCommand(""); 127. jPanel1.add(valvesOnOff); 128. valvesOnOff.setBounds(30, 240, 110, 23); 129. motorOnOff.setText("Open Motor"); 130. motorOnOff.setActionCommand("Motor ON"); 131. jPanel1.add(motorOnOff); 132. motorOnOff.setBounds(30, 210, 110, 20); 133. jButton1.setText("Write References"); 134. jButton1.addActionListener(new java.awt.event.Actio nListener() { 135. public void actionPerformed(java.awt.event.ActionEv ent evt) { 136. jButton1ActionPerformed(evt); 137. } 138. }); 139. jPanel1.add(jButton1); 140. jButton1.setBounds(149, 240, 140, 23); 141. jButton2.setText("Write ByteState"); 142. jButton2.setAutoscrolls(true); 143. jButton2.addActionListener(new java.awt.event.Actio nListener() { 144. public void actionPerformed(java.awt.event.ActionEv ent evt) { 145. jButton2ActionPerformed(evt); 146. } 147. }); 148. jPanel1.add(jButton2); 149. jButton2.setBounds(150, 210, 140, 23); 150. add(jPanel1); 151. jPanel1.setBounds(0, 0, 310, 290); 152. }// 153. private void jButton2ActionPerformed(java.awt.event .ActionEvent

evt) { 154. // TODO add your handling code here: 155. String StateByte="0"; 156. if (motorOnOff.isSelected()==true &&

valvesOnOff.isSelected()==true )

Page 89: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

89

157. { 2. StateByte ="61";

158. } 159. if (motorOnOff.isSelected()==true &&

valvesOnOff.isSelected()==false ) 160. {

2. StateByte ="63"; 161. } 162. if (motorOnOff.isSelected()==false &&

valvesOnOff.isSelected()==true ) 163. {

2. StateByte ="60"; 164. } 165. if (motorOnOff.isSelected()==false &&

valvesOnOff.isSelected()==false ) 166. {

2. StateByte ="62"; 167. } 168. boolean result; 169. result = writeValue(this.m_parent.getPoint("StateByte"),

StateByte); 170. } 171. private void href4StateChanged(javax.swing.event.Ch angeEvent evt)

{ 172. // TODO add your handling code here: 173. // The Integer to double conversion is done because the Jslider 174. // can´t generate double values 175. href4Value.setText(Double.valueOf(href4.getValue())/100+""); 176. } 177. private void href1StateChanged(javax.swing.event.Ch angeEvent evt)

{ 178. // TODO add your handling code here: 179. href1Value.setText(Double.valueOf(href1.getValue())/100+""); 180. } 181. private void href2StateChanged(javax.swing.event.Ch angeEvent evt)

{ 182. // TODO add your handling code here: 183. href2Value.setText(Double.valueOf(href2.getValue())/100+""); 184. } 185. private void href3StateChanged(javax.swing.event.Ch angeEvent evt)

{ 186. // TODO add your handling code here: 187. href3Value.setText(Double.valueOf(href3.getValue())/100+""); 188. } 189. private void jButton1ActionPerformed(java.awt.event .ActionEvent

evt) { 190. // TODO add your handling code here: 191. boolean result; 192. result = writeValue(this.m_parent.getPoint("href1"),

href1Value.getText()); 193. result = writeValue(this.m_parent.getPoint("href2"),

href2Value.getText()); 194. result = writeValue(this.m_parent.getPoint("href3"),

href3Value.getText()); 195. result = writeValue(this.m_parent.getPoint("href4"),

href4Value.getText()); 196. } 197. private javax.swing.JSlider href1; 198. private javax.swing.JTextField href1Value; 199. private javax.swing.JSlider href2; 200. private javax.swing.JTextField href2Value; 201. private javax.swing.JSlider href3; 202. private javax.swing.JTextField href3Value; 203. private javax.swing.JSlider href4;

Page 90: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

90

204. private javax.swing.JTextField href4Value; 205. private javax.swing.JButton jButton1; 206. private javax.swing.JButton jButton2; 207. private javax.swing.JLabel jLabel1; 208. private javax.swing.JLabel jLabel2; 209. private javax.swing.JLabel jLabel3; 210. private javax.swing.JLabel jLabel4; 211. private javax.swing.JPanel jPanel1; 212. private javax.swing.JPanel jPanel2; 213. private javax.swing.JCheckBox motorOnOff; 214. private javax.swing.JCheckBox valvesOnOff; 215. }

3. PI Controller Implementation Code This is an example of implementing the remote controller using PI controller, in this applet the main idea is to using the skills of reading and writing OPC elements that OPC Datahub library provides to implement a controller that should control the quadruple tanks remotely.

1. package cogent; 2. public class Test extends DataHubListener { 3. double textvalue=90; 4. boolean stop= false; 5. double setPoint1,setPoint2,actualPosition1,actualPo sition2; 6. // those variable in order to create the thread tha t enables as to

devide the 7. // CPU process into 2 parts that is what avoids the problem of infinite

loop 8. private Thread methodThread ; 9. private boolean cond = true ; 10. double prv_error1 = 0; 11. double error1=0; 12. double P1=0; 13. double I1=0; 14. int dt=0; 15. double output1=0; 16. double prv_error2 = 0; 17. double error2=0;

Page 91: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

91

18. double P2=0; 19. double I2=0; 20. double output2=0; 21. double q1=0; 22. double q2=0; 23. double q3=0; 24. double q4=0; 25. double gamma1=0.7; 26. double gamma2=0.6; 27. public void init() { 28. try { 29. java.awt.EventQueue.invokeAndWait(new Runnable() { 30. public void run() { 31. initComponents(); 32. } 33. }); 34. } catch (Exception ex) { 35. ex.printStackTrace(); 36. } 37. super.init(); 38. } 39. /** This method is called from within the init() me thod to 40. initialize the form. 41. WARNING: Do NOT modify this code. The content of th is method is 42. always regenerated by the Form Editor. 43. */ 44. // <editor-fold defaultstate="collapsed" desc="Gene rated Code"> 45. private void initComponents() { 46. jPanel3 = new javax.swing.JPanel(); 47. jScrollPane2 = new javax.swing.JScrollPane(); 48. controller2 = new javax.swing.JTable(); 49. jScrollPane3 = new javax.swing.JScrollPane(); 50. controller1 = new javax.swing.JTable(); 51. jLabel2 = new javax.swing.JLabel(); 52. jLabel3 = new javax.swing.JLabel(); 53. jLabel1 = new javax.swing.JLabel(); 54. samplingTime = new javax.swing.JTextField(); 55. setPointb = new javax.swing.JTextField(); 56. setPointa = new javax.swing.JTextField(); 57. jLabel4 = new javax.swing.JLabel(); 58. jLabel5 = new javax.swing.JLabel(); 59. jPanel4 = new javax.swing.JPanel(); 60. sendControl = new javax.swing.JRadioButton(); 61. sendCoeff = new javax.swing.JRadioButton(); 62. stopSending = new javax.swing.JButton(); 63. jButton1 = new javax.swing.JButton(); 64. o2 = new javax.swing.JTextField(); 65. t1 = new javax.swing.JTextField(); 66. t2 = new javax.swing.JTextField(); 67. e1 = new javax.swing.JTextField(); 68. e2 = new javax.swing.JTextField(); 69. o1 = new javax.swing.JTextField(); 70. q44 = new javax.swing.JTextField(); 71. q11 = new javax.swing.JTextField(); 72. q22 = new javax.swing.JTextField(); 73. q33 = new javax.swing.JTextField();

74. setLayout(null);

75. jPanel3.setBackground(new java.awt.Color(255, 255, 255)); 76. jPanel3.setBorder(javax.swing.BorderFactory.createT itledBorder("PID

Controller Coefficients")); 77. jPanel3.setLayout(null);

Page 92: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

92

78. controller2.setModel(new javax.swing.table.DefaultT ableModel( 79. new Object [][] { 80. {"1", "30"} 81. }, 82. new String [] { 83. "Ki", "Kp" 84. } 85. )); 86. jScrollPane2.setViewportView(controller2);

87. jPanel3.add(jScrollPane2); 88. jScrollPane2.setBounds(30, 100, 454, 40);

89. controller1.setModel(new javax.swing.table.DefaultT ableModel( 90. new Object [][] { 91. {"3", "30"} 92. }, 93. new String [] { 94. "Ki", "Kp" 95. } 96. )); 97. jScrollPane3.setViewportView(controller1);

98. jPanel3.add(jScrollPane3); 99. jScrollPane3.setBounds(30, 40, 454, 40);

100. jLabel2.setText("Controller 2"); 101. jPanel3.add(jLabel2); 102. jLabel2.setBounds(30, 80, 160, 14);

103. jLabel3.setText("Controller 1"); 104. jPanel3.add(jLabel3); 105. jLabel3.setBounds(30, 20, 160, 14);

106. jLabel1.setText("Sampling Time in mSec"); 107. jPanel3.add(jLabel1); 108. jLabel1.setBounds(300, 150, 120, 20);

109. samplingTime.setText("500"); 110. jPanel3.add(samplingTime); 111. samplingTime.setBounds(420, 150, 59, 20);

112. setPointb.setText("0.7"); 113. setPointb.addActionListener(new java.awt.event.Acti onListener() {

Page 93: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

93

114. public void actionPerformed(java.awt.event.ActionEv ent evt) { 115. setPointbActionPerformed(evt); 116. } 117. }); 118. jPanel3.add(setPointb); 119. setPointb.setBounds(250, 150, 22, 20);

120. setPointa.setText("0.5"); 121. setPointa.addActionListener(new java.awt.event.Acti onListener() { 122. public void actionPerformed(java.awt.event.ActionEv ent evt) { 123. setPointaActionPerformed(evt); 124. } 125. }); 126. jPanel3.add(setPointa); 127. setPointa.setBounds(100, 150, 22, 20);

128. jLabel4.setText("Set Point2"); 129. jPanel3.add(jLabel4); 130. jLabel4.setBounds(174, 150, 60, 14);

131. jLabel5.setText("Set Point1"); 132. jPanel3.add(jLabel5); 133. jLabel5.setBounds(24, 150, 60, 14);

134. add(jPanel3); 135. jPanel3.setBounds(20, 20, 510, 180);

136. jPanel4.setBackground(new java.awt.Color(255, 255, 255)); 137. jPanel4.setBorder(javax.swing.BorderFactory.createT itledBorder("C

ontrol Mode Selection")); 138. jPanel4.setLayout(null);

139. sendControl.setBackground(new java.awt.Color(255, 2 55, 255)); 140. sendControl.setText("Send Control Coefficient"); 141. sendControl.addActionListener(new java.awt.event.Ac tionListener()

{ 142. public void actionPerformed(java.awt.event.ActionEv ent evt) { 143. sendControlActionPerformed(evt); 144. } 145. }); 146. jPanel4.add(sendControl); 147. sendControl.setBounds(60, 30, 170, 23);

148. sendCoeff.setBackground(new java.awt.Color(255, 255 , 255)); 149. sendCoeff.setText("Send Control Signals"); 150. sendCoeff.addActionListener(new java.awt.event.Acti onListener() { 151. public void actionPerformed(java.awt.event.ActionEv ent evt) { 152. sendCoeffActionPerformed(evt); 153. }

Page 94: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

94

154. }); 155. jPanel4.add(sendCoeff); 156. sendCoeff.setBounds(260, 30, 220, 23);

157. stopSending.setText("Stop Sending"); 158. stopSending.addActionListener(new java.awt.event.Ac tionListener()

{ 159. public void actionPerformed(java.awt.event.ActionEv ent evt) { 160. stopSendingActionPerformed(evt); 161. } 162. }); 163. jPanel4.add(stopSending); 164. stopSending.setBounds(60, 70, 110, 20);

165. jButton1.setText("jButton1"); 166. jButton1.addActionListener(new java.awt.event.Actio nListener() { 167. public void actionPerformed(java.awt.event.ActionEv ent evt) { 168. jButton1ActionPerformed(evt); 169. } 170. }); 171. jPanel4.add(jButton1); 172. jButton1.setBounds(290, 70, 75, 23);

173. add(jPanel4); 174. jPanel4.setBounds(20, 210, 510, 110);

175. o2.setText("jTextField1"); 176. add(o2); 177. o2.setBounds(270, 500, 59, 20);

178. t1.setText("jTextField1"); 179. add(t1); 180. t1.setBounds(80, 340, 59, 20);

181. t2.setText("jTextField1"); 182. add(t2); 183. t2.setBounds(80, 370, 59, 20);

184. e1.setText("jTextField1"); 185. e1.addActionListener(new java.awt.event.ActionListe ner() { 186. public void actionPerformed(java.awt.event.ActionEv ent evt) { 187. e1ActionPerformed(evt); 188. } 189. }); 190. add(e1); 191. e1.setBounds(80, 420, 59, 20);

Page 95: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

95

192. e2.setText("jTextField1"); 193. add(e2); 194. e2.setBounds(80, 450, 59, 20);

195. o1.setText("jTextField1"); 196. add(o1); 197. o1.setBounds(190, 500, 59, 20);

198. q44.setText("jTextField2"); 199. add(q44); 200. q44.setBounds(400, 450, 59, 20);

201. q11.setText("jTextField2"); 202. add(q11); 203. q11.setBounds(400, 340, 59, 20);

204. q22.setText("jTextField2"); 205. add(q22); 206. q22.setBounds(400, 380, 59, 20);

207. q33.setText("jTextField2"); 208. add(q33); 209. q33.setBounds(400, 420, 59, 20); 210. }// </editor-fold>

211. private void sendControlActionPerformed(java.awt.event.ActionEve nt evt) {

212. //set the values of the controller1,controlelr2 coe fficients 213. boolean result;

214. result = writeValue(this.m_parent.getPoint("C1KI"),controlle r1.getValueAt(0, 0).toString());

215. result = writeValue(this.m_parent.getPoint("C1KP"), controller1.getValueAt(0, 1).toString());

216. result = writeValue(this.m_parent.getPoint("C2KI"), controller2.getValueAt(0, 0).toString());

217. result = writeValue(this.m_parent.getPoint("C2KP"), controller2.getValueAt(0, 1).toString());

218. }

Page 96: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

96

219. private void sendCoeffActionPerformed(java.awt.even t.ActionEvent evt) {

220. // TODO add your handling code here:

221. sendControl.setSelected(false); 222. cond=true; 223. setPoint1=0; 224. setPoint2=0; 225. actualPosition1=0; 226. actualPosition2=0; 227. prv_error1 = 0; 228. error1=0; 229. P1=0; 230. I1=0; 231. dt=0; 232. output1=0; 233. prv_error2 = 0; 234. error2=0; 235. P2=0; 236. I2=0; 237. output2=0; 238. q1=0; 239. q2=0; 240. q3=0; 241. q4=0;

242. // Switching off the internal PID Controller 243. boolean result; 244. result = writeValue(this.m_parent.getPoint("StateBy te"),"29"); 245. methodThread = new Thread ( new Runnable () 246. { 247. public void run () 248. { 249. while ( cond ) 250. { 251. calculateControllerSignals( 252. Double.valueOf(controller1.getValueAt(0, 0).toStrin g()), 253. Double.valueOf(controller1.getValueAt(0, 1).toStrin g()), 254. Double.valueOf(controller2.getValueAt(0, 0).toStrin g()), 255. Double.valueOf(controller2.getValueAt(0, 1).toStrin g())); 256. } 257. } 258. }); 259. methodThread.start() ; 260. }

261. private void stopSendingActionPerformed(java.awt.event.A ctionEvent evt) {

262. // TODO add your handling code here: 263. // in order to stop the sending process 264. cond=false; 265. }

266. private void setPointaActionPerformed(java.awt.even t.ActionEvent evt) {

Page 97: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

97

267. // TODO add your handling code here: 268. }

269. private void e1ActionPerformed(java.awt.event.Actio nEvent evt) { 270. // TODO add your handling code here: 271. }

272. private void setPointbActionPerformed(java.awt.even t.ActionEvent evt) {

273. // TODO add your handling code here: 274. }

275. private void jButton1ActionPerformed(java.awt.event .ActionEvent evt) {

276. // TODO add your handling code here: 277. boolean result; 278. result = writeValue(this.m_parent.getPoint("h1ref") ,

Double.parseDouble(setPointa.getText())); 279. result = writeValue(this.m_parent.getPoint("h2ref") ,

Double.parseDouble(setPointb.getText())); 280. }

281. // Variables declaration - do not modify 282. private javax.swing.JTable controller1; 283. private javax.swing.JTable controller2; 284. private javax.swing.JTextField e1; 285. private javax.swing.JTextField e2; 286. private javax.swing.JButton jButton1; 287. private javax.swing.JLabel jLabel1; 288. private javax.swing.JLabel jLabel2; 289. private javax.swing.JLabel jLabel3; 290. private javax.swing.JLabel jLabel4; 291. private javax.swing.JLabel jLabel5; 292. private javax.swing.JPanel jPanel3; 293. private javax.swing.JPanel jPanel4; 294. private javax.swing.JScrollPane jScrollPane2; 295. private javax.swing.JScrollPane jScrollPane3; 296. private javax.swing.JTextField o1; 297. private javax.swing.JTextField o2; 298. private javax.swing.JTextField q11; 299. private javax.swing.JTextField q22; 300. private javax.swing.JTextField q33; 301. private javax.swing.JTextField q44; 302. private javax.swing.JTextField samplingTime; 303. private javax.swing.JRadioButton sendCoeff; 304. private javax.swing.JRadioButton sendControl; 305. private javax.swing.JTextField setPointa; 306. private javax.swing.JTextField setPointb; 307. private javax.swing.JButton stopSending; 308. private javax.swing.JTextField t1; 309. private javax.swing.JTextField t2; 310. // End of variables declaration

311. public void setValue(DataHubPoint point, boolean is _echo)

Page 98: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

98

312. { 313. // Those lines are to read the setPoint1 and setPoi nt2 conitously

so 314. // In any time we need the online data will be exis t 315. setPoint1 =Double.valueOf(setPointa.getText()) ; 316. setPoint2 =Double.valueOf(setPointb.getText()) ; 317. actualPosition2=this.m_parent.getPoint("TankLevel2" ).getDoubleVal

ue(); 318. actualPosition1=this.m_parent.getPoint("TankLevel1" ).getDoubleVal

ue(); 319. } 320. // This method is to generate the controller signal s i.e.

calculate the controller remotely 321. public void calculateControllerSignals(double C1KI, double

C1KP,double C2KI,double C2KP) a. {

322. // Reading dt the sampling time 323. dt= Integer.valueOf(samplingTime.getText()); 324. // Calculating the errors, and then the contro sign al 325. // The Controller # 1 326. // dt/1000.0 because dt in mSec 327. error1 = setPoint1-actualPosition1; 328. P1 = C1KP*error1; 329. I1 = I1 + C1KI * error1 * (dt/1000.0); 330. output1 = P1+I1; 331. prv_error1 = error1; 332. // The Controller # 2 333. error2 = setPoint2-actualPosition2; 334. P2 = C2KP*error2; 335. I2 = I2 + C2KI * error2 * (dt/1000.0); 336. output2 = P2+I2; 337. prv_error2 = error2;

338. q1=gamma1*output1; 339. q2=gamma2*output2; 340. q3=(1-gamma2)*output2; 341. q4=(1-gamma1)*output1;

342. if (C1KI == 0) {I1=0;} 343. if (C2KI == 0){I2=0;}

344. // Check the compatibility of the output signal 345. if (q1 >= 3) {q1=3; } 346. if (q2 >= 3){q2=3;} 347. if (q3 >= 3) {q3=3;} 348. if (q4 >= 3){ q4=3;} 349. if (q1 < 0){q1=0;} 350. if (q2 < 0){q2=0; } 351. if (q3 < 0) { q3=0; } 352. if (q4 < 0){ q4=0; }

353. t1.setText(actualPosition1+""); 354. t2.setText(actualPosition2+""); 355. // in order to print the actual reading of the both tanks levels

Page 99: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

99

356. System.out.println("TL1: " + actualPosition1 + "TL2 : " + actualPosition2 );

357. e1.setText(error1+""); 358. e2.setText(error2+""); 359. o1.setText(output1+""); 360. o2.setText(output2+""); 361. q11.setText(q1+""); 362. q22.setText(q2+""); 363. q33.setText(q3+""); 364. q44.setText(q4+""); 365. // Senting Control Signals 366. // check the compatibilty 367. boolean result; 368. result = writeValue(this.m_parent.getPoint("href1") , (q1/3)); 369. result = writeValue(this.m_parent.getPoint("href2") , (q2/3)); 370. result = writeValue(this.m_parent.getPoint("href3") , (q3/3));

result = writeValue(this.m_parent.getPoint("href4") , (q4/3));

//dt in mSeconds

try {Thread.sleep(dt);}

catch(InterruptedException ex) {}

371. } 372. }

4. OPC Server with JOPCClient Product

This code presents the second way to connect your application with the OPC server, using the JOPCClient Library

1. import dk.opi.io.*; 2. import dk.opi.io.opc.opcclient.*; 3. //import com.genlogic.*; 4. public class GUI extends javax.swing.JApplet implem ents IOListener 5. {

Page 100: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

100

6. protected IOItem TankLevel; 7. protected IOItem TankLeve2; 8. static IOServer MyServer = null; 9. /** Initializes the applet GUI */ 10. public void init() { 11. try { 12. java.awt.EventQueue.invokeAndWait(new Runnable() { 13. public void run() {

initComponents();

14. } 15. }); 16. } catch (Exception ex) {

ex.printStackTrace();

17. } 18. }

19. /** This method is called from within the init() me thod to 20. initialize the form. 21. WARNING: Do NOT modify this code. The content of th is method is 22. always regenerated by the Form Editor. 23. */ 24. // <editor- fold defaultstate="collapsed" desc="Generated Code" > 25. private void initComponents() { 26. jTabbedPane2 = new javax.swing.JTabbedPane(); 27. jTabbedPane1 = new javax.swing.JTabbedPane(); 28. jPanel1 = new javax.swing.JPanel(); 29. Connect = new javax.swing.JButton(); 30. Close = new javax.swing.JButton(); 31. Status = new javax.swing.JTextField(); 32. jPanel2 = new javax.swing.JPanel(); 33. jScrollPane1 = new javax.swing.JScrollPane(); 34. ServerElements = new javax.swing.JTable(); 35. jPanelLevelMonitor = new javax.swing.JPanel(); 36. jButton1 = new javax.swing.JButton(); 37. Connect.setText("Connect"); 38. Connect.setActionCommand("Connect To Server"); 39. Connect.addActionListener(new java.awt.event.Action Listener() { 40. public void actionPerformed(java.awt.event.ActionEv ent evt) { 41. ConnectActionPerformed(evt); 42. } 43. }); 44. Close.setText("Close"); 45. Close.addActionListener(new java.awt.event.ActionLi stener() {

2. public void actionPerformed(java.awt.event.ActionEv ent evt) { 3. CloseActionPerformed(evt); 4. }

46. }); 47. Status.addActionListener(new java.awt.event.ActionL istener() {

2. public void actionPerformed(java.awt.event.ActionEv ent evt) { 3. StatusActionPerformed(evt); 4. }

48. });

Page 101: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

101

49. org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);

50. jPanel1.setLayout(jPanel1Layout); 51. jPanel1Layout.setHorizontalGroup( 52. jPanel1Layout.createParallelGroup(org.jdesktop.layo ut.GroupLayout

.LEADING) � .add(jPanel1Layout.createSequentialGroup() � .addContainerGap()

53. .add(jPanel1Layout.createParallelGroup(org.jdesktop .layout.GroupLayout.LEADING)

� .add(Status, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 201 , org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

54. .add(jPanel1Layout.createParallelGroup(org.jdesktop .layout.GroupLayout.TRAILING, false)

� .add(org.jdesktop.layout.GroupLayout.LEADING, Close , org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)

� .add(org.jdesktop.layout.GroupLayout.LEADING, Connect, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))

� .addContainerGap(304, Short.MAX_VALUE)) 3. ); 4. jPanel1Layout.setVerticalGroup(

55. jPanel1Layout.createParallelGroup(org.jdesktop.layo ut.GroupLayout.LEADING)

� .add(jPanel1Layout.createSequentialGroup() � .add(30, 30, 30) � .add(Status,

org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

� .add(18, 18, 18) � .add(Connect,

org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 23, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

� .addPreferredGap(org.jdesktop.layout.LayoutStyle.UN RELATED)

� .add(Close) � .addContainerGap(275, Short.MAX_VALUE))

3. ); 4. jTabbedPane1.addTab("Server Connect", jPanel1); 5. ServerElements.setModel(new javax.swing.table.Defau ltTableModel(

� new Object [][] { � {null, null, null} � }, � new String [] { � "Tank Level", "Water Flow", "Valve" � }

6. )); 7. jScrollPane1.setViewportView(ServerElements); 8. org.jdesktop.layout.GroupLayout jPanel2Layout = new

org.jdesktop.layout.GroupLayout(jPanel2); 9. jPanel2.setLayout(jPanel2Layout); 10. jPanel2Layout.setHorizontalGroup(

56. jPanel2Layout.createParallelGroup(org.jdesktop.layo ut.GroupLayout.LEADING)

� .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()

� .addContainerGap(43, Short.MAX_VALUE)

Page 102: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

102

� .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 454 , org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

� .add(18, 18, 18)) 3. ); 4. jPanel2Layout.setVerticalGroup(

57. jPanel2Layout.createParallelGroup(org.jdesktop.layo ut.GroupLayout.LEADING)

� .add(jPanel2Layout.createSequentialGroup() � .add(32, 32, 32) � .add(jScrollPane1,

org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

� .addContainerGap(329, Short.MAX_VALUE)) 3. ); 4. jTabbedPane1.addTab("Monitor Variables", jPanel2); 5. jButton1.setText("Show Live Data"); 6. jButton1.addActionListener(new java.awt.event.Actio nListener() {

� public void actionPerformed(java.awt.event.ActionEv ent evt) {

� jButton1ActionPerformed(evt); � }

7. }); 8. org.jdesktop.layout.GroupLayout jPanelLevelMonitorL ayout = new

org.jdesktop.layout.GroupLayout(jPanelLevelMonitor) ; 9. jPanelLevelMonitor.setLayout(jPanelLevelMonitorLayo ut); 10. jPanelLevelMonitorLayout.setHorizontalGroup(

58. jPanelLevelMonitorLayout.createParallelGroup(org.jd esktop.layout.GroupLayout.LEADING)

� .add(jPanelLevelMonitorLayout.createSequentialGroup () � .add(126, 126, 126) � .add(jButton1,

org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 109 , org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

� .addContainerGap(280, Short.MAX_VALUE)) 3. ); 4. jPanelLevelMonitorLayout.setVerticalGroup(

59. jPanelLevelMonitorLayout.createParallelGroup(org.jd esktop.layout.GroupLayout.LEADING)

� .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanelLevelMonitorLayout.createSequentialGroup()

� .addContainerGap(366, Short.MAX_VALUE) � .add(jButton1) � .addContainerGap())

3. ); 4. jTabbedPane1.addTab("Tank Level Diagram", jPanelLev elMonitor); 5. org.jdesktop.layout.GroupLayout layout = new

org.jdesktop.layout.GroupLayout(getContentPane()); 6. getContentPane().setLayout(layout); 7. layout.setHorizontalGroup(

60. layout.createParallelGroup(org.jdesktop.layout.Grou pLayout.LEADING)

� .add(layout.createSequentialGroup() � .add(jTabbedPane1,

org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 520 , org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

� .addContainerGap(90, Short.MAX_VALUE)) 3. ); 4. layout.setVerticalGroup(

61. layout.createParallelGroup(org.jdesktop.layout.Grou pLayout.LEADING)

� .add(layout.createSequentialGroup() � .add(jTabbedPane1,

org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 425 , org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

Page 103: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

103

� .addContainerGap(org.jdesktop.layout.GroupLayout.DE FAULT_SIZE, Short.MAX_VALUE))

3. ); 62. }// </editor-fold> 63. private void ConnectActionPerformed(java.awt.event. ActionEvent

evt) { 2. // TODO add your handling code here: 3. // This codeis responsible of esablishing the conne ction 4. try{

� connect(); � IOGroup g1 = createGroup1(this);n � // fire an onValueChange() event for all added item s in

order to ensure � // our application get the initial item values for all

items in the group. � // Read all items initial value using the

IOItem.DEVICE_READ option 5. g1.fireAllItems(this, true, IOItem.DEVICE_READ); 6. } catch (RbxIOException e) {

� e.printStackTrace(); 7. } 8. // In order to print the status of the server 9. if (MyServer != null) {

� Status.setText("The Server is Conenct Successfully" ); 10. } 11. // Extracting the variables from the server

64. } 65. private void CloseActionPerformed(java.awt.event.Ac tionEvent evt)

{ 2. // TODO add your handling code here: 3. // Before we close the application we should be sur e that the

connection is closed also 4. if (MyServer != null)

� MyServer.releaseConnection(); � System.exit(0);

66. } 67. private void StatusActionPerformed(java.awt.event.A ctionEvent

evt) { 2. // TODO add your handling code here:

68. } 69. private void jButton1ActionPerformed(java.awt.event .ActionEvent

evt) { 2. // TODO add your handling code here:

70. } 71. // Variables declaration - do not modify 72. private javax.swing.JButton Close; 73. private javax.swing.JButton Connect; 74. private javax.swing.JTable ServerElements; 75. private javax.swing.JTextField Status; 76. private javax.swing.JButton jButton1; 77. private javax.swing.JPanel jPanel1; 78. private javax.swing.JPanel jPanel2; 79. private javax.swing.JPanel jPanelLevelMonitor; 80. private javax.swing.JScrollPane jScrollPane1; 81. private javax.swing.JTabbedPane jTabbedPane1; 82. private javax.swing.JTabbedPane jTabbedPane2; 83. // End of variables declaration 84. public static void connect() throws RbxIOException { 85. // Initialize the OPC client interface to a Iconics simulated OPC

server 86. MyServer = new OpcClientApi("Cogent.OPCDataHub.1"); 87. } 88. public IOGroup createGroup1(IOListener iol) throws RbxIOException

� {

Page 104: Chapter 1 Introduction - Universidad de Sevillabibing.us.es/proyectos/abreproy/70050/descargar_fichero/memoria.pdf · [7] Traditional SCADA systems are similar to Distributed Control

--------------------------------------------------------------------------------------------------------------- Web-based Control System – Master Project – The University of Seville

104

89. // Get the reference to the OPC Server 90. OpcClientApi oa1 = (OpcClientApi)MyServer; 91. // Add a group to this server 92. OpcGroup og1 = oa1.addGroup("testgrp", true, 500, 0 f); 93. // Sign up specified listener for value change even ts. The

onValueChanged() 94. // method of the listener will be callled. It's imp ortant to sign

up 95. // as listener before items are added, otherwise no tifications

may be lost 96. og1.addIOListener(iol); 97. // Add three items - the item name is specific for the type of

device you 98. // are going to read from. The specified item name (ie.

"Device1.boolItem") 99. // must match the item name as it is known to the O PC server. 100. TankLevel = og1.addItem("QTP.TankLevel1", null, tru e,

� IOItem.DATATYPE_INT, "myIntItem"); 101. // TankLeve2 = og1.addItem("TankLevel2", null, true , 102. // IOItem.DATATYPE_STRING, "m yIntItem"); 103. return(og1); 104. } 105. // Called when a data value has changed 106. public void onValueChanged(IOItem i) { 107. System.out.println("onValueChanged action=" +

i.getActionCommand() + " " + 108. i + "=" + i.getOldValue()+" quality=" + i.getOldQua lity()); 109. ServerElements.setValueAt(TankLevel.getOldValue(), 0,0); 110. ServerElements.setValueAt(TankLeve2.getOldValue(), 0,1); 111. } 112. }