PCaPAC2012

EPICS Channel Access using
WebSocketSokendai

A. UCHIYAMAKEKK. FURUKAWA

RIKEN

Y. HIGURASHI
A. UCHIYAMAAdvantage of Web-based System Use of the Wide Area Network for the System••

We can use Internet access around the world.
Web is already a standard protocol in the Internet.

 Not only Control Room, But also other place.
•The maintainer operate over the web without a central control room.

 Rapid development of HTML/JavaScript•

Development of GUIs needs human resources, for example C/C++ and JAVA.

 Unnecessary to install exclusive software.
••

No X-window System, No Java virtual machine because almost browsers are crossplatform... expect IE.
Almost devices are installed web browsers already.

2

A. UCHIYAMAHTTP(HyperText Transfer Protocol)
A sequence from the connection to the disconnect for HTTPCGIWeb Application

GET /sample1/Hello.cgi?message=ABCD
POST/sample1/HelloHTTP Request

HTTP Response
Server-Side
Fundamental architecture
1. A browser send the HTTP request.
2. Web application is run in the server.
3. HTTP response is returned.

Client-Side3

A. UCHIYAMAWeb-based System Using EPICS (1)CAML Channel Access Markup Language by SNS

CAML is a framework , it can control using the CA protocol from a Web browser by XML.

CA plug-in
WebCA plug-in
developed by Cosylab

EPICS IOC・Dependencies for browsers

The plug-in needs for Firefox, Google Chrome, and Safari.

・A browser generates CA connection directly.
It is difficult to use non-PC-based browser.

4

A. UCHIYAMAWeb-based System Using EPICS (2)WebOPI ・ WebOPI can be used to access the GUIs developed by CSS/BOY from a Web browser.
by SNSWebOPI is a useful !

Ajax (Asynchronous JavaScript and XML)

RequestResponse・Ajax is used for interactive action on the Web.
・Firefox Web browser could access the Web server with a cycle of ~100 ms for data transfer
in our Intranet environment.

5A. UCHIYAMARevolution of Web-based System
ICALEPCS2011@France Grenoble 2011/10• Y. Furukawa at SPring-8 proposed the development methods
for the main OPI using WebSokect.
• The prototype system was constructed using a MADOCA-based system.

Web has a disadvantage about the interactive response.
●However, Real-time web has many advantages. <--- WebSocket !
●We started to develop WebSocket server for EPICS Channel Access protocol.
●Reference: Proc. ICALEPCS2011, No.WEMAU10, Y. Furukawa

6

A. UCHIYAMAWebSocket（１）New protrocol for bi-directional communication
Disadvantage of Ajax
– Must make the socket connection many time.
• Response speed is very important for OPI.
– There is no callback function.
– We CanNot know the server status from browsers.

PutWebSocket
ServerBrowser
sconnection

Put ... fail？success？

⇥⇤⌅⇧Success because of OK callback

Keep bi-directional communication
7

A. UCHIYAMAWebSocket（２）Disadvantage of WebSocket

All browsers are not available.
Mozilla Firefox
Google ChromeOperaInternet Explorer９
Microsoft planned WebSocketcompliance in IE10◎◎◎
×StandardProtocol8

A. UCHIYAMARequirement
In order to realize for EPICS, there are requirements.

1. Development of WebSocket serverWe utilized Node.js（Server-Side JavaScript)

2. Node.js has to call the CA API
C++ add-on (Channel Access for Node.js=NodeCA)

3. Implementation of Client System
JQuery libraries is used for visualization (chart or gauge).
DOM coded JavaScript is used for Text update.
9A. UCHIYAMANode.jsFeature

The Node.js-based network application consist of simple code !

Server-Side JavaScript Generally, JavaScript is running on browsers.
 Using C/C++, it’s difficult to develop Websocket server from scratch.
 JavaScript is also used on the server-side as well as client-side.

Node.js can utilize a library for WebSocket API.
• I don't want to do complicated tasks ...

Socket.IO
10A. UCHIYAMANodeCA・WebSocket server Overview
The softwaredeveloped bythis research

WebSocket Server for EPICS CASocket.IO
Node.js
Google V8 Engine

NodeCAEPICS basecaget Example(server-side)
var pv = require(“../build/Release/nodeca”);
val = pv.caget(“akito12:example”);
console.log(val);

Reading add-on
EPICS PV
Output value

This system concept is the coding as simple as possible.
11A. UCHIYAMAOverview of the System
Example of EPICS-based System–That’s typical system.

OPICA
ProtocolDevices

EPICS IOC12⌃⌥ ⌦↵ ⌃ ⌃Overview of the System
WebSocket server and OPI are same layer.
WebSocket
ServerOPICA
ProtocolWebSocket

Devices

EPICS IOC

13A. UCHIYAMAWebSocket Overview
・In our system, WebSocket server and Web server use same port. (80)

HTTP Request
HTTP(S)
ServerWeb Browser

HTTP Response

HTMLJavaScript

WebSocket
WebSocketServerCAEPICS IOC

MethodcaGet, caPut,caMonitor, etc

1. Web browser sends HTTP request and get HTTP response.
2. Web browser connects to WebSocket server after handshake response.
3. Client-side JavaScript sends some methods to WebSocket server.
4. WebSocket server connects to EPICS IOC and get/put the value.
5. WebSocket server returns the value to Web browser.

14

A. UCHIYAMAImplementation of client-side JavaScript (1)/* send */var socket =io.connect('/ca/gauge');socket.emit('caMonitor',{pv: 'akito12Host:ai1',
data_name: 'ai'})/* recieve */socket.on('ca', function(data){var value = data.ai;});EPICS PV
Defined data name

Receive data

15A. UCHIYAMAImplementation of client-side JavaScript (2)JavaScript libraries are used for visualization of real-time data.

・jsgauge(jQuery-base library, MIT license)
・flot

Making good looking chart from scratch is costly work.
Other paid JavaScript libraries are also available.

GUI development for OPI ≒ Web(HTML) development
The level of difficulty become lower.
16A. UCHIYAMADemonstration

17A. UCHIYAMAExample of RIBF SC-ECR Ion Source Control

18

A. UCHIYAMAImplementation of client-side (Mobile)

Google Chrome on Android4.0
Safari on iPhone4S
The Level of difficulty become lower

than Objective-C & cocoa Touch

・Safari has a function to get
the touch event for iPhone/iPod Touch.
Multi-touch application is also available.
19

A. UCHIYAMAWWW・ World Wide Web was born in CERN
Tim Berners-Lee developed WWW forsharing and updating information among researchers.

・Since then, we can control accelerators
by using WWW with new WebSocket now ...

Don't you feel
dramatic story ?
Flickr upload bot on 16:24, 1 May 2010 (UTC) by Ranveig (talk).

A. UCHIYAMASummary• We developed the OPI for EPICS using WebSocket.
• In order to develop the OPI, we developed✔
✔

NodeCA as an add-on to the interface for the CA protocol.
WebSocket server for CA call from client-side JavaScript.

We could control and monitor one part of the accelerator
parameters as well as the traditional EPICS-based application.
●The developed Web-based OPI runs not only on the main PC-basedbrowsers, but also Android and iPhone4S browsers.
●Thank you
21A. UCHIYAMA