A U.S. Department of Energy Office of Science Laboratory Operated by The University of Chicago Argonne National Laboratory Office of Science U.S. Department.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 3 Writing Java Applications, Java Development Tools.
Advertisements

Status of VDCT Mark Pleško, Matej Šekoranja, John Maclean EPICS Meeting – Japan, 2004.
Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
Using Eclipse. Getting Started There are three ways to create a Java project: 1:Select File > New > Project, 2 Select the arrow of the button in the upper.
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
JCA 2.0 Eric. Boucher – APS EPICS Collaboration Meeting - June 18-20, 2003.
Remote Method Invocation Chin-Chih Chang. Java Remote Object Invocation In Java, the object is serialized before being passed as a parameter to an RMI.
Principles of Object-Oriented Software Development The language Java.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
A U.S. Department of Energy Office of Science Laboratory Operated by The University of Chicago Argonne National Laboratory Office of Science U.S. Department.
Java implementation of Channel Access (CAJ) Matej Šekoranja ( presented by Rok Šabjan ) Funded by DLS (M.Heron) and DESY (M.Clausen) EPICS Meeting – SLAC,
Lecture 1: Overview of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++ Designed.
01 Introduction to Java Technology. 2 Contents History of Java What is Java? Java Platforms Java Virtual Machine (JVM) Java Development Kit (JDK) Benefits.
EPICS and Java Michael Dorin Metropolitan State University St. Paul, MN.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Exception Handling in Java Course Lecture Slides 7 th July 2010 “ Admitting.
Applets  The Applet Class  The HTML Tag F Passing Parameters to Applets.
Servlets Environment Setup. Agenda:  Setting up Java Development Kit  Setting up Web Server: Tomcat  Setting up CLASSPATH.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
Kazuro Furukawa, KEK, Jul Jacva and JCA / CAJ EPICS Workshop 2006, VECC, India 1 Java and JCA / CAJ Kenneth Evans, Jr. October 12, 2004 Part of the.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Introduction to Java. 2 Module Information Programming conceptsPrerequisites Beginners in JAVATarget Audience This module will provide you a solid grounding.
SC84, Epics C# Library Written by Christoph Seiler Presented by Dirk Zimoch.
Introduction to Eclipse and Eclipse RCP Kenneth Evans, Jr. Presented at the EPICS Collaboration Meeting June 13, 2006 Argonne National Laboratory, Argonne,
The Basics of Javadoc Presented By: Wes Toland. Outline  Overview  Background  Environment  Features Javadoc Comment Format Javadoc Program HTML API.
Java Spring PImage Let’s look at the PImage class in ProcessingPImage –What are the fields (i.e., variables)? –What methods are available? –What.
Java Introduction to JNI Prepared by Humaira Siddiqui.
By Noorez Kassam Welcome to JNI. Why use JNI ? 1. You already have significantly large and tricky code written in another language and you would rather.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and Server Side Programming Very rich GUI libraries Portability (machine independence) A.
CSCE 2013L: Lab 1 Overview  Java Basics The JVM Anatomy of a Java Program  Object-Oriented Programming Overview  Example: Payroll.java JDK Tools and.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
May 9, 2002Serguei A. Mokhov, 1 Kickstart Intro to Java Part I COMP346/ Operating Systems Revision 1.6 February 9, 2004.
A U.S. Department of Energy Office of Science Laboratory Operated by The University of Chicago Argonne National Laboratory Office of Science U.S. Department.
POS 406 Java Technology And Beginning Java Code
Java Programming Presented by Daniel Rosenthal Friday, November 30 th, 2007.
10/20/2015J-PARC1 Control Room Accelerator Physics Channel Access – Connection to Hardware Through EPICS Getting Information directly from the Control.
IBM TSpaces Lab 1 Introduction. Summary TSpaces Overview Basic Definitions Basic primitive operations Reading/writing tuples in tuplespace HelloWorld.
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
(Java) CA Client Libraries Status Matej Šekoranja
CS Software Studio Java Lab 1 Meng-Ting Wang PLLAB, Computer Science Department, National Tsing-Hua University.
We will talking about story of JAVA language. By Kristsada Songpartom.
CSE S. Tanimoto Java Introduction 1 Java A Programming Language for Web-based Computing with Graphics.
Writing a Channel Access Client in EPICS Bob Dalesio, April 5, 2000.
Copyright © Mohamed Nuzrath Java Programming :: Syllabus & Chapters :: Prepared & Presented By :: Mohamed Nuzrath [ Major In Programming ] NCC Programme.
Writing a Channel Access Client in EPICS Bob Dalesio, April 5, 2000.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
Applied Computing Technology Laboratory QuickStart Java Learning to Program in Java Dr. Tom Way October 21, 2005.
JAVA COURSE 1 Computer Engineering Association. Compile your first program Public class Hello{ public class Hello(){ System.out.println(“Hello”); } puclic.
JAVA Programming “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Server-Side Java Mapping Copyright © ZeroC, Inc. Ice Programming with Java 6. Server-Side Java Mapping.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Overview of Java CSCI 392 Day One. Running C code vs Java code C Source Code C Compiler Object File (machine code) Library Files Linker Executable File.
Channel Access Client Coding 2006
Classes, Interfaces and Packages
Controls Zheqiao Geng Oct. 12, Autosave Additions/Upgrades and Experiences at SLAC Zheqiao Geng Controls Department SLAC National Accelerator Laboratory.
3/5/2002e-business and Information Systems1 Java Java Java Virtual Machine (JVM) Java Application Program Interface (API) HW Kernel API Application Programs.
1 Applets Programming. Introduction Java programs are divided into two main categories, applets and applications. An application is an ordinary Java program.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 15: Java Basics Fundamentals of Web Programming.
Updates to CaPython/CaChannel John Hammonds Beamline Controls and Data Acquisition Group APS Engineering Support Division EPICS Collaboration Meeting INFN.
Features of JAVA PLATFORM INDEPENDENT LANGUAGE JAVA RUNTIME ENVIRONMENT (JRE) JAVA VIRTUAL MACHINE (JVM) JAVA APP BYTE CODE JAVA RUNTIME ENVIRONMENT.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Object Oriented Programming in
Before You Begin Nahla Abuel-ola /WIT.
Internet and Java Foundations, Programming and Practice
Part of the EPICS “Getting Started” Lecture Series
(Computer fundamental Lab)
Java Channel Access Client and Server Library - status
Presentation transcript:

A U.S. Department of Energy Office of Science Laboratory Operated by The University of Chicago Argonne National Laboratory Office of Science U.S. Department of Energy Java and JCA Kenneth Evans, Jr. October 12, 2004 Part of the EPICS “Getting Started” Lecture Series

Pioneering Science and Technology Office of Science U.S. Department of Energy 2 Outline Java Java and EPICS Overview of JCA Examples -SimpleJCAGet -SimpleJCAMonitor -JProbe

Pioneering Science and Technology Office of Science U.S. Department of Energy 3 Java Java is designed to be platform independent -Write once, run everywhere Java programs are interpreted by another program, possibly on another machine -The Java Virtual Machine (Java VM) Java technology includes -J2SEStandard Edition -J2EEEnterprise Edition (Multi-tier business apps) -J2MEMicro Edition (Phones, PDAs, etc.) Java is advertised to be all of these SimpleArchitecture neutralObject oriented PortableDistributedHigh performance InterpretedMultithreadedRobust DynamicSecure

Pioneering Science and Technology Office of Science U.S. Department of Energy 4 Java and EPICS EPICS Channel Access is native code -Not platform independent -Build cycle is edit – compile [to machine code] - link - run Pure Java -Build cycle is edit – compile [to byte code] – run [anywhere] Java Native Interface [JNI] is used to access native code -Not “Pure Java” -No longer platform independent -You generate shared object or DLL libraries that must be used with the Java program You can write your own JNI -Not that hard if you know Channel Access The EPICS build system handles Java projects and JNI Ant is an alternative

Pioneering Science and Technology Office of Science U.S. Department of Energy 5 JCA Stands for Java Channel Access JCA is a JNI implementation of an EPICS Channel Access client library for Java -Provides equivalents to most of the Channel Access API -Developed by Eric Boucher while at the APS -Currently taken over by Cosylab Available for download at - Latest version is at Cosylab JCA Version 1 uses EPICS Base 3.13 JCA Version 2 uses EPICS Base Channel Access is threaded -Allows for preemptive callbacks - Works better with Java, which is inherently threaded

Pioneering Science and Technology Office of Science U.S. Department of Energy 6 CAJ CAJ is a Java replacement for Channel Access Under development at Cosylab (Control Systems Laboratory) - -Located in Ljubljana in Slovenia -Situated between Austria (North), Italy (West), Hungary (East) and Croatia (South) -Cosylab also develops VDCT Will allow your programs to be “Pure Java” Can be used with JCA -Replaces JNI implementation -Requires replacing only one line of code - jca.createContext(JCALibrary.JNI_THREAD_SAFE); - jca.createContext(“com.cosylab.epics.caj.CAJContext”);

Pioneering Science and Technology Office of Science U.S. Department of Energy 7 Requirements Java J2SE installed (Current [suggested] version is 1.4.2) JCA -Java libraries - Download source and/or JAR files from the web -Native JNI libraries - Download from the web or build them - Currently found with the distribution only - jca.dllWindows - libjca.soUnix (Currently only Linux) Your project -JCA files need to be in your CLASSPATH -UNIX: Shared object library needs to be in your LD_LIBRARY_PATH -Windows: DLL needs to be in your PATH

Pioneering Science and Technology Office of Science U.S. Department of Energy 8 Resources EPICS web pages - -Look under Extensions, then JCA JCA API - htmlhttp:// html JCA API - Java Tutorial - J2SE Documentation - J2SE API (Javadoc) -

Pioneering Science and Technology Office of Science U.S. Department of Energy 9 JCA Packages Five Packages -gov.aps.jcaChannel-Access-like routines -gov.aps.jca.configurationConfiguration -gov.aps.jca.dbrDBR types -gov.aps.jca.eventEvent handling -gov.aps.jca.jniNative interface functions

Pioneering Science and Technology Office of Science U.S. Department of Energy 10 gov.aps.jca This is the package you will use most directly Classes -CASeverityEnum -CAStatusJCALibrary -ChannelMonitor -Channel.ConnectionStateValuedEnum -Context Exceptions -CAExceptionTimeoutException

Pioneering Science and Technology Office of Science U.S. Department of Energy 11 JCALibrary Initializes JCA JCALibrary jca=JCALibrary.getInstance(); There is only one instance Used to create contexts and manage JCA configuration info Properties -JNI_THREAD_SAFEpreemptive - Suggested for Java, which is inherently threaded -JNI_SINGLE_THREADEDnon-preemptive Methods -createContext -getProperty -listProperties -getVersion, getRevision, getModification

Pioneering Science and Technology Office of Science U.S. Department of Energy 12 Context Corresponds to a Channel Access context Created by JCALibrary.createContext createContext(JCALibrary.JNI_SINGLE_THREADED) createContext(JCALibrary.JNI_THREAD_SAFE) Controls all IO You can have more than one context Methods -createChannel -flushIO, pendIO, pendEvent, poll -attachCurrentThread -addContextExceptionListener, removeContextExceptionListener -addContextMessageListener, removeContextMessageListener -destroy

Pioneering Science and Technology Office of Science U.S. Department of Energy 13 Channel Represents a Channel Access channel Created by Context.createChannel createChannel(String name, connectionListener l) Properties -CLOSEDCONNECTED -DISCONNECTEDNEVER_CONNECTED Methods -get, many overloads -put, many overloads -getName, getConnectionState, getElementCount, etc. -addMonitor -addConnectionListener, removeConnectionListener -addAccessRightsListener, removeAccessRightsListener -destroy

Pioneering Science and Technology Office of Science U.S. Department of Energy 14 Monitor Represents a Channel Access monitor Created by Channel.addMonitor addMonitor(DBRType type, int count, int mask, MonitorListener l) Properties -ALARMLOGVALUE Methods -addMonitorListener, removeMonitorListener -getMonitorListener, getMonitorListeners -clear -getChannel, getContext -getCount, getMask, getType -isMonitoringAlarm, isMonitoringLog, isMonitoringValue

Pioneering Science and Technology Office of Science U.S. Department of Energy 15 MonitorListener Part of gov.aps.jca.event One method -monitorChanged Example private class MyMonitorListener implements MonitorListener { public void monitorChanged(MonitorEvent ev) { // Call my handler onValueChanged(ev); } }; The value and status comes with the MonitorEvent

Pioneering Science and Technology Office of Science U.S. Department of Energy 16 MonitorEvent Part of gov.aps.jca.event Methods -getDBRHow you get the value -getStatusHow you determine the status Example if(ev.getStatus() == CAStatus.NORMAL) { DBR dbr=ev.getDBR(); double [] value=((DOUBLE)dbr).getDoubleValue(); }

Pioneering Science and Technology Office of Science U.S. Department of Energy 17 Event Types MonitorListenerMonitorEvent GetListenerGetEvent PutListenerPutEvent AccessRightsListenerAccessRightsEvent ConnectionListenerConnection Event ContextExceptionListenerContextExceptionEvent ContextMessageListenerContextMessageEvent Events all inherit from CAEvent They all work similarly to Monitor -Call the routine that fires the event when it occurs -Add a listener with the appropriate handler -Get the data from the event that is passed to your handler

Pioneering Science and Technology Office of Science U.S. Department of Energy 18 gov.aps.jca.dbr Implements the EPICS DBR_xxx types Interfaces -DOUBLE, FLOAT, INT, STRING, TIME, CTRL, etc. Primary Class -DBR Subclasses of DBR -DBR_Double, DBR_Float, DBR_Int, DBR_STS_Double, etc. Example: DBR_STS_Double -Interfaces - STS, DOUBLE -Extends - DBR_Double -Subclasses - DBR_GR_Double, DBR_Time_Double

Pioneering Science and Technology Office of Science U.S. Department of Energy 19 SimpleJCAGet package simplejca; import gov.aps.jca.*; import gov.aps.jca.dbr.*;

Pioneering Science and Technology Office of Science U.S. Department of Energy 20 SimpleJCAGet public class SimpleJCAGet { public static void main(String[] args) { SimpleJCAGet simpleJCAGet = new SimpleJCAGet(); JCALibrary jca=null; Context ctxt=null; Channel chan=null; // Parse the command line if(!simpleJCAGet.parseCommand(args)) System.exit(1); if(!simpleJCAGet.pvSpecified) { System.err.println("No PV specified\n"); System.exit(1); }

Pioneering Science and Technology Office of Science U.S. Department of Energy 21 SimpleJCAGet // Initialize and search try { // Get the JCALibrary instance jca=JCALibrary.getInstance(); // Create a non-preemptive context context=jca.createContext( JCALibrary.JNI_SINGLE_THREADED); // Search chan=ctxt.createChannel(simpleJCAGet.name); // Wait for search ctxt.pendIO(simpleJCAGet.timeout); } catch(Exception ex) { System.err.println("Search failed for " + simpleJCAGet.name + ":\n" + ex); System.exit(1); }

Pioneering Science and Technology Office of Science U.S. Department of Energy 22 SimpleJCAGet // Get the first value as a String try { // Get the value String [] value; value=((STRING)chan.get(DBRType.STRING,1)). getStringValue(); // Wait for the get ctxt.pendIO(simpleJCAGet.timeout); // Print the value System.out.println("The value of " + simpleJCAGet.name + " is " + value[0]); } catch(Exception ex) { System.err.println("Get failed for " + simpleJCAGet.name + ":\n" + ex); System.exit(1); }

Pioneering Science and Technology Office of Science U.S. Department of Energy 23 SimpleJCAGet // Clean up try { // Clear the channel chan.destroy(); // Destroy the context ctxt.destroy(); } catch(Exception ex) { System.err.println("Clean up failed for " + simpleJCAGet.name + ":\n" + ex); System.exit(1); } // Successful exit System.exit(0); }

Pioneering Science and Technology Office of Science U.S. Department of Energy 24 SimpleJCAGet output java.exe -classpath \SimpleJCA.jar; \jca jar simplejca.SimpleJCAGet evans:calc The value of evans:calc is 3

Pioneering Science and Technology Office of Science U.S. Department of Energy 25 SimpleJCAMonitor Similar to SimpleJCAGet -Imports, parsing the command line, etc. are the same We will have listeners We will use JNI_THREAD_SAFE ( preemptive) We will use flushIO and not pendIO, etc.

Pioneering Science and Technology Office of Science U.S. Department of Energy 26 SimpleJCAMonitor /** Implementation of Connection Listener class */ private class SJCAConnectionListener implements ConnectionListener { public void connectionChanged(ConnectionEvent ev) { onConnectionChanged(ev); } }; /** Implementation of MonitorListener class */ private class SJCAMonitorListener implements MonitorListener { public void monitorChanged(MonitorEvent ev) { onValueChanged(ev); } };

Pioneering Science and Technology Office of Science U.S. Department of Energy 27 SimpleJCAMonitor // Instance of SimpleJCAMonitor SimpleJCAMonitor sjcam=new SimpleJCAMonitor(); // Initialize JCA try { // Get the JCALibrary instance jca=JCALibrary.getInstance(); // Create a preemptive context, default configuration ctxt=jca.createContext(JCALibrary.JNI_THREAD_SAFE); } catch(Exception ex) { System.err.println("Initialization failed for " + sjcam.name + ":\n" + ex); System.exit(1); }

Pioneering Science and Technology Office of Science U.S. Department of Energy 28 SimpleJCAMonitor // Search try { // Search chan=ctxt.createChannel(sjcam.name, sjcam.new SJCAConnectionListener()); ctxt.flushIO(); } catch(Exception ex) { System.err.println("Search failed for " + sjcam.name + ":\n" + ex); System.exit(1); }

Pioneering Science and Technology Office of Science U.S. Department of Energy 29 SimpleJCAMonitor private void onConnectionChanged(ConnectionEvent ev) { Channel ch=(Channel)ev.getSource(); Context ctxt=ch.getContext(); // Start a monitor on the first connection if(connectionCounter == 0 && ch.getConnectionState() == Channel.CONNECTED) { try { // Add a monitor listener and flush ch.addMonitor(DBRType.STRING,1, Monitor.VALUE|Monitor.LOG|Monitor.ALARM, new SJCAMonitorListener()); ctxt.flushIO(); } catch(Exception ex) { ex.printStackTrace(); }

Pioneering Science and Technology Office of Science U.S. Department of Energy 30 SimpleJCAMonitor // Print connection state if(ch.getConnectionState() == Channel.CONNECTED) { System.out.println(ch.getName() + " is connected"); } else if(ch.getConnectionState() == Channel.CLOSED) { System.out.println(ch.getName() + " is closed"); } else if(ch.getConnectionState() == Channel.DISCONNECTED) { System.out.println(ch.getName() + " is disconnected"); } else if(ch.getConnectionState() == Channel.NEVER_CONNECTED) { System.out.println(ch.getName() + " is never connected"); }

Pioneering Science and Technology Office of Science U.S. Department of Energy 31 SimpleJCAMonitor private void onValueChanged(MonitorEvent ev) { Channel ch=(Channel)ev.getSource(); Context ctxt=ch.getContext(); // Check the status if (ev.getStatus() != CAStatus.NORMAL) { System.err.println("monitorChanged: Bad status”); } // Get the value from the DBR try { DBR dbr=ev.getDBR(); String [] value=((STRING)dbr).getStringValue(); System.out.print(SJCAUtils.timeStamp() + " " + getName() + ": “ + value[0]); } catch(Exception ex) {... }

Pioneering Science and Technology Office of Science U.S. Department of Energy 32 Simple JCAMonitor output Oct 11, :36: Starting Simple JCA Monitor Oct 11, :36: Search successful for: evans:calc CHANNEL : evans:calc TYPE : gov.aps.jca.dbr.DBRType[DBR_DOUBLE=6] COUNT : 1 STATE : gov.aps.jca.Channel$ConnectionState[CONNECTED=2] HOSTNAME : ctlapps4l188.aps4.anl.gov:5064 READ : true WRITE : true Oct 11, :36: evans:calc is connected Oct 11, :36: evans:calc: 2 Oct 11, :36: evans:calc: 3... Oct 11, :36: evans:calc: 3 Oct 11, :36: evans:calc: 4 Oct 11, :36: All Done

Pioneering Science and Technology Office of Science U.S. Department of Energy 33 JProbe JProbe is a simple example that demonstrates using JCA in a Swing GUI

Pioneering Science and Technology Office of Science U.S. Department of Energy 34 Write once, run everywhere?

Pioneering Science and Technology Office of Science U.S. Department of Energy 35 Source files for Simple JCA routines All the source and JAR files should be available with the presentation -LICENSE -SimpleJCA.jar -simplejca - SimpleJCAMonitor.java - SimpleJCAGet.java - SJCAUtils.java -JProbe.jar -jprobe - JProbe.java - MainFrame.java - AboutBoxPanel.java Stored as SimpleJCA.zip

Pioneering Science and Technology Office of Science U.S. Department of Energy 36 Acknowledgements JCA was developed by Eric Boucher while at the APS Matej Sekoranja [Cosylab] has taken over JCA and is developing CAJ Both of these people were very helpful in getting JCA working for me

Pioneering Science and Technology Office of Science U.S. Department of Energy 37 Thank You This has been an APS Controls Presentation

Pioneering Science and Technology Office of Science U.S. Department of Energy 38 Thank You This has been an APS Controls Presentation