PAUL SCHERRER INSTITUT
EPICS at PSI
PSIEPICSSLSSwissFELProscan

EPICS

EPICS at PSI
Software
Training

web epics.web.psi.ch

Author: A.Bertrand, A.Bertrand
Phone: +41 56 310 2765
Updated: 29.11.2007


Printer friendly version
 

PHP EPICS Module

Obsolete and unsupported!

1. Introduction

This module is intended to be used by a php Web applications. A dedicated php application will give the users, beamline scientists, etc. the possibility to create their own panels and Web pages to observe EPICS process variables without having to write the php code. To read, set or monitor EPICS channels from a php Web page the PHP was extended. The EPICS functions have been implemented in a PHP_EPICS dynamic external module (php_epics.so). The module is loaded by a php script, i.e. php Web page at run time by using the function dl(). It loads a shared object from disk and makes its functionality available to the php script.

The examles in section 3. explain how to use the module in a php page.

2. Supported Versions / Platforms

PHP_EPICS has been tested with/on Operating Systems
  • linux-x86 (2.4)
  • red-hat 9
EPICS Versions
  • 3.14
  • 3.13
PHP version
  • 4.3.x

Download

php_epics.tgz (14Kb)

3. Functions implemented

ca_get varriant ca_get(string channel_name) Get the value of the channel and return it with the correct variable type (double, int, string)
ca_put string ca_put(string channel_name,string channel_value) Set the value of the specified channel to the new value. Returns either OK or an error message.
ca_monitor string ca_monitor(string channels,int timouout,string callback) Setup a monitor on the channels (separated by commas) for the given "timeout" number of seconds. The function "callback" will be called each time some channel values change. The callback function need to receive 2 parameters, where the first is the channel modified, and the second is the new value. If 0 is specified for the timeout, the monitor will continue forever (not recommended).
ca_typestring ca_type(string channel) Return the type of data.
ca_statestring ca_state(string channel) Return the state of the channel. For example "Valid chid, connected to server"
ca_infoarray ca_info(string channel) Return information about the channel, like the host serving it (returned in array).

4. How to use ca_get, ca_put, ca_monitor in a PHP script?

Example 1. shows the php code of how to read and set an EPICS process variables, example 2. shows how to monitor, i.e. refresh the display when EPICS value has been changed.

Example 1: test_ca_get_put.php

	<?php
	#load external module
	dl("php_epics.so");

	#call function ca_get implemented in the php_epics.so module and display
	#the result

	$rt = ca_get("TEST:ai1");
	echo "Channel TEST:ai1 ".$rt;

	#in order to call ca_put function we want to pass a value as a parameter from
	#a text field
	echo "<FORM METHOD=GET ACTION=test_ca_get_put.php>\n";
	echo "Channel TEST:ai2 <INPUT TYPE=TEXT NAME=CHANNEL VALUE=".$_GET["CHANNEL"].">";
	echo "<INPUT TYPE=SUBMIT VALUE=Go>\n";
	echo "</FORM>";

	#call the function
	ca_put("TEST:ai2",$_GET["CHANNEL"]);

	#read and display the value
	echo "Channel TEST:ai2 ".ca_get("TEST:ai2");

	#Note: Channels "TEST:ai1","TEST:ai2" are running as soft channels on a PC
	#      on PSI network.
	?>
It looks like so:

Example 2: test_ca_monitor.php

<?php
	//load external module
	dl("php_epics.so");

	/* The function is called by ca_monitor imlemented in php_epics.so
	 * module any time when a value of one of EPICS channels changes
	 *Parameters:
	 *      channel name
	 *      value
	*/
	function test_monitor($a,$b) {
	    echo "test_monitor called: new value of $a is $b $<BR>\n";
	    //flush the output buffer to the browser
	    flush();
	}

	//flush the output buffer and turn off the output buffering
	ob_end_flush() ;

	//ca_monitor is implemented in php_epics.so module
	$res=ca_monitor("TEST:ai1,TEST:ai2",40,"test_monitor");

	echo "$res... Done.";

	//Note: Channels "TEST:ai1","TEST:ai2" are running as soft channels on a PC
	//      on PSI network.
	?>
It looks like so:

You don't know and don't want to learn the php scripting language? Try to follow the next section.

5. Things in progress

Currently a PHP parser/interpreter of adl files (MEDM) is under development. Once it will be finished, it will allow to see/run (most if not all) MEDM pannel, directly from any recent web browser. If you are interrested to see the current status of this development contact us.
Contacts: Alain BertrandRenata Krempaska

Author: A.Bertrand, A.Bertrand   Phone: +41 56 310 2765   Email: alain.bertrand@psi.ch   Updated: 29.11.2007   Source: /afs/psi.ch/project/epics/webhosting/software/php-epics/index.php