You are on page 1of 100

<Int> <Ind> <Rev>

<Int>
Technical
Information FCN/FCJ Java Function
Programmer's Guide
TI 34P02K26-01E

Yokogawa Electric Corporation TI 34P02K26-01E


2-9-32, Nakacho, Musashino-shi, Tokyo, 180-8750 Japan ©Copyright Dec.2003
Tel.: 81-422-52-5586 Fax.: 81-422-52-9802 1st Edition Dec.15,2002
2nd Edition Jul.25,2003
<Toc> <Ind> <Rev> <Introduction> i

Introduction
The STARDOM autonomous controller FCN/FCJ (hereinafter abbreviated as FCN/FCJ)
has not only control functions, but it also has an environment for the execution of Java
applications. The FCN/FCJ function for the execution of Java applications is called the
FCN/FCJ Java function. By application of the FCN/FCJ Java function, sending and
receiving e-mail and Web server functions become possible for FCN/FCJ, and functions
for data accumulation and calculations also can be produced.
This guide explains the outline for the creation of Java applications running on FCN/FCJ
and the tutorial.
y This guide has been written for persons who develop Java applications with
FCN/FCJ.
y This is the programmer's guide for the FCN/FCJ Java function loaded in the
autonomous controller FCN/FCJ.
y The details for each function and the usage are introduced in the online help. This
guide includes a tutorial easy to understand even for first-time users.
y Understanding the contents of this manual requires the knowledge of an outline of
the functions of the Java language and programming of Java applications as well as
the knowledge of the basic operation of FCN/FCJ. Accessing the data of the control
functions with tutorial also requires the knowledge of the construction of the
FCN/FCJ control functions.

Composition of this Guide


This guide has the following composition.

1. Outline
Application examples for the FCN/FCJ Java function are shown together with the
operation environment and related documents.
2. Function Specifications
The function outline for the FCN/FCJ Java function is shown.
3. Tutorial
This is a tutorial for actual creation of applications.

All Rights Reserved. Copyright © 2003, Yokogawa Electric Corporation TI 34P02K26-01E 2002.12.15-00
2003.07.25-00
<Toc> <Ind> <Rev> <Introduction> ii

Map of Related Documents


Hardware Manual
STARDOM FCN/FCJ Guide (IM 34P02Q01-01E)
Specifications, installation, caution items, etc. for the autonomous controller FCN/FCJ
are described.

Software Manual
y Online help

STADOM FCN/FCJ Java Application Development Kit Online Help

The FCN/FCJ Java application development kit is explained from the outline to class
library setting details.

STADOM FCN/FCJ Webmetry Basic Library Online Help

The Webmetry basic library is explained from the outline to program examples and
the class library setting details.
y Technical information

FCN/FCJ Java Function Programmer's Guide (TI 34P02K26-01E)

(This guide) The outline of the FCN/FCJ Java function and the tutorial are described.

All Rights Reserved. Copyright © 2003, Yokogawa Electric Corporation TI 34P02K26-01E 2002.12.15-00
2003.07.25-00
<Int> <Ind> <Rev> Toc-1

STARDOM
FCN/FCJ Java Function
Programmer's Guide
TI 34P02K26-01E 2nd Edition

CONTENTS
1. Outline........................................................................................... 1-1
1.1 Positioning of the FCN/FCJ Java Function .......................................... 1-1
1.2 FCN/FCJ Java Function .......................................................................... 1-2
1.3 FCN/FCJ Java Application Development Kit ........................................ 1-3
1.4 Operation Environment .......................................................................... 1-4
1.5 Related Packages and Documents........................................................ 1-5
2. Function Specifications............................................................... 2-1
2.1 FCN/FCJ Java Function .......................................................................... 2-1
2.1.1 JEROS basic part......................................................................... 2-3
2.1.2 JEROS Extended Part ................................................................. 2-4
2.1.3 System Settings ........................................................................... 2-5
2.2 Webmetry Basic Library Portfolio.......................................................... 2-6
3. Tutorial .......................................................................................... 3-1
3.1 Installation Preparations (required software)....................................... 3-1
3.2 Programming Section ............................................................................. 3-7
3.2.1 Development Flow ....................................................................... 3-7
3.2.2 FCN/FCJ Java Function............................................................... 3-8
3.2.3 Sleeper Creation ........................................................................ 3-10
3.2.4 Compiling ................................................................................... 3-15
3.2.5 Operation Confirmation.............................................................. 3-16
3.3 Actual Machine Operation Section...................................................... 3-21
3.3.1 Sleeper Operation...................................................................... 3-21
3.3.2 Start of FCN/FCJ in Maintenance Mode .................................... 3-22
3.3.3 Jar File Creation and Transfer to FCN/FCJ ............................... 3-25
3.3.4 AdditionalClassPath Setting....................................................... 3-27
3.3.5 Restart in Online Mode .............................................................. 3-31
3.3.6 Duolet Execution ........................................................................ 3-32

TI 34P02K26-01E 2002.12.15-00
2003.07.25-00
<Int> <Ind> <Rev> Toc-2
3.4 Mail Examples........................................................................................ 3-40
3.4.1 Mail Replyer Creation ................................................................ 3-40
3.4.2 Mail Function.............................................................................. 3-41
3.4.3 Compile and File Transfer.......................................................... 3-44
3.4.4 E-mail Function Setting.............................................................. 3-45
3.4.5 Execution and Operation Confirmation...................................... 3-50
3.5 FTP Examples ........................................................................................ 3-52
3.5.1 Creation of PeriodicCopy ........................................................... 3-52
3.5.2 Execution and Operation Confirmation...................................... 3-56
3.6 Examples for the Control Data Access Class .................................... 3-57
3.6.1 Reverser Creation...................................................................... 3-57
3.6.2 Device Label .............................................................................. 3-58
3.6.3 Definition of the Device Label Variable ...................................... 3-59
3.6.4 Code Creation ............................................................................ 3-64
3.6.5 Execution ................................................................................... 3-70
3.7 Creation of Combined Applications .................................................... 3-72
3.7.1 Application Outline ..................................................................... 3-72
3.7.2 Preparing the Control application .............................................. 3-73
3.7.3 Code Creation ............................................................................ 3-74
3.7.4 Execution Preparation................................................................ 3-80
3.7.5 Execution and Operation Confirmation...................................... 3-81
Revision......................................................................................................i

TI 34P02K26-01E 2002.12.15-00
2003.07.25-00
<Toc> <Ind> <1. Outline > 1-1

1. Outline
This chapter shows the outline of the FCN/FCJ Java function of the STARDOM
autonomous controller FCN/FCJ (hereinafter abbreviated as FCN/FCJ).
The FCN/FCJ Java function is the function for execution of Java applications on
FCN/FCJ. Control functions programmed with IEC 61131-1 run on FCN/FCJ. The
FCN/FCJ Java function runs independently from these control functions, and Java
functions for monitoring of control data, alarm notification, logging, etc. can be created.

1.1 Positioning of the FCN/FCJ Java Function


With FCN/FCJ, the realtime OS always runs two types of function, control functions and
the FCN/FCJ Java function. With the FCN/FCJ Java function, JEROS system service
can be used as the platform, and Java applications can use various functions of the OS.
The FCN/FCJ Java function runs in a separate memory space so as not to influence
other functions (control functions etc.). Accordingly, even when the Java applications
consume much memory, the memory space of the control engine part is not threatened.
Java applications run with a lower priority than the control application running on the
control function.

Controller

control function FCN/FCJ Java function

<<Control AP>> <<Control AP >> <<Java AP>> <<Java AP>>


:IEC6113 :IEC6113 :Duolet :Duolet

<<Control execution engine>> <<Java platform>>


:JEROS system service

<<Realtime OS>>

Hardware

Figure: Positioning of the FCN/FCJ Java function

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <1. Outline > 1-2

1.2 FCN/FCJ Java Function


Various things can be accomplished by use of the FCN/FCJ Java function.
The system composition shown in the following figure shows examples for use of the
FCN/FCJ Java function.

E-mail notification
Storage of trend of alarm messages Java development
data etc. environment
Etc (SMTP)

FTP server Mail server Development PC

Controller

Figure: Examples for the FCN/FCJ Java function

The following functions are offered to realize the above examples.

JEROS system service


y Platform for the realtime OS
This controls the JavaVM(Virtual Machine) running on the realtime OS and offers
services such as access data of the control functions, sending/receiving e-mail.
y Java application management
This offers an environment for multitasking of Java applications. The unit of these
applications is called a Duolet.

Development Environment
y Use of the development environment
JDK (Java Development Kit) and the FCN/FCJ Java application development kit can
be used to develop user original Java application.
y Downloading to FCN/FCJ
A developed Duolet can be loaded to the system card of the FCN/FCJ with ftp.

The user can use this platform to create original Duolets for alarm detection algorithms,
I/O diagnosis, etc. In addition, the following functions also can be implemented for
FCN/FCJ.
y Data monitoring using a Web server
y Alarm notification (e-mail) or operation commands (execution of functions by
receiving e-mail) using sending/receiving e-mail
y Original HTML tag definitions and executions using Web base applications
y Storage of FCN/FCJ data using the FTP client, server function

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <1. Outline > 1-3

1.3 FCN/FCJ Java Application Development Kit


FCN/FCJ Java applications are developed using the Java Development Kit (JDK) of Sun
Microsystems on Windows.
The FCN/FCJ Java Application Development Kit offers the following tools for the
development of applications running on the FCN/FCJ Java function.

Class libraries
The following class libraries used with JDK are offered.
y JADE class library
This is the class library for multitask execution management of Java applications on
FCN/FCJ.
y JEROS class library
This is the class library for system management.
y Control data access library
This is the class library for accessing control function data.

Duolet monitor
This is the software for monitoring Java applications running on FCN/FCJ on a Windows
machine.
Java applications running on FCN/FCJ can be monitored on Windows, and this is used
for debugging of Java applications.

JEROS emulator
This is the software for emulation of the FCN/FCJ Java environment on Windows. This
is used for debugging of Java applications for FCN/FCJ on Windows.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <1. Outline > 1-4

1.4 Operation Environment


Development Environment
y Hardware
Machine type : Corresponding to the logic designer operation environment
y Software
OS : Corresponding to the logic designer operation environment
y Java development environment
: JDK1.1.8 or later offered by Sun Microsystems (J2SE SDK
1.3.1 or later recommended. However, the Java standard
class of the FCN/FCJ Java function is compliant with the API
of JDK 1.1.8, so that APIs added later cannot be used for the
FCN/FCJ Java function.)
FCN/FCJ Java application development kit
: R1.20.01 or later
Web browser : Internet Explorer 5.5 SP2 or later
(required when modify system setting file)
y Controller
Machine type : STARDOM autonomous controller FCN/FCJ

Execution Environment
y Hardware
Machine type : STARDOM autonomous controller FCN/FCJ (*1)
y Software
FCN/FCJ basic software : R1.20.01 or later (*2)

*1: The FCN/FCJ Java function cannot be used with FCN with a dual CPU configuration.
*2: With the FCN/FCJ basic software, the software with Java function must be selected for the basic specifications
code.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <1. Outline > 1-5

1.5 Related Packages and Documents


The packages related to the development of applications for the FCN/FCJ Java function
are shown.
Table: List of packages related to the FCN/FCJ Java function
Model GS number Name

FCN/FCJ Java application development kit


NT755FJ GS 34P02Q76-01E
(provided as the FCN/FCJ software medium)

Option Functions for the FCN/FCJ Java Function


Webmetry basic library portfolio
The Webmetry basic library portfolio is a library used with the FCN/FCJ Java function,
and it is the library for creation of applications where FCN/FCJ itself sends information
as a Web server.
The Webmetry basic library portfolio is composed of the Webmetry basic library portfolio
license for execution of applications on FCN/FCJ and the Webmetry basic library for
creation of applications.

Model GS number Name


NT8010J GS 34P02P50-01E Webmetry basic library portfolio license

Webmetry basic library


--- GS 34P02P50-01E
(provided as the application portfolio software medium)

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <1. Outline > 1-6

FCN/FCJ Related Documents


The documents related to FCN/FCJ are shown. Instruction manuals (IM) can be
purchased. However, the following instruction manuals are included as PDF files on the
FCN/FCJ software medium on which the FCN/FCJ Java Application Development Kit is
recorded. For general specifications (GS) and technical information (TI), please contact
the sales department in charge.

STARDOM GS (General Specifications)


GS34P02A01-02E STARDOM Outline
GS34P02Q01-01E Autonomous Controller FCN/FCJ (functions)
GS34P02Q11-01E Autonomous Controller FCN/FCJ (software)
GS34P02Q12-01E Autonomous Controller FCN/FCJ (hardware)

STARDOM IM (Instruction Manuals)


IM34P02Q01-01E STARDOM FCN/FCJ Operation Instruction
IM34P02Q81-01E Use of FCN/FCJ
IM34P02Q91-01E STARDOM FCN/FCJ Installation Procedure

STARDOM TI (Technical Information)


TI34P02A01-02E STARDOM Introduction
TI34P02A51-01E STARDOM Application Guide, Vol. 1
TI34P02K21-01E First Step Guide
TI34P02K25-01E STARDOM Network Configuration Guide
TI34P02Q01-01E Introduction of FCN/FCJ
TI34P02Q02-01E FCN/FCJ Function Outline
TI34P02Q11-01E FCN/FCJ Structure
TI34P02Q91-01E FCN/FCJ Installation Guide

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <2. Function Specifications > 2-1

2. Function Specifications
This chapter explains the outline of the FCN/FCJ Java function.

2.1 FCN/FCJ Java Function


The composition of the FCN/FCJ Java function is shown below.

Java application (Duolet)


Java JADE class
class
library JEROS system class
Java standard class Control data access class

Correspondence

JEROS system service


JEROS JEROS System
extended part basic part OS
setting
file

Hardware

Figure: Composition of the FCN/FCJ function

JEROS system service


The JEROS system service is composed of the basic part and the extended part. The
basic part provides the functions required for network computing and the hardware
drivers provided by the OS. The extended part provides the application framework and
manages multitasked Java applications (Duolets). The JEROS extended part is
composed of the multitask management system called JADE.

Java class libraries


With the FCN/FCJ Java function, the following class libraries can be used for the
development of applications.
y Java standard class
This is the class library provided by the Java language, and all classes can be used,
except for AWT and other classes using the GUI. This class is the Java language
class specified by Sun Microsystems, and the FCN/FCJ Java Function is compliant
with version 1.1.8.
y JEROS system class
This offers the interface for the function offered by the JEROS basic part.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <2. Function Specifications > 2-2
y JADE class
This is a multitask management system for execution of Java applications called
Duolet.
y Control data access class
Class library for access to data of control functions programmed with IEC 61131-3.

Java applications
FCN/FCJ executes Java applications called Duolet which is managed by the JADE
class. Duolets can use the class provided by JADE, Java standard class and class
library provided by the JEROS system class, control data access class.

System setting
The operation of the JEROS system service is decided by a number of system files
which are read in only once at the time of system start. These configurations are set on
a maintenance homepage using a Web browser. For the operation, please refer to
STARDOM FCN/FCJ Guide (IM 34P02Q01-01E).

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <2. Function Specifications > 2-3

2.1.1 JEROS basic part


Table: List of JEROS basic part functions and support

Item Outline Java class library

Network function TCP/IP communication driver Java standard class


Periodic sleep function Periodically wakes up the thread. JEROS System Class

Measures the elapsed time between two points in time with


Laptime measuring function JEROS System Class
high accuracy.

Java Standard Class


System clock function Reference to and setting of the system time
JEROS System Class

Records the operation history and errors of the JEROS basic


Kernel log function JEROS System Class
part and logs writing from applications.

File system function Reads/writes files compatible with the MS-DOS file system. Java System Class

Detects application termination requests.


Makes termination requests to applications.
System shut-down function JEROS System Class
Forcibly terminates applications.
Resets the system.
Java run environment Starts Java VM and executes Java applications. JEROS System Class
FTP server function Starts and stops an FTP server. JEROS System Class
Web server function Starts and stops a Web server. JEROS System Class
Maintenance function Performs remote setting of IP addresses. None
FTP client function The FTP client function is executed. JADE Class

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <2. Function Specifications > 2-4

2.1.2 JEROS Extended Part


Table: List of JEROS extended part functions and support

Item Outline Java class library

Duolet management Creates, starts, stops, and deletes Duolets.


JADE Class
function Manages the state of Duolet.
Event notification function
Sends and receives events between Duolets. JADE Class
between Duolets
Network communication Sends and receives messages between Duolets which are
JADE Class
function between Duolets connected via a network.

Records the processing results and errors in the JEROS extended


System log function JADE Class
part and logs writing from applications.

Linked with the system shut-down function of the JEROS basic


JEROS extended part
part, this customizes the hook handling at the time of JADE JADE Class
management function
start/stop and network correspondence (Duolet monitor).

Timer event notification


Notifies periodic timer events. JADE Class
function

Performs immediate e-mail sending, spooled e-mail sending, and


E-mail function JADE Class
e-mail reception (correspondence to SMTP/POP3).

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <2. Function Specifications > 2-5

2.1.3 System Settings


A Web browser can be used to configure the JEROS system services. The system
setting files setting these configurations are shown below.
As the system setting file is read in only once at the time of FCN/FCJ booting, FCN/FCJ
must be rebooted to reflect any changes.
For details, refer to Help from the FCN/FCJ maintenance home page.
Table: System setting files
Name File name Setting contents

Network function, system shut-down function, Java execution


JEROS basic setting file DUONUS.PRP
function, FTP server function, Web server function
User account definition file DUOUSERS Web server function, FTP server function, maintenance function

Duolet management function, network communication function


Duolet environment setting file JADE.PRP between Duolets, system log function, JEROS extended part
management function

Duolet start definition file MDUOLOAD.PRP Setting of the Duolet loaded at the time of FCN/FCJ start
E-mail setting file DEVMAIL.PRP E-mail function
Network function
Host name definition file HOSTS Setting of the e-mail server used for the FCN/FCJ Java function
etc.

IP routing setting file GATEWAYS Network function(*1)


Kernel log setting file JRLOG.PRP Kernel log function
Web file name definition file FNAMES.TBL Web server function

*1: Basically it is set by the STARDOM node configurator.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <2. Function Specifications > 2-6

2.2 Webmetry Basic Library Portfolio


The Webmetry basic library portfolio is an option portfolio running on the FCN/FCJ Java
function. This portfolio is composed of the class library and license for creation of
applications which acquire data on FCN/FCJ and monitor data on Web browser of the
machine on the network. This library is composed of two modules, the data collection
part running on JADE and the data display part running on the Web browser. The user
can display data to the Web browser just by programming (Java) the data collection part.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial > 3-1

3. Tutorial
This chapter explains the installation of the FCN/FCJ Java function, environment
setting, and the creation and execution of programs.

3.1 Installation Preparations (required software)


In addition to the FCN/FCJ Basic Software the following three types of software are
required to go through this tutorial. If these software are not installed on the personal
computer being used, please install them before installing basic software. The
explanations for this tutorial assume that the required software has been installed to the
default installation locations.
For use of the FCN/FCJ Java function it is required to select the software with Java
function for the basic specification code specified at the time of FCN/FCJ basic software
license arrangement.
Table: Software required for the tutorial described and examples

Default
Software used for this
Software type URL for the software suppliers installation
tutorial
Folder

Java development
environment Sun Microsystems Corporation
JDK1.1.8 C:\jdk1.1.8
(JDK1.1.8 or later) http://java.sun.com/Products/OV_jdkProducts.html
(*1)

Microsoft Corporation
Web browser Internet Explorer 5.5 SP2
http://www.microsoft.com/ie_intl/ja

C:\YOKOGAWA\
FCN/FCJ Java
FCN/FCJ Java application FCN-
application Yokogawa Electric Corporation
development kit (NT755FJ) FCJ\JavaApDevel
development kit
opmentKit

*1: JDK=Java Development Kit

However, the following software already shall have been installed on the machine.
y Web browser :Internet Explorer 5.5 SP2

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial > 3-2

Installation of JDK1.1.8
The JDK1.1.8 software is downloaded from the Web site java.sun.com and is installed.
Run the downloaded file and install it following the instructions.

Installation of the FCN/FCJ Java Application Development Kit


The FCN/FCJ Java application development kit (type: NT755FJ) is the tool kit for
development and execution of FCN/FCJ applications on Windows machines, and it
includes the following four softwares. The FCN/FCJ Java application development kit is
stored on the FCN/FCJ software medium (type: NT203AJ).
y Class library
y Duolet monitor
y JEROS emulator
y Sample program and Project skeleton

Installation key code


A license is required for installation of the FCN/FCJ Java application development kit.
When you purchase a license, an order ID sheet with listed order ID and password will
be provided. Use this order ID and password to obtain a Installation key code from the
Web site of our company and install the FCN/FCJ Java application development kit.

Installation method
Set a CD-ROM of the FCN/FCJ software medium and start the installer by selecting
"Product software", "FCN/FCJ Java application development kit". Then install following
the installer instructions.
Table: Folders specified at the time of installation
Folder Explanation Default
Development Kit Folder for storage of the main body of this kit. It is composed C:\YOKOGAWA\FCN-
installation folder of folders for class libraries, documents, sample programs, etc. FCJ\JavaApDevelopmentKit
For the folder configuration, refer to the following
"Development Kit folder configuration after installation
completion".
JEROS emulator Folder for storage of the operation environment file for the C:\JEROS
operation environment JEROS emulator.
file installation folder For operation of the emulator, a folder named "JEROS" must
exist directly under the drive on which Windows is installed.
Accordingly, the default name for the folder should not be
changed, unless there are special reasons.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial > 3-3

Development kit folder configuration after installation completion


When the installation has been completed, the folders shown in the following figure is
created under the installation folder specified at the time of installation for the Java
Application Development Kit.

Install Folder
(Default = C:\YOKOGAWA\FCN-FCJ)\JavaApDevelopmentKit)
Lib

Document

Tool

Sample

Projcts

Template
Figure: Folder configuration for the FCN/FCJ Java Application Development Kit

Install Folder
Folder for storage of the development kit is specified at the time of installation. The
installer sets the name of this folder to the environment variable
SDCS_JAVAKIT_TOPDIR. This kit uses batch files for program compiling, file transfer,
etc., and these batch files refer to this environment variable.

Lib
Folder for storage of the class library for this kit.
When compiling a program without use of the batch files offered by this kit, specify the
Jar file under this folder in the environment variable CLASSPATH.

Document
Folder for storage of Online help, API references, and PDF files for this technical
information.

Tool
The program for batch transfer of files to FCN/FCJ (FcxRestore.exe), the batch file for
running Duolet monitor, and other development support tools are stored in this folder.

Sample
The sample programs explained in this technical information are stored in this sample in
the project folder format (explained later).

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial > 3-4

Projects
Folder consolidating several project folders (explained later). When creating a new
project folder, it should be created under this folder.

Template
Template for project folders. Template of batch files for compiling and transfer to
FCN/FCJ and template of program source files are stored in this folder.
Please copy this folder and use the copy when creating a new project folder.

Project folder
The unit for development of one Java application is called the project, and the folder for
storage of this project is called the project folder.
The following figure shows the configuration of the project folder created at the time of
installation.

Install Folder
Project
Projects
Template
CallJavac.bat

CallWinJade.bat
Ftp2Fcx.bat
src
Package1
Template.java

class

FtpWork
MNT
JEROS
Figure: Folder configuration in the project folder

The configuration of each folder and file under the project folder will be explained by
referring template folder.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial > 3-5

Project folder (Template)


The batch files (extension .bat) for compiling and transfer to FCN/FCJ are stored directly
under the project folder. Please modify and use these batch files when developing an
application.
The functions of each batch file and the required modification contents are explained in
the following table.
Table: Functions of each batch file and contents to be modified at the time of use
Batch file name Explanation Contents of the modification at the
time of use
CallJavac.bat Batch file for compiling a Java program. The Specify the folder names (package
environment variable CLASSPATH also is set names) under src folder.
internally.
CallWinJade.bat Batch file for starting the JEROS emulator. The
environment variable CLASSPATH also is set
internally.
Ftp2Fcx.bat Batch file for transfer to FCN/FCJ. • Specify the destination as FCN/FCJ
Compiled class files under the Class folder are host name or IP address.
converted to files in the Jar format, copied to • Specify the package name.
FtpWork, and transferred to the FCN/FCJ specified in • Specify the file name of the Jar file.
the batch file.

src
Folder for storage of the Java program source file (extension .java).
For Java, the created classes are categorized as a function called package. The source
file (Template.java) categorized as a package called "Package1" is provided under
template folder.
The following is the source file for Template.java.

Package pakage1;
Public class app
{
}

class
Folder for storage of the compiled result. When the batch file (CallJavac.bat) for
compiling is executed, the class file (extension .class) representing the compile result is
output to this folder or under.

FtpWork
Work folder for transfer of Java application files to FCN/FCJ.
When the batch file (Ftp2Fcx.bat) for file transfer is executed, the class files under Class
file are converted to Jar format and are copied to a suitable position under this folder.
If other original files such as parameter files are to be transferred at the same time, they
will be transferred to FCN/FCJ when they are placed under this folder.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial > 3-6

Method for creation of a new project


For creation of a new program, copy the Template project and change the name to a
suitable name.
Install Folder
Projects
Template
src
class

FtpWork

newProject Copy&Rename

src

class
FtpWork

Sample program usage


The sample programs are provided in the project format.
When the reference sample is to be run as it is, copy it to a location under Projects.
Install Folder
Sample
Mail
src
class

FtpWork
Copy
Projects
Mail

src

class
FtpWork

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-7

3.2 Programming Section


3.2.1 Development Flow
The development procedures for applications operating with the FCN/FCJ Java function
are explained.
The flow of the entire development is shown below. The procedures ranging from source
code creation to running and debugging in the emulation environment on a PC are
explained.

Source code creation

Compiling Work on a PC

Running and debugging on


the emulation environment

Running and debugging Work using a PC and a FCN/FCJ


on the actual machine

Figure: Development flow

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-8

3.2.2 FCN/FCJ Java Function


The FCN/FCJ Java applications run on a framework called JADE. JADE manages the
execution of Java applications called Duolets on the framework.
Accordingly, application development means Duolet creation.
Duolets are divided into DeviceDuolets of the event occurrence type and
ApplicationDuolets of the event driven type. DeviceDuolets are used mainly for
communication with the FCN/FCJ control functions operation of physical devices such
as communication with equipment on the network. It is defined as at logical event source
in addition to physical equipment. ApplicationDuolets perform application logic such as
calculation processing. Cooperation between Duolets uses an event mechanism (event
notification between Duolets) provided by JADE.
When an event has occurred for a DeviceDuolet, this is received by an
ApplicationDuolet, which handles it, notifies it to other ApplicationDuolets, and instructs
the DeviceDuolet about the next handling, etc.

JADE
Event
Application Device
Duolet Duolet
Action
Figure: JADE and Duolet

The substance of a Duolet is a program called a class. DeviceDuolet and


ApplicationDuolet inherit the Duolet, and user applications are defined as their sub
classes.

Duolet

ApplicationDuolet DeviceDuolet

User User
application application
Figure: ApplicationDuolet and DeviceDuolet

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-9

Duolet State
A Duolet has a state. Execution is controlled by JADE, and the state transits according
to creation, execution, stop, deletion, etc. The main state types are LOADED and
READY. LOADED indicates the state where the Duolet has been loaded to JADE, and
READY indicates the execution state. The state types other than LOADED and READY
are transitory state types.
NONE

UNLOAD LOAD

LOADED

STOP START

READY
Figure: Duolet state transition

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-10

3.2.3 Sleeper Creation


A sample for the simplest Duolet is created. This sample repeatedly receives an event
every 5 seconds from the periodic timer function and then sleeps for 2 seconds. As it
performs sleep processing, it is called a 'Sleeper'. A Sleeper outputs a message to the
system log when it receives an event from the timer and when the sleep ends.
The periodic timer function is provided by 'JEROS', the Java class library for FCN/FCJ.
This function is a DeviceDuolet called DevTimer. DevTimer is started automatically from
the system and can send EvDevTimer event objects periodically to an ApplicationDuolet.
When the ApplicationDuolet receives an event, the notificationCall() method is called.
The Sleeper describes this sleep processing.

JADE
EvDevTimer

Sleeper DevTimer

Figure: Relation between Sleeper and DevTimer.

At the time of Duolet start, the Sleeper makes an event occurrence request to DevTimer.
At the time of termination, it makes an event stop request.
At the time of start, the Duolet once transits to START state. As the start() method is
called at this time, an event occurrence request procedure is described here in the
Sleeper. In the same way, at the time of termination, Duolet transit to STOP state and
as the contents of the stop() method are processed, the event stop procedure is
described.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-11

Source Code
Sample code Sleeper.java

package jp.co.yokogawa.stardom.sample;
import jeros.ade.*;

/**
Sleeper: Sample program for Application Duolet
An event is received every 5 seconds from DevTimer, it sleeps
for 2 seconds when it receives the event.
*/
public class Sleeper extends ApplicationDuolet
{

/**
Event handling method
This method is called by event notification from DevTimer.
*/
public void notificationCall(EvObject ev) {
if(ev instanceof EvDevTimer){
// Output to the log
DevSysLog.logInfoMessage(this,"Notified...");
try {
// Sleep for 2 seconds
Thread.sleep(2000);
}catch(InterruptedException ex) {
DevSysLog.logErrorMessage(this,"Interrupted Exception" + ex ;
}
DevSysLog.logInfoMessage(this,"Done...");
} else {
// When an unexpected event has been received
DevSysLog.logErrorMessage(this,"Unexpected notification"+ ev);
}
return;
}

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-12
/**
Duolet start processing method
Specification for DevTimer to notify an event every 5 seconds
*/
public boolean start() {
try {
// Specification for event notification every 5 seconds
DevTimer.setNotify(this,5000);
} catch(IllegalArgumentException ex) {
DevSysLog.logErrorMessage(this,"IlligalParameter in start " +
ex);
return false;
} catch(NoMoreRequestException ex) {
DevSysLog.logErrorMessage(this,"NoMoreRequest in start " + ex);
return false;
}
return true;
}

/**
Duolet stop processing
Event notification is stopped.
*/
public boolean stop() {
// Stop event notification
DevTimer.resetNotify(this);
return true;
}
}

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-13

Project creation
Create a project for creation of a Sleeper program.
Normally, the Template folder under the Projects folder is copied and the name is
changed to Sleeper for use.
Install Folder
Projects
Template
src
class

FtpWork

newProject Copy&Rename

src

class
FtpWork
Figure: Normal method for project creation

Here, a sample program is used. As shown in the following figure, copy the Sleeper
folder under the Sample folder to the Projects folder and use it.
Install Folder
Sample
Sleeper
src
class

FtpWork
Copy
Projects
Sleeper

src

class
FtpWork
Figure: Copy of the Sleeper project

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-14

Modification of the source code


Modify the file Sleeper.java under Src under the copied Sleeper folder.
As the sample, a sleep time is 3 seconds, modify this to 2 seconds.

Figure: Modification of the source code

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-15

3.2.4 Compiling
Compiling is done with the compiling batch file CallJavac.bat directly under the project
folder.
Run the batch file CallJavac.bat directly under the copied Sleeper folder.
When compiling has been completed, the compiled class file Sleeper.class is created
under the Class folder of the Sleeper folder.

In case of a Compile Error


Compile errors can be caused by wrong the environment setting or code errors.
One cause for errors from wrong environment setting is wrong class path setting. In this
case, the following compile message is displayed. Please modify the class path setting.

Sleeper.java:3: Package jeros.ade not found in import.


import jeros.ade.*;
^

An error caused by a code error as shown below. Modify the respective location and
compile again.

Sleeper.java:27: '}' expected.


}
^

Supplement: When a compiler other than JDK1.1.8 is used


When Duolets are created with a compiler other than JDK1.1.8, the cross-compile option
has to be specified. For example, the command for Java2 SE 1.4 is as follows.

javac -target 1.1 -bootclasspath C:\jdk1.1.8\lib\classes.zip


Sleeper.java

For option details, refer to the compiler document.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-16

3.2.5 Operation Confirmation


The JEROS emulator (WinJade) is used for operation confirmation. WinJade is the
Duolet execution environment running on Windows.

Start of WinJade
WinJade is started with the WinJade start batch file CallWinJade.bat directly under the
project folder.
Run CallWinJade.bat directly under the copied Sleeper folder.
After start, the following screen is displayed.

Figure: WinJade

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-17

Duolet Loading
For operation of a Sleeper, the Sleeper must be loaded onto WinJade.
Select [Load Duolet...] from the [File] menu.

Figure: Duolet loading

Enter 'Sleeper1' as the Instance Name in the LOAD DUOLET dialog box and enter
'jp.co.yokogawa.stardom.sample.Sleeper' as the Class Name. On JADE, multiple
instances can be created from one Duolet. Each instance is identified by an Instance
Name. For this reason, the Instance Name must be unique.

Figure: Specification of instance name and class name

When [OK] is pressed, 'sleeper1' is loaded and the following window is displayed as
shown below. With this, the Sleeper has been loaded onto JADE. This can be confirmed
by the display of LOADED at the right below Sleeper1. This displays the Duolet state.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-18

Figure: Load completion for Sleeper1

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-19

Duolet Execution
When the state is LOAD, the Sleeper is not yet running. In order to run (execute) the
sleeper, it is necessary to change the Sleeper state to READY.

1. Click sleeper1.

Figure: Sleeper selection

2. Select [Start...] from the [Duolet] menu.

Figure: Start of Sleeper

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-20
When [OK] is clicked in the dialog box, the Sleeper starts and the following screen
appears. When the Sleeper is started, %Timer is loaded to the DeviceDuolet and is
executed. This is DevTimer.
The arrow from DevTimer to sleeper1 indicates "Duolet event notification", and timer
event notification with each timer period can be confirmed.

Figure: Events between Duolets

Operation confirmation
The log output is displayed in the 'LOG WINDOW'. Please confirm that messages are
displayed periodically according to the Sleeper operation.

Figure: LOG WINDOW

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-21

3.3 Actual Machine Operation Section


3.3.1 Sleeper Operation
The Sleeper example of the preceding section is used to explain the operation
sequence. The operation sequence on FCN/FCJ is shown in the following figure. In the
sleeper example, '192.168.50.10' is used as the IP address of FCN/FCJ in this
explanation.
Start FCN/FCJ in maintenance mode

Jar file creation and transfer to FCN/FCJ

AdditionalClassPath setting

Restart FCN/FCJ in online mode

Execution, debugging

Figure: FCN/FCJ operation flow

NOTE
For running a Java program on FCN/FCJ, "Use Java" must be checked on the Resource Configurator
(tool for basic setting/operation of FCN/FCJ, included with the basic software).

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-22

3.3.2 Start of FCN/FCJ in Maintenance Mode

Maintenance Mode
Restart FCN/FCJ in maintenance mode as preparation for transfer of the created Java
program to FCN/FCJ.
Open the FCN/FCJ maintenance homepage.
The URL of the maintenance homepage is the IP address/MNT/ of http://FCN(FCJ).
Open this URL with the browser.

The user name and the password at the time of connection are as follows.
y User name :stardom
y Password :YOKOGAWA

When the authentication is succeeded, the following screen is displayed.

Figure: Maintenance Page

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-23
When the [Maintenance Menu] link is clicked, the following page is displayed.
Click [Reboot].

Click [Reboot].

Figure: Maintenance Menu page

The Reboot FCX page appears. Select [Reboot (Maintenance Mode)] and click [OK].

Reboot (Maintenance Menu)

Figure: Reboot mode selection screen

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-24
When rebooting starts, the following screen appears.

Figure: Reboot screen

It takes some time until the maintenance mode starts. Look at the FCN/FCJ LED and
confirm the start in maintenance mode.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-25

3.3.3 Jar File Creation and Transfer to FCN/FCJ


To run a Java program on FCN/FCJ, the created Java program must be consolidated in
the JAR file format and must be transferred to FCN/FCJ. (A Jar file is an archive
consolidating the class files into a single file.)
Normally, Jar file is created and transferred to FCN/FCJ at command prompt, this
development kit provides a batch file for doing these in a batch.
In the following, explanations are given for using a batch file for Jar file creation and
transfer to FCN/FCJ and for doing these at the command prompt.

Jar file creation and transfer using a batch file


For Jar file creation and transfer by a batch file, run the batch file Ftp2Fcx.bat directly
under the project folder.
For use of this batch file, the IP address for FCN/FCJ in the batch file must be modified.

Modification of the batch file


Open Ftp2Fcx.bat directly under the Sleeper folder with Notepad etc.
Set the IP address of the transfer destination in the batch file to the actual FCN/FCJ IP
address (192.168.50.10 in this example).

Execution of the batch file


Execute Ftp2Fcx.bat directly under the Sleeper folder.
Confirm that the created Sleeper.class files are consolidated to a userjava.jar file and
are transferred to /JEROS/SYS/CLASSES/PJT of FCN/FCJ.

Jar file creation and transfer at the command prompt


The following two procedures are used for Jar file creation and transfer to FCN/FCJ at
the command prompt.

Jar file creation


Consolidate the Sleeper class files in a file called userjava.jar. Enter the following
command at command prompt after changing the Class folder under the copied Sleeper
folder to the current directory.

jar cvf userjava.jar jp\co\yokogawa\stardom\sample\Sleeper.class

When creating a JAR file, use the MS-DOS8.3 format (file name: 8 bytes, extension: 3
bytes (JAR)) for the file name.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-26

FTP transfer to FCN/FCJ


Here, explanations are made using the standard FTP command of Windows.

Log in with the FTP user name 'MNT' and the password 'duonusMNT'.

Enter IP address of FCJ/FCN.


> ftp 192.168.50.10
Connected to 192.168.50.10.
220 FCX STARDOM(FCJ-1) FTP server ready for maintenance
(JRS:R2.04.02).
User (192.168.50.10:(none)): MNT MNT
331 Password required for MNT.
Password: duonusMNT
230 User MNT logged in.

The file userjava.jar is transferred in binary mode to the folder


/JEROS/SYS/CLASSES/PJT.

Move to /JEROS/SYS/CLASSES/PJT
ftp> cd sys/classes/pjt
250 Changed directory to "/JEROS/SYS/CLASSES/PJT".
ftp> bin
Binary mode
200 Type set to I, binary mode.
ftp> put userjava.jar
Transfer userjava.jar.
200 Port set okay.
150 Opening BINARY mode data connection for
/JEROS/SYS/CLASSES/PJT/USERJAVA.JAR
(192.168.50.1,1220).
226 Transfer complete.
ftp: 7945 bytes sent in 0.03Seconds 264.83Kbytes/sec.
ftp> quit
End of FTP
221 Bye...see you later.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-27

3.3.4 AdditionalClassPath Setting


When a Jar file has been transferred to FCN/FCJ, the transferred Jar file must be set in
AdditionalClassPath of the JEROS basic setting file of FCN/FCJ.

Select the [Maintenance Homepage] link on the Reboot page.

Maintenance Homepage

Figure: Reboot page

The Maintenance Page is displayed. Click [OK].

OK

Figure: Maintenance Page

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-28
Open the Maintenance Menu screen of FCN/FCJ. Click the [Edit] link.

Figure: Maintenance Menu Page

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-29
Select [JEROS Basic Setting File] and click [OK].

Figure: Edit System Setting Files page

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-30
Add the path of the transferred Jar file to the AdditionalClassPath.
Add a colon (:) after AdditionalClassPath =/JEROS/SYS/CLASSES/STARDOM.JAR and
set the path of the added Jar file.
y AdditionalClassPath =/JEROS/SYS/CLASSES/STARDOM.JAR:/JEROS/SYS/CLAS
SES/PJT/USERJAVA.JAR

Figure: Change of the setting file

Click [OK].

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-31

3.3.5 Restart in Online Mode


When AdditionalClassPath setting has been completed, reboot FCN/FCJ from
maintenance mode to online mode.

Select the [Reboot] link on the FCX Maintenance Menu page. The Reboot FCX page is
displayed. Select [Reboot (Online Mode)] and click [OK].

Reboot
(Online Mode)

Figure: Reboot mode selection screen

The following screen is displayed and FCJ/FCN is rebooted.

Figure: Reboot screen

Starting in online mode takes some time. Look at the FCN/FCJ LEDs to confirm that
start in online mode has been performed (HRDY: Lit, RDY: Lit, CTRL: Not lit).

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-32

3.3.6 Duolet Execution

Connection to FCN/FCJ
The Duolet Monitor is used to execute a Duolet on FCJ/FCN. Duolet Monitor is a tool for
monitoring the operation status of a Duolet on FCN/FCJ.
Start Duolet monitor from the Start menu by [Programs] - [YOKOGWA FCN-FCJ] -
Duolet Monitor].

The following screen is displayed when the Duolet Monitor is started.

Figure: Duolet Monitor

For connection to FCN/FCJ, select [Connection...] from the Duolet Monitor [File] menu.

Figure: Connection to FCN/FCJ

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-33
The CONNECT TARGET dialog is displayed. Enter the IP address (192.168.50.10) of
the connection destination FCJ/FCN for [System Name] and click [Connect].

Figure: CONNECT TARGET dialog

The following is displayed when the connection is started.

Figure: Connecting

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-34
The following screen is displayed when the connection has been completed.

Figure: Connection completion

NOTE
When an error has occurred at the time of connection:
The following error screen may be displayed at the time of connection. This error occurs when the host
name specified in the JEROS basic setting file (DUONUS.PRP) does not match the name specified for
[System Name] in the [Connect Target] dialog.
For example, the default host name for FCJ is 'FCX', but when connection is made with specification of
192.168.50.10 as the IP address, as in the case of the example, an error message is displayed
because FCX and 192.168.50.10 are not the same. In this case, edit the JEROS basic setting file to
change the host name to 192.168.50.10, or set the host name so that 'FCX' is recognized as the IP
address (192.168.50.10) and use FCX as the system name at the time of connection.

Figure: Error message

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-35

Sleeper Execution
In the same way as in the debugging section, the Sleeper must be loaded for execution
of the Sleeper.
Select [Load Duolet...] from the [File] menu.
Then enter the following at the LOAD DUOLET dialog.
y Instance Name :sleeper1
y Class Name :jp.co.yokogawa.stardom.sample.Sleeper

Figure: Specification of instance name and class name

For execution of the Sleeper, select sleeper1 and select [Start...] from the [Duolet] menu.

Figure: Sleeper execution

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-36
Confirm the Sleeper operation in the LOG WINDOW of the Duolet Monitor.

Figure: LOG WINDOW

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-37

Supplement: Start of the Sleeper at the time of start of FCN/FCJ


The procedure for automatic start of the Sleeper after the start of FCN/FCJ is explained.

1. Reboot in maintenance mode and open the maintenance page.


Open the [Edit] link.

Figure: Maintenance page

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-38
2. Select [Duolet Loader Configuration File] and click [OK].

Figure: Edit System Setting Files page

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-39
3. Add the Sleeper setting.
Specify the class name and the instance name after Duolet2.
Use the following notation for the Sleeper.
y Duolet2=jp.co.yokogawa.stardom.sample.Sleeper,sleeper1

Figure: Setting file change

4. Click [OK].
5. Reboot in online mode.

Use Duolet Monitor for operation confirmation. Confirm that the Sleeper runs after
rebooting.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-40

3.4 Mail Examples


This section explains the procedures for creating sample applications for the e-
mail send/receive function.

3.4.1 Mail Replyer Creation


Creation of the Duolet 'MailReplyer' for send/receive e-mail is described.
In the MailReplyer example, the e-mail server and the e-mail address are as follows.
y E-mail address used by the Duolet : duolet@stardom.jp
y User e-mail address : stardom_user@stardom.jp
y SMTP server : smtp_server(IP address:192.168.10.1)
y POP3 server : pop3_server(IP address:192.168.10.2)

When the user sends an e-mail to duolet@stardom.jp, the MailReplyer receives the e-
mail. The MailReplyer checks the e-mail sender addressee and reply the contents as
they are to the sender addressee. The subject becomes the subject of the original e-
mail, preceded by 'Re:'.

E-Mail server (POP3,SMTP)


Sends e-mail to
Receive e-mail duolet@stardom.jp

FCN(FCJ)
User
MailReplyer Reply e-mail Receive the (stardom_user@
stardom.jp)
reply e-mail

Create a reply e-mail


to the address
stardom_user@stardom.jp

Figure: MailReplyer

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-41

3.4.2 Mail Function


The DeviceDuolet DevMail provided by JEROS is used to send and receive e-mail.
DevMail periodically confirms e-mail arrival at the POP3 server. When e-mail arrives,
DevMail sends a received notification event. When MailReplyer receives this received
notification, it creates a reply. The created reply is sent via DevMail to the SMTP server.

3: Reply mail
2: Reception JADE 1: Periodic reception
creation
notification of mail (POP3) POP3 server
MailReplyer DevMail
SMTP server
4: Mail sending 5: Mail sending
(SMTP)
Figure: MailReplyer operation

MailReplyer receives an event from DevMail. As this is an event driven type, this
MailReplyer must be ApplicationDuolet. As the received notification event request and
stop are made at the time of Duolet start and stop, they must be described in start() and
stop().

E-mail to a Duolet adds the information required for sending the e-mail to the desired
Duolet as the 'Duolet extended header' to the body of the e-mail.
MailReplyer uses the item 'DataName' in the Duolet extended header. MailReplyer
checks the value of DataName and receives only e-mail with the same value. The
notation for the items in the Duolet extended header is 'item name = value'. The Duolet
extended header and the normal body of the e-mail are separated by one space.
An example for the body of an e-mail sent to MailReplyer is shown below.

DataName=sample

Hello, Duolet!

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-42

Source Code
The MailReplyer source code is shown below.

MailReplyer.java

package jp.co.yokogawa.stardom.sample;

import jeros.ade.*;
import jeros.ade.mail.*;
import java.util.Date;

/**
jp.co.yokogawa.stardom.sample.MailReplyer

Repling a mail example


*/
public class MailReplyer extends ApplicationDuolet{
private static final String DATA_NAME = "sample";

/**
Event handler
*/
public void notificationCall(EvObject ev){
if (ev instanceof EvDevMail){
DevSysLog.logInfoMessage(this,"Notified ... ");

EvDevMail mail = (EvDevMail)ev;

try{
String to = mail.getReplyToAddress(true);
if (to == null){
to = mail.getFromAddress(true);
}

String subject = "Re: " + mail.getSubject();


String body = mail.getAllText();

DevSysLog.logInfoMessage(this,"Sending Mail ... ");

DevSysLog.logInfoMessage(this,to);
DevSysLog.logInfoMessage(this,subject);
DevSysLog.logInfoMessage(this,body);

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-43

DevMail.sendMessage(this,to,subject,body);
DevSysLog.logInfoMessage(this,"Done");
}catch(MailException ex){
DevSysLog.logErrorMessage(this,"Mail Exception in
notificationCall: "+ ex);
}

}else{
DevSysLog.logErrorMessage(this,"Unexpected "+ ev);
}
return;
}

/**
Staring process
*/
public boolean start(){
try{
DevMail.setNotify(this,DATA_NAME,false);
DevMail.startSender();
DevMail.startReceiver();
}catch(MailException ex){
evSysLog.logErrorMessage(this,"Mail Exception in start: " + ex);
return false;
}
return true;
}

/**
Stopping process
*/
public boolean stop(){
try{
DevMail.resetNotify(this,DATA_NAME,false);
}catch(MailException ex){
DevSysLog.logErrorMessage(this,"Mail Exception in stop: " + ex);
return false;
}
return true;
}
}

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-44

3.4.3 Compile and File Transfer


The procedure for compile and transfer is shown.

Copy the MailReplyer folder under the Sample folder to the Projects folder.
Confirm the contents of the MailReplyer.java file under the src folder under the copied
MailReplyer folder.
Execute CallJavac.bat directly under the MailReplyer folder and compile the
MailReplyer.

Consolidate the compiled class files in a Jar file and transfer this file to FCN/FCJ.
The procedure is as shown below.
1. Change to maintenance mode
2. Open Ftp2Fcx.bat directly under the MailReplyer folder with Notepad etc. and
modify the destination FCN/FCJ IP address.
3. Execute Ftp2Fcx.bat for Jar file creation and transfer to FCN/FCJ.
4. Add userjava.jar to AdditionalClassPath of the "JEROS Basic Setting File".
5. Change to online mode

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-45

3.4.4 E-mail Function Setting


Sending e-mail requires setting of the SMTP server and setting of the user name to
which the e-mail is to be sent. Setting is done in the e-mail configuration file
(DEVMAIL.PRP).
Also, set the host name definition file (HOSTS) for correspondence between host name
and IP address.
In the sample, the following setting is done.
y SMTP server :smtp_server(IP address:192.168.10.1)
y POP3 server :pop3_server(IP address:192.168.10.2)
y POP3 user name :duolet
y POP3 user’s domain name :stardom.jp
y POP3 password :passwd
y E-mail receiving period :1 minute
y E-mail sending period :1 minute

Rebooting in Maintenance Mode


FCN/FCJ must be rebooted in maintenance mode to change the setting file.
1. Start the browser and open the Maintenance Page (IP address /MNT/ of
http://FCN(FCJ)).
2. Click [Reboot (Maintenance Mode)] from the Reboot page.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-46

Setting File Editing


Editing is done according to the following procedures.
1. Confirm completion of rebooting with the FCN/FCJ LED.
2. Click the link of the [Maintenance Homepage].

Figure: Reboot page

3. Click [OK].

Figure: Maintenance page

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-47
4. Click the [Edit] link.

Figure: FCX Maintenance Menu page

5. Select [E-Mail Configuration File] and click [OK].

Figure: FCX Maintenance Menu page

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-48
6. The editing screen for the mail setting file appears.

Figure: Editing screen for the mail setting file appears.

The notation in the setting file is divided into sections for each function.
(As the default is commented out, please delete the "#" symbol.)
Change the following location in the [General Settings] section.
y PopUser=duolet

Change the following locations in the [Setting Items for Sending Mails] section.
y SmtpServer=smtp_server
y Domain=stardom.jp
y TrueName=Duolet
y SendCycle=1

Change the following locations in the [Setting Items for Receiving Mails] section.
y PopPassword=passwd
y PopServer= pop3_server
y RecvCycle=1

7. After the changes have been completed, click [OK].


8. Return with [Back] to the page for selection of the system setting file, select
[HOSTS File], and click [OK].

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-49
9. The editing screen for the host name definition file appears.

Figure: Editing screen for the host name definition file

Add the following two lines to the final line of this file.
192.168.10.1 smtp_server
192.168.10.2 pop3_server

10. After the changes have been completed, click [OK].


11. Use [Maintenance Menu] to return to the Maintenance Menu page.
12. Select [Reboot (Online Mode)] on Reboot page and return to online mode.

The above procedures complete the editing of the setting file.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-50

3.4.5 Execution and Operation Confirmation


Execute MailReplyer on FCN/FCJ. The procedures are as follows.
1. Run Duolet monitor from the Start menu.
2. Load MailReplyer.
y Instance name : replyer1
y Class name : jp.co.yokogawa.stardom.sample.MailReplyer
3. Select replyer1 and start.

Operation Confirmation
Send e-mail to MailReplyer to confirm reply e-mail.
Mail is sent according to the following contents.
y Address : duolet@stardom.jp
y Return address : stardom_user@stardom.jp
y Subject : Hello!

The body of the e-mail has the following contents.

DataName=sample

Hello, duolet!

Figure: Mail to MailReplyer

NOTE
The FCN/FCJ function is compatible only with mail in the TEXT format. Be sure to send mail in TEXT
format, as this function is not compatible with the HTML format etc.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-51
Please confirm that the mail has been sent properly. The following e-mail is replied soon.
The replied e-mail includes the header information of the sent e-mail in the body of the
e-mail.

Figure: Return contents

NOTE
The default for the FCN/FCJ Java execution environment corresponds to English. When Japanese is
used in the e-mail contents, the Java start parameters must be modified.
When Japanese is used in the e-mail contents, modify the following part of the JEROS basic setting file
(DUONUS.PRP).
Before modification: JavaStart=jeros.ade.SystemManager /JEROS/CONF/SYS/JADE.PRP
After modification: JavaStart=-Duser.language=ja -Duser.region=JP -Dfile.encoding=SJIS jeros.ade.Sys
temManager /JEROS/CONF/SYS/JADE.PRP

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-52

3.5 FTP Examples


This section explains the creation procedure for applications using the FTP client
function.

3.5.1 Creation of PeriodicCopy


The creation of a Duolet using the FTP client function is explained.
The sample Duolet gets a file from the FTP server and transfers the file to a different
directory of the same FTP server. As this processing is repeated every hour, this is
called 'PeriodicCopy'.

The FTP server name etc. in the PeriodicCopy example are as follows.
y FTP server name : ftp_server(IP address:192.168.10.3)
y FTP user name : stardom
y FTP password : YOKOGAWA
y Acquired source file : /data.txt
y Write destination file : /copy/data.txt

PeriodicCopy receives an event from the periodic timer DevTimer every hour and gets
the data.txt file. The acquired contents are written to /copy/data.txt.

FTP
JAD
2: Get
"/data txt"
PeriodicCo
p
1 Even 3: Write to
"/copy/data.txt".
DevTimer

Figure: Operation of PeriodicCopy

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-53

Code Creation
For access to the FTP server, an object of the FtpClient class provided by JEROS is
created. The server name, the user name, and the password are specified as the
Constructor arguments.

FtpClient client = new FtpClient("ftp_server","stardom","YOKOGAWA",);

The get method is called to get a file. The file name and the transfer mode are specified
as arguments. The transfer mode is made true for ASCII and false for binary. The
acquired file is stored in a byte-type array of the return value of the get method.

byte[] data = client.get("data.txt",false);

The chdir method is used to change the directory. The argument is the directory name.

client.chdir("/copy");

The put method is used to write the file. The data of the byte array type, the write
destination file name, and the transfer mode are specified as the arguments.

client.put(data,"data.txt",false);

Supplement: When the file acquired from the FTP server is stored on
the FCN/FCJ system card
It is possible to save the data directly from the FTP server to a file instead of storing the
file data in the byte array.
In this case, the arguments of the get method become as follows.

client.get ("file name on the FTP server", "file name on FCJ",


false);

It is also possible to send a file on FCN/FCJ as it is to the FTP server. This becomes as
shown below.

client.put ("file name on FCJ", "file name on the FTP server".


false);

For details, refer to the FtpClient item in the 'JEROS API reference' of the online
document.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-54

Source Code
PeriodicCopy.java

package jp.co.yokogawa.stardom.sample;

import jeros.ade.*;
import jeros.ftp.FtpClient;
import jeros.ftp.FtpException;
import java.util.Date;

/**
jp.co.yokogawa.stardom.sample.PeriodicCopy

FTP sample
*/
public class PeriodicCopy extends ApplicationDuolet
{
private static final int COPY_PERIOD = 3600000;

/**
Event Handler
*/
public void notificationCall(EvObject ev) {
if(ev instanceof EvDevTimer) {
try {
DevSysLog.logInfoMessage(this,"Notified... ");

String serverName = "ftp_server";


String userName = "stardom";
String password = "YOKOGAWA";
String fileName = "data.txt";

FtpClient ftp = new FtpClient(serverName,userName,password);


byte[] fileData = ftp.get(fileName,false);
ftp.chdir("/copy");
ftp.put(fileData,fileName,false);
ftp.close();

DevSysLog.logInfoMessage(this,"Done");
} catch(FtpException ex) {
DevSysLog.logErrorMessage(this,"Error "+ ex);
}

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-55
} else {
DevSysLog.logErrorMessage(this,"Unexpected "+ ev);
}
return;
}

/**
Starting Process
*/
public boolean start() {
try {
DevTimer.setNotify(this,COPY_PERIOD);
} catch(IllegalArgumentException e) {
DevSysLog.logErrorMessage(this,"IlligalParam in start");
return false;
} catch(NoMoreRequestException e) {
DevSysLog.logErrorMessage(this,"NoMore");
return false;
}
return true;
}

/**
Stopping Process
*/
public boolean stop() {
DevTimer.resetNotify(this);
return true;
}
}

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-56

3.5.2 Execution and Operation Confirmation

Execution Preparation
Copy the PeriodicCopy folder under the Sample folder to the Projects folder.
Compile the PeriodicCopy.java and transfer it to FCN/FCJ.
Modify the host name definition file and set the IP address of the FTP server.
Modify data.txt as the acquisition source file on the FTP server. Also create the directory
/copy as the write destination. Please note that an error message (FtpException) will
occur at the time of execution when these files and/or directories do not exist.

Execution
Load PeriodicCopy with copy1 as the instance name. After loading, execute copy1.

Operation Confirmation
Confirm that the file on the FTP server is copied every hour from /data.txt to
/copy/data.txt.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-57

3.6 Examples for the Control Data Access Class


The control data access class is the class library for accessing data of the control
function on FCN/FCJ from a Duolet. This section explains examples for this
control data access.

3.6.1 Reverser Creation


FCJ is used for the samples of this section. The explanations apply for 192.168.50.10 as
the IP address of FCJ.
Reverser reads data from the digital input (DI) of FCJ and performs reversed output of
DI to the digital output (DO). At the same time, the result is written to the log.
I/O operation is processed by a DeviceDuolet subclass. As I/O operation is performed,
this is called 'IOHandler'. Instructions to IOHandler, DI reversal, and writing to the log are
processed by an ApplicationDuolet sub class. As reversal processing is done, this is
called Reverser. These two Duolets are used to realize reversed output and display
processing.
The DI status is confirmed periodically. In the sample, this period is 5 seconds. The 5-
second periodic timer uses DevTimer. The Reverser is driven by the timer events from
DevTimer.

4:Calculation of
the DO value 2:DI value 3:DI value
acquisition acquisition
Data access
Reverser IOHandler API
5:DO value 6:DO output
setting
1:Timer event

DevTimer

Figure: Reverser operation

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-58

3.6.2 Device Label


The I/O of FCJ are 6 points of AI, 2 points of AO, 16 points of DI, and 16 points of DO.
These I/O points are operated from the control application or from a Java application by
specifying a 'Device label'.
The device label is the name for each I/O point. The default names for DI are I_D_01,
I_D_02 ... I_D_06. Each I/O device label is confirmed by the resource configurator.

Figure: Device label confirmation

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-59

3.6.3 Definition of the Device Label Variable


Each I/O has a device label. For operating this from a Java application, a variable is
assigned to a device label. This variable is called a device label variable.
LogicDesigner is used to define device label variables.

The following device label variables are defined for samples.


y DI:I_D_01
y DO:O_D_17

1. Start LogicDesigner.
2. Select [New Project] from the [File] menu.
3. Select 'STARDOM FCX' and click [OK].

Figure: Selection of a new project

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-60
4. Double-click [DeviceLabelDefinition].

Figure: Display of the device label variable

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-61
5. The device label variable definition dialog is displayed.
Add the following items.

Device label name Signal type Task


I_D_01 I_Sts Task1
O_D_17 O_Sts Task1
(When only Task0 can be selected by task specification, specify Task0.)

Figure: Device label variable definition

Click [OK] after the addition has been completed.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-62
The OPC check of the device label variable must be set to ON to access control data
variables from the FCN/FCJ Java function.
1. Double-click Global_Variables and display the following table.
2. Check the OPC item for I_D_01_BOOL and O_D_17_BOOL in the table.
DI has two variables I_D_01 and I_D_01_BOOL. As reference to the boolean type is
made with the Duolet, OPC is checked for I_D_01_BOOL. The same applies for
DO.

Figure: Variable worksheet of LogicDesigner

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-63
The project must be built to make the device label variable effective.
1. Set the IP address 192.168.50.10 of FCJ to the target (TargetSetting).

Figure: IP address setting

2. Save the project.


Use c:\YOKOGAWA\FCN-FCJ\LogicDesigner\Projects\Reverser as the file name.
3. Select [Make] from the [Build] menu and build the control application.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-64

3.6.4 Code Creation

Control Data Access Library


The CSDCSAppDataAccess class is used to access data on the control function.
The ReadVarDate method is used to read out values. The arguments are the vector
which stores the device label variable name array and the value, and the array for error
storage. The return value is the error status.
When the device label variable name specified from the side of the FCN/FCJ Java
function is I_D_01_BOOL, the variable name is '@GV.I_D_01_BOOL'. A list of the
device label variable names which can be specified at FCN/FCJ Java function is output
to the following file.

C:\YOKOGAWA\FCN-
FCJ\LogicDesigner\Projects\reverser\C\Configuration\R\FCX01\ADLST.csv

String[] deviceLabels = {"@GV.I_D_01_BOOL"};


Vector varData = new Vector();
long[]errors = new long[1]; // ReadVarData error code
errors[0] = 0;

CSDCSAppDataAccess access = new CSDCSAppDataAccess();


long lRet = access.ReadVarData(deviceLabels,varData, errors);

After data acquisition, the elements are taken out from the vector. The DI data values
are acquired as a boolean type. For a boolean type, the notation is as follows.

CSDCSBool dataVal = (CSDCSBool)(varData.elementAt(0));

WriteVarData is used to write the value. The arguments are the array of the device label
variable name, the vector of the value to be written, and the array for error storage. In
case of DO data, an object with a boolean value entered for CSDCSBoolValue is stored
in the array.
The return value is the error status.

String[] deviceLabels = {"@GV.O_D_17_BOOL"};


Vector varData = new Vector();
long[] errors = new long[1]; // ReadVarData error code
errors[0] = 0;
varData.addElement(new CSDCSBoolVal(value));

CSDCSAppDataAccess access = new CSDCSAppDataAccess();


long lRet = access.WriteVarData(deviceLabels,varData, errors);

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-65

Duolet Loading and Unloading


Two Duolets are used in the sample. This requires IOHandler load processing from
Reverser. The loadDuolet method of the DuoletManager class is used for this
processing.

DuoletManager.loadDuolt("Duolet class name",'Duolet instance


name")

The load processing is performed when Reverser starts. Unload processing is


performed when Reverser ends.
The unloadDuolet method is used for unloading.

DuoletManager.unloadDuolt(Duolet instance)

Supplement
Class for array data access:
The array data access class is used for access to large-volume control applications. The details are
explained in the section for the creation of combined applications in this tutorial.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-66

Source Code
The source code for Reverser and IOHandler is shown in the following.

Reverser.java

package jp.co.yokogawa.stardom.sample;

import jeros.ade.*;
import java.io.IOException;

/**
jp.co.yokogawa.stardom.sample.Reverser

I/O sample
*/
public class Reverser extends ApplicationDuolet
{
private IOHandler handler;

/**
Event Handler
*/
public void notificationCall(EvObject ev) {
if(ev instanceof EvDevTimer) {
try {
DevSysLog.logInfoMessage(this,"Notified... ");

// reverse output
boolean diValue = handler.readDI();
DevSysLog.logInfoMessage(this,"DI : "+ diValue);

boolean doValue = !diValue;


DevSysLog.logInfoMessage(this,"DO : "+ doValue);

handler.writeDO(doValue);

DevSysLog.logInfoMessage(this,"Done");
} catch(IOException ex) {
DevSysLog.logErrorMessage(this,"Error "+ ex.getMessage());
}
} else {
DevSysLog.logErrorMessage(this,"Unexpected "+ ev);

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-67
}
return;
}
/**
Starting Duolet
*/
public boolean start() {
try {
// load duolet
handler =(IOHandler)DuoletManager.loadDuolet("jp.co.
yokogawa.stardom.sample.IOHandler","IOHandler1");
DuoletManager.startDuolet(handler);
DevTimer.setNotify(this,5000);
} catch(Exception ex) {
DevSysLog.logErrorMessage(this,ex.getMessage());
return false;
}
return true;
}

/**
Stopping Duolet
*/
public boolean stop() {
try{
// unload duolet
DuoletManager.stopDuolet(handler);
DuoletManager.unloadDuolet(handler);
}catch(DuoletControlException ex){
DevSysLog.logErrorMessage(this,ex.getMessage());
return false;
}
DevTimer.resetNotify(this);
return true;
}
}

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-68
IOHandler.java

package jp.co.yokogawa.stardom.sample;

import jeros.ade.*;
import jp.co.yokogawa.stardom.dataaccess.*;
import java.util.Vector;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

/**
jp.co.yokogawa.stardom.sample.IOHandler

I/O sample
*/
public class IOHandler extends DeviceDuolet
{
// Device Label Variable names
private String diTags[] = {"@GV.I_D_01_BOOL"};
private String doTags[] = {"@GV.O_D_17_BOOL"};

// Data access object


private CSDCSAppDataAccess access = new CSDCSAppDataAccess();
private Vector varData = new Vector();
private long[] errors = new long[1];

/**
Read DI
Exception : java.io.IOException
*/
public boolean readDI() throws IOException{
errors[0] = 0;

long status=0;
try{
// read DI
status = access.ReadVarData(diTags,varData,errors);
}catch(Exception ex){
throw new IOException("readDI() Not_Succes " +
ex.getMessage());
}

// check status

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-69
if(status != CSDCSAppDataAccess.S_SUCCEED || errors[0] != 0)
{
throw new IOException("readDI() Not_Succes errors[0]=" + errors[0]);
}

CSDCSBool dataVal = (CSDCSBool)(varData.elementAt(0));


return dataVal.getVal();
}

/**
Write DO
Exception : java.io.IOException
*/
public void writeDO(boolean value) throws IOException{
varData.removeAllElements();
varData.addElement(new CSDCSBoolVal(value));
errors[0] = 0;

long status = 0;
try{
// read Write
status = access.WriteVarData(doTags,varData,errors);
}catch(java.io.UnsupportedEncodingException ex){
throw new IOException("writeDO() Not_Succes " +
ex.getMessage());
}

// check status
if(status != CSDCSAppDataAccess.S_SUCCEED || errors[0] != 0) {
throw new IOException("writeDO() Not_Succes errors[0]
=" + errors[0]);
}
}
}

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-70

3.6.5 Execution
Copy the Reverser folder under the Sample folder to the Projects folder.
Compile the Duolet according to the normal procedure and transfer it to FCJ.
The control application must be downloaded before Duolet execution.
1. Start LogicDesigner.
2. For loading to FCJ, select [Project Control] from the [Online] menu.
3. The following dialog boxes are displayed.
Click [Download].

Figure: Project control dialog

4. Click [Download] of Project in the following dialog boxes.

Figure: Download dialog

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-71
5. Click [Cold] to execute the control application.

Figure: Project control dialog

The above completes the execution of the control application.


Next, use Duolet Monitor to load Reverser.

Operation Confirmation
Execute Reverser and confirm the operation. Confirm that DO becomes the reversed
output of DI. Also confirm that the value is displayed in the LOG WINDOW.

NOTE
The JEROS emulator (WinJade) is not compatible with the control data access class. Please test
Duolets using the control data access class on FCN/FCJ.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-72

3.7 Creation of Combined Applications


This section explains the creation of applications combining the e-mail function,
the FTP function, and the control data access function.

3.7.1 Application Outline


An application logging the analog input (AI) value is created.
The AI value is read every minute and the data is saved in a log file on FCJ. When data
have been acquired for one hour, the log file is transferred to the FTP server. At the
same time, e-mail notifying that the log has been completed is sent. The log file is a
comma-delimited type with the three items of time, data name, and value.

The logging application is created using two Duolets, DeviceDuolet and


ApplicationDuolet. Reading of AI values is handled by a DeviceDuolet. The name is
'AnalogReader'. Log creation, transfer to the FTP server, and notification by e-mail is
handled by an ApplicationDuolet. The name is 'Logger'.
The application operation is shown below.

2.1:Value
DevMail
acquisition
2.2:File
1.3:Value
transmission 1.2:Value acquisition
acquisition Data
FTP AnalogReade
Logger access API
function

1.4:Log 1.1:Periodic
creation 1 min timer DevTime

Figure: Logger operation

Log Output Destination


The log output destination file names are shown below.
y On FCJ /JEROS/USERS/PJT/anlg_dat.csv
y On the FTP server (FTP root)/sample/anlg_dat.csv

In this sample, the settings for the FTP server and the e-mail server are as follows.
y FTP server :ftp_server(IP address:192.168.10.3)
y FTP user :stardom
y FTP password :YOKOGAWA
y SMTP server :smtp_server(IP address:192.168.10.1)
y E-mail destination :stardom_user@stardom.jp

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-73

3.7.2 Preparing the Control application


Control application is required to read out AI values.
The control application of the sample stores the AI value in a UINT-type array. The UINT-
type array is a data type defined in the control application. The FCN/FCJ Java function
side can refer to it as an int-type array.
The number of elements of a UINT-type array is one, and it is defined as a global
variable. The variable name is A_IN. It becomes '@GV.A_IN' with reference from the
Duolet side.

Figure: Control application for storing an AI value in an array

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-74

3.7.3 Code Creation


The array data access class is used to read out AI. In this sample, only the data of one
AI point are read in, but when large-volume data are read from the control application,
the data can be handled efficiently by using array.
The ReadVarArvData method of the CSDCSAryAppDataAccess class is used for access
to array data.
The arguments are the variable name array, the vector storing the read-in value, the
vector storing CSDCSADLSTInfo, and the array storing errors. The return value is the
error status.
The use method is shown below.

String[] varNames = {"@GV.A_IN"};


Vector data = new Vector();
Vector info = new Vector();
long[] lError = new long[vecTag.size()];

CSDCSAryAppDataAccess Access = new CSDCSAryAppDataAccess();


long lRet = Access.ReadVarAryData(varNames,data,info,lError);

Source Code
The code of Logger and AnalogReader is shown below.

Logger.java

package jp.co.yokogawa.stardom.sample;

import jeros.ade.*;
import jeros.ade.mail.*;
import jeros.ftp.*;

import java.io.*;
import java.util.Date;

/**
jp.co.yokogawa.stardom.sample.Logger

Sample for a logging application


*/
public class Logger extends ApplicationDuolet
{
//private static final int DATA_COUNT = 10;
private static final int DATA_COUNT = 60;
//private static final int READ_PERIOD = 6000;
private static final int READ_PERIOD = 60000;

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-75

private static final String LOG_FILE_NAME = "ANLG_DAT.CSV";


private static final String LOG_FILE_DIR = "/JEROS/USERS/PJT";

private int count;


private AnalogReader reader;

/**
log writing
*/
private void writeLog(String data){
//DateFormat timeFormatter = DateFormat.getTimeInstance();
//String line = timeFormatter.format(Calendar.getInstance().getTime())
String line = new Date() + " , " + "A_IN_0" + " , "+ data;

DevSysLog.logInfoMessage(this,"write log : " + line);

try{
PrintWriter writer = new PrintWriter(new
FileWriter(LOG_FILE_DIR+"/"+LOG_FILE_NAME,true));
writer.println(line);
writer.close();
}catch(IOException ex){
DevSysLog.logErrorMessage(this,"File write error :"+
ex.getMessage());
}
}

/**
Preparation of a new file
*/
private void newFile(){
// Directory creation
File dir = new File (LOG_FILE_DIR);
if (!dir.exists()){
dir.mkdirs();
}

// Create new a file


File file = new File (LOG_FILE_DIR + "/" + LOG_FILE_NAME);
if (file.exists()){
file.delete();
}

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-76
}

/**
Sending e-mail to stardom_user@stardom.jp
*/
private void sendMail(){
String to = "stardom_user@stardom.jp";
String subject = "FCJ report";
String body = "Logging data is modified at " + new Date();

DevSysLog.logInfoMessage(this,"Mail sending");
try{
DevMail.sendMessage(this,to,subject,body);
}catch(MailException ex){
DevSysLog.logErrorMessage(this,"Mail Exception in notificationCall: "+ ex);
}
}

/**
Sending the log file to ftp_server
*/
private void putFile(){
FtpClient ftp = null;

String serverName = "192.168.50.1";


//String serverName = "ftp_server";
String userName = "stardom";
String password = "YOKOGAWA";
String fileName = "ANLG_DAT.CSV";

DevSysLog.logInfoMessage(this,"File transfer");
try {
ftp = new FtpClient(serverName,userName,password);
ftp.chdir("/SAMPLE");
ftp.put(LOG_FILE_DIR + "/" + LOG_FILE_NAME,LOG_FILE_NAME,true);
} catch(FtpException ex) {
DevSysLog.logErrorMessage(this,"FTP Error "+ ex);
}finally{
try{
if(ftp != null) {
ftp.close();
}
}catch(FtpException ex){

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-77
DevSysLog.logErrorMessage(this,"Closing FTP connection failed. "+ ex);
}
}
}

/**
Receiving an event
*/
public void notificationCall(EvObject ev) {
if(ev instanceof EvDevTimer) {
count ++;
if (count == 1){
newFile();
}

// AI reading
String dataText = null;
try {
dataText = String.valueOf(reader.read());
}catch(IOException ex){
DevSysLog.logErrorMessage(this,ex.getMessage());
dataText="Read_Error";
}

// log writing
writeLog(dataText);

if (count == DATA_COUNT){
// Processing every hour
putFile();
sendMail();
count = 0;
}
} else {
DevSysLog.logErrorMessage(this,"Unexpected "+ ev);
}
return;
}

/**
Starting Duolet
*/
public boolean start() {

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-78
count = 0;
try {
// load duolet
reader =(AnalogReader)DuoletManager.loadDuolet("jp.co.
yokogawa.stardom.sample.AnalogReader",
"AnalogReader1");
DuoletManager.startDuolet(reader);
DevTimer.setNotify(this,READ_PERIOD);
} catch(Exception ex) {
DevSysLog.logErrorMessage(this,ex.getMessage());
return false;
}
return true;
}

/**
Stopping Duolet
*/
public boolean stop() {
try{
// unload duolet
DuoletManager.stopDuolet(reader);
DuoletManager.unloadDuolet(reader);
}catch(DuoletControlException ex){
DevSysLog.logErrorMessage(this,ex.getMessage());
return false;
}
DevTimer.resetNotify(this);
return true;
}
}
AnalogReader.java

package jp.co.yokogawa.stardom.sample;

import jeros.ade.*;
import jp.co.yokogawa.stardom.dataaccess.*;
import java.util.Vector;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

/**
jp.co.yokogawa.stardom.sample.AnalogReader

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-79

Logging application sample


*/
public class AnalogReader extends DeviceDuolet
{
// Device Label Variable names
private String diTags[] = {"@GV.A_IN"};

// Data access object


private CSDCSAryAppDataAccess access = new CSDCSAryAppDataAccess();
private Vector vars = new Vector();
private Vector infos = new Vector();
private long[] errors = new long[1];

/**
Read AI
Exception : java.io.IOException
*/
public int read() throws IOException{
errors[0] = 0;
vars.removeAllElements();
infos.removeAllElements();

long status=0;
try{
// read @GV.A_IN array
status = access.ReadVarAryData(diTags,vars,infos,errors);
}catch(Exception ex){
throw new IOException("read() Not_Succes " + ex.getMessage());
}

// check status
if(status != CSDCSAryAppDataAccess.S_SUCCEED || errors[0] != 0) {
throw new IOException("read() Not_Succes errors[0]=" +
errors[0]);
}

int [] dataVal = (int[])vars.elementAt(0);


return dataVal[0];
}
}

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-80

3.7.4 Execution Preparation

E-mail Server
Make the following settings in the FCJ e-mail setting file (DEVMAIL.PRP).
y SMTP server :smtp_server
y POP3 user name :duolet

HOSTS setting
Set the IP addresses for smtp_server and ftp_server in the FCJ host name definition file
(HOSTS).

FTP Server
Prepare the directory /sample for storage of the log file on the FTP server.

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-81

3.7.5 Execution and Operation Confirmation

Execution
Perform execution according to the following procedures.
1. Copy the Logger folder under the Sample folder to the Projects folder.
2. Compile the source file.
3. Consolidate the created class files in a Jar file and transfer it to FCJ.
4. Use Logic Designer to download the control application to FCJ.
5. Execute the control application.
6. Use Duolet monitor to load the Logger.

Operation Confirmation
Execute Logger and confirm the operation. The current AI value is displayed every
minute in the LOG WINDOW of Duolet Monitor.
Confirm updating of the file /sample/anlg_dat.csv on the FTP server every hour. The log
file has the following contents.

Figure: Log file

TI 34P02K26-01E 2003.07.25-00
<Toc> <Ind> <3. Tutorial> 3-82
Also confirm notification via e-mail.

Figure: Notification via e-mail

TI 34P02K26-01E 2003.07.25-00
<Int> <Toc> <Ind> i

Revision Technical Information


Title : FCN/FCJ Java Function Programmer's Guide
Manual No. : TI 34P02K26-01E

Dec. 2002/1st Edition/R1.20 or later*


Newly published

Jul. 2003/2nd Edition/R1.20 or later*


Contents revised
- Errors were corrected

* : Denotes the release number of the software corresponding to the contents of this Technical Information.
The revised contents are valid until the next edition is issued.

Written by Open Control Systems Dept. PMK


IA Systems Business Div.
Published by Yokogawa Electric Corporation
2-9-32 Nakacho, Musashino-shi, Tokyo 180-8750, Japan
Printed by Yokogawa Graphic Arts Co., Ltd.

TI 34P02K26-01E 2002.12.15-00
2003.07.25-00

You might also like