Package xal.plugin.epics7
The Open XAL EPICS7 plugin was introduced in v4.0. It enables communication with IOCs using both PV Access and Channel Access protocols, as well as the creation of EPICS softIOCs as part of Open XAL applications.
The other 2 plugins available are:
- jca: this is the plugin previously used. It implements the EPICS v3 protocol and uses the jca/caj Java library.
- pvaccess: implements the PV access protocol, but no Channel Access. This plugin behaves slightly different than the jca plugin when trying to connect a channel that is not alive. Some applications might not function properly for this reason. Recommendation is NOT to use it.
Configuration
The plugin will use the EPICS environment variables by default. This configuration can be overwritten by setting a set of Java preferences. The main tool to modify those preferences is the <ac:link> <ri:page ri:space-key="BPCRS" ri:content-title="User documentation for Open XAL Configurator" /> <ac:plain-text-link-body> <![CDATA[Open XAL Configurator]]> </ac:plain-text-link-body> </ac:link>.
If one needs to edit these preferences from a Java application, use the class xal.tools.apputils.Preferences as:
java.util.prefs.Preferences defaults = Preferences.nodeForPackage(Channel.class);
The names of the preferences are the same as the EPICS environment variables.
Finally, the configuration can be modified when launching the application by setting properties for the JVM, or even using the System.setProrperty() method. The names of the properties are also the same as the EPICS environment variables. For example, one can do:
java -DEPICS_PVA_AUTO_ADDR_LIST=false -jar openxal.app.application.jar
For more information, please check the loadConfig method in xal.plugin.epics7.Epics7ChannelSystem.
Client usage
In general, EPICS communication is done implicitly by calling methods of SMF elements. The EPICS signal names used are taken from the SMF XML lattice files.
By default, the plugin tries to connect using both Channel Access and PV Access protocols. If the channel exists in both protocols, it will use the one which replies first, which can make the behaviour non-deterministic. It is possible to set which protocol to use by adding the ca:// or pva:// prefix to the signal name.
One can also explicitly connect to a channel by using the ChannelFactory class. First, get the Factory:
ChannelFactory channelFactory = ChannelFactory.defaultFactory();
Then use the method getChannel() to get the channel:
Channel channel = channelFactory.getChannel("PV:NAME");
and finally use any of the get methods to retrieve data from the channel, e.g.:
double result = channel.getValDbl();
To make a put, use the putVal() method, as in the following example:
channel.putVal(3.1416);
If the timestamp is also required, one can do as follows:
ChannelTimeRecord timeRecord = channel.getTimeRecord();
Timestamp timestamp = timeRecord.getTimestamp();
And similarly for the alarm status:
ChannelStatusRecord statusRecord = channel.getStatusRecord();
int status = statusRecord.status();
int severity = statusRecord.severity();
Monitors
The Channel can also be used to create monitors. Here you can find an example on how to create a monitor for value changes:
Monitor monitor = channel.addMonitorValue((record, chann) -> {
System.out.println("Value = " + record.doubleValue());
}, 0);
Here a lambda function is used, but in general the listener can be any class implementing IEventSinkValue.
Server usage
Similarly to the client, the plugin creates channels for both Channel Access and PV Access protocols. In this case, there is no option to disable one of the protocols. This option might be added in the future if it is required. The plugin ensures that if a put is done using one protocol, the value is updated for both protocols.
In order to create a server channel, one first needs to get the factory:
ChannelFactory channelFactory = ChannelFactory.newServerFactory();
The procedure to create the channel is exactly the same as for the client:
Channel channel = channelFactory.getChannel("TEST:SERVER:PV");
After that, the new channel is created and accepting connections. One can put new values the same way as for the client, as well as running monitors from the same code to check when a put is done externally.
After finishing all the EPICS communications, it is advisable to free all resources by running:
ChannelFactory.disposeAll();
-
ClassDescriptionThis
Channel
implementation can connect to ChannelAccess or PV Access.NOTE: previous implementations kept a cache of native channels, but that is not required since ChannelFactory keeps a list of Open XAL Channels, which can create only 1 native channel each.ChannelRecord implementation for Epics7.ChannelStatusRecord implementation for Epics7.ChannelTimeRecord implementation for Epics7.Monitor implementation for Epics7.