EPICS CHANNEL ACCESS USING WEBSOCKET
A. Uchiyama#, The Graduate University for Advanced Study (SOKENDAI), Tsukuba, JapanK. Furukawa, High Energy Accelerator Research Organization (KEK), Tsukuba, Japan
Y. Higurashi, RIKEN Nishina Center, Wako, Japan
Abstract
Web technology is useful as a means of widely
disseminating accelerator and beam status information.
For this purpose, WebOPI was implemented by SNS as a
web-based system using Ajax (asynchronous JavaScriptand XML) with EPICS [1]. On the other hand, it is often
necessary to control the accelerator from different
locations as well as the central control room during beam
operation and maintenance. However, it is not realistic toreplace the GUI-based operator interface (OPI) with aWeb-based system using Ajax technology because ofinteractive performance issue. Therefore, as a nextgeneration OPI over the web using EPICS Channel
Access (CA), we developed a client system based onWebSocket, which is a new protocol provided by theInternet Engineering Task Force (IETF) for Web-basedsystems. WebSocket is a web technology that provides bidirectional, full-duplex communication channels over asingle TCP connection. [2] By utilizing Node.js and theWebSocket access library called Socket.IO, a WebSocket
server was implemented. Node.js is a server-side
JavaScript language built on the Google V8 JavaScript
Engine. [3] In order to construct the WebSocket server as
an EPICS CA client, an add-on for Node.js was developedin C/C++ using the EPICS CA library, which is includedin the EPICS base. As a result, for accelerator operation,Web-based client systems became available not only inthe central control room but also with various types ofequipment.

INTRODUCTION
One of the advantages of an EPICS-based system is theunified communication protocol between the front-end
controller and client systems provided by the CA(Channel Access) protocol. Thus, even when various
types of controllers were used as control systems, all theclient systems such as the OPI (operator interface) could
be developed on the basis of the CA protocol without
hardware dependencies. In general, a method that used theCA libraries or display manager supported by EPICS
collaboration,suchasCAJ/JCA,
CA-Python,
MEDM/EDM, and CSS (Control System Studio) [4], wasadopted for the development of the GUI in the EPICSbased system. On the other hand, the engineers at SPring8 proposed the development methods for the main OPI
using WebSocket and conducted a prototype
implementation [5]. The prototype system wasconstructed using a MADOCA (message and databaseoriented control architecture)-based system that was______________________________________________

a-uchi@riken.jp#developed at SPring-8. It was different from the EPICSbased system. Since the web application with real-time
have many advantages, we started to develop WebSocket
server corresponding to EPICS CA, and implemented
Web applications using WebSocket for the EPICS-basedcontrol system. The traditional Web application lacked theinteractivity needed to operate some of the hardware forthe accelerator control system. By utilizing WebSocket
technology, it is possible to solve the problems of Webbased OPI, such as the interactive response.

WEBSOCKET PROTOCOL
WebSocket is a new protocol for achieving thebidirectional communication between a Web server andWeb browser. In the beginning, WebSocket was part of
HTML5. It was formulated as an RFC6455 by ITEF in
Dec. 2011. An overview of the protocol is as follows.
1.
2.
3.

A Web browser sends a handshake request to theserver for connecting to the WebSocket.
The server returns the handshake response afterapproval.
After the establishment of the handshake, theprotocol switches to the WebSocket, and then thebi-directional communication occurs between theWeb server and Web browser.

WebSocket makes interactive response realizable andthus compensates for the disadvantage that could not beeliminated in traditional HTML. Thus far, various types ofWeb services in EPICS-based systems have beenimplemented. However, there were only implemented in
Web-based systems, where a quick response andmonitoring are unnecessary such as in archive viewers
and electric-log systems. This is because it is difficult fora Web-based OPI to realize a real-time response similar tonative applications such as EDM/MEDM/CSS, even if
Ajax technology is utilized. Since it becomes bidirectional transmission between a server and clients has
become possible, the aforementioned problem is solved
by WebSocket. In practice, we confirmed sufficientinteractive response in a 100 ms cycle using WebSocketon the Web browser, and it had a performance similar tothat of native EPICS applications such as EDM.
Furthermore, since periodic polling is not necessary likeAjax, it becomes possible to reduce network traffic.
WebSocket does have a problem with Internet Explorer 9(IE9), which is one of the main browsers, because aWebSocket connection is unavailable. However, thisproblem may be resolved in IE10, which is the nextversion, because Microsoft planned it to be compliantwith WebSocket. [6]SERVER SIDE SYSTEM
We utilized Node.js and Socket.IO [7] as a WebSocket
library to develop the WebSocket server. Node.js is one ofthe server-side JavaScript languages developed based onthe Google V8 JavaScript Engine. As a main feature,
Node.js works asynchronously with single-thread
processing. Although many human resources may berequired for the development of an asynchronous
WebSocket server from scratch, Socket.IO solve theaforementioned problem. Node.js 0.6.18 and Socket.IO
0.9.6, which were stable versions of the languages, wereutilized for the development. In order to implement theWebSocket server with a CA connection using Node.js,
Node.js has to call the CA API. Therefore, we developed
add-on software to interface CA from Node.js, that is,NodeCA. Since Node.js can call the function developedby C++, NodeCA utilized the CA library provided by theEPICS base. To call CA from Node.js, caGet, caPut, andcaMonitor, which are basic functions in EPICS, wereprepared. In general, an event-driven caMonitor needs anon-blocking algorithm in the program, although singlethreading Node.js causes the thread to be blocked by theimplementation negligently. Consequently, in order toprevent the thread blocking, NodeCA is in waiting theCA event into another thread, and then it send themessage queue to the main thread. Figure 1 shows anoverview of NodeCA. The software developed by thisresearch is shown in the gray area.

Figure1: Overview of the System

CLIENT SIDE SYSTEM
It is possible to realize a text update like EDM bycoding DOM (document object model) with JavaScript on
the Web. In addition, flot [8] and jsgause [9], which are
jQuery-based JavaScript libraries, were used for thevisualization of the accelerator parameters in our system.
Many JavaScript libraries, other than those mentionedabove, are also available for the visualization ofinformation, such as strip chart. As a result, the clientsystem has the advantage of low development costs sincemoney can be saved multiple steps. Figure 2 shows thewhole system chart.
1.
2.

In the code of client side JavaScript, custom
events (caGet, caPut, caMonitor) are sent to theserver by using WebSocket protocol
WebSocket server connect to EPICS IOC via
NodeCA.

3.

It is available to get the accelerator parametersfrom EPICS IOC.

Figure 2: Whole System Chart

IMPLEMENTATION
After satisfying the need for interactive access forWebSocket using an EPICS-based system, we attempted
to implement NodeCA and the WebSocket server as aWeb-based OPI. As a result, the OPI was found to haveadequate ability for accelerator operation compared to thetraditional EPICS-based OPI. Moreover, we confirmedthat almost all the browsers for the iPhone4S/Android arecapable of obtaining and displaying numerical values
from EPICS IOC via WebSocket. The present software
support for browsers and OS is shown in Table 1. In thecase of iPhone, it is difficult to install self-produced
software without the approval of Apple Store. On theother hand, approval of Apple Store is unnecessary toinstall the self-produced Web application on an iPhone,although a Web server is required. We consider that theWeb application using the WebSocket server and NodeCA
have satisfactory performance as an OPI compared with
the native applications of the iPhone.
At present, we are implementing it for controlling the28GHz-ECRIS at RIKEN RIBF on a trial basis. [10] We
already verified that we had a good response whenmonitoring the vacuum of the plasma chamber,controlling the gas-valve, and so on.
Table 1: The Present Software Support
OSBrowsers
Windows/Linux Google Chrome 20, Firefox 14,
Opera 11
Android 4.0
Google Chrome 18, Firefox 14
iOS (iPhone)

Safari 5, Google Chrome 19,Mercury

DISCUSSION
In 2000, GAN (global area network) was proposed byICFA (International Committee for Future Accelerators)
as a network for ILC accelerator control. [11] Although
GAN aimed at an accelerator-only network withinternational collaboration, it has not been realized thus
far. Currently, a WAN with has sufficient high-speed data
communication is already in place around the world forthe development of Internet technology. On the otherhand, it is difficult to gain direct access from othernetworks using this WAN with the CA protocol because
firewalls are implemented between the accelerator
network and gateways. For this reason, we considered thepossibility of accelerator control using HTTP technology,
which is a standard protocol for the Internet, andWebSocket.
First, we considered the following in order to protect
the accelerator networks from outside intrusion. In thecase of accessing the accelerator network from the WAN,
we ensure the security of WebSocket access by using
VPN and authentication with SSL. Additionally,accelerator operators have to completely understand theuser attempting to access the networks (login ID and soon) and access route (full domain of Internet providers
and so on) before WebSocket control is allowed.
Therefore, all of the accessing logs for WebSocket control
should be open to the accelerator operators.
Next, we considered instructions for accelerator
operation to EPICS IOC from the Web browser via
WebSocket. For caPut, which provides instructions toeach device or component during accelerator operation,accelerator operators need to know the action andbehaviour perfectly. On the other hand, it would not
matter if they did not understand some simple instructions
in detail such as caGet and caMonitor, which are used tomonitor or obtain the numerical values for the accelerator
parameters. If some accelerator parameters are changed
using the Web application from outside the internal
networks without considering the beam tuning, theaccelerator condition will be complicated in many cases.
Thus, when using caPut, a policy is needed for between
the accelerator operators in the control room and amaintainer exerting control remotely over the Web. The
following are proposed for this policy.
1.
2.

3.
4.
5.

6.

Before the maintainer exercises remote control
over the Web, they have to call the acceleratoroperator or send an E-mail.
The maintainer authenticates users (andpasswords) using SSL on the Web. After theauthentication, it is possible to monitor theaccelerator parameters via WebSocket.
The accelerator operators check the user ID andthe domain or IP address of the Internet provider
for the maintainer.
The maintainer sends a request to the accelerator
operators when sending caPut instruction to theEPICS record.
In response to the request from the maintainer,
the accelerator operators make a judgement
decision about whether the component in theEPICS record may be controlled usingWebSocket. A response is returned to themaintainer about whether it is possible to operate
the component in the EPICS record.
After receiving this response, the maintainer can
not only monitor, but also operate the component
via WebSocket.

7.

If the accelerator operators make a judgement
decision to interrupt the operation, theWebSocket operation is discontinued as soon as
possible by the accelerator operator. In addition,
if a certain period of time passes, the permission
for the WebSocket operation will be cancelled bya timeout.

CONCLUSION
We developed a server that makes it possible to connect
with EPICS CA by WebSocket. It enables the display ofinformation on the accelerator conditions and make itpossible to control it from the Web browser in real time. Italso makes it possible to call CA API from Node.js byNodeCA as an add-on to the interface for the CA protocol.
We confirmed that we could control and monitor one partof the accelerator parameters as well as the traditional
EPICS-based application. Additionally, the developed
Web-based OPI runs not only on the main PC-basedbrowsers, but also on almost all of the browsers forAndroid and iPhone4S. We believe that this technology
will be useful as a means of accelerator operation using
Internet access, even if it has some problems of security.
In order to resolve these security problem for theoperation from a WAN, it is necessary to lay everythingout on the table to develop an access policy. In the future,
we will develop the NodeCA and WebSocket server forthe latest version of Node.js, which will be released as
open-source software.

REFERENCES[1] K. U. Kasemir, et al., Proceedings of ICALPECS
2011, Grenoble, France, 2011, THBHAUST01.
[2] I. Fette and A. Melnikov, The WebSocket Protocol,IETF HyBi Working Group. 2011.
[3] http://nodejs.org/[4] X. Chen, et al., Proceedings of 2011 Particle
Accelerator Conference, New York, NY, USA, 2011,
WEOBN3 .
[5] Y. Furukawa, et al., Proceedings of ICALPECS 2011,
Grenoble, France, 2011, WEMAU010.
[6] http://msdn.microsoft.com/en-us/library/ie/[7] http://socket.io/[8] http://code.google.com/p/flot/[9] http://code.google.com/p/jsgauge/[10] A. Uchiyama, et al., Proceedings of ECRIS 2012,
Sydney, Australia, 2012, TUPP12[11] “A Global Accelerator Network: ICFA Task Force
Reports”,
http://www.fnal.gov/directorate/icfa/icfa_tforce_repo
rts.html, Dec. 2001