# Presentation: 093360

## Serial Support for Diamond

*A review of EPICS serial interface options*
- Pete Owens
- Daresbury Laboratory

## Serial Interfaces

- Sharp intake of breath!

- Serial Support for Diamond - Pete Owens - Daresbury Laboratory

- EPICS Collaboration Meeting - May 2002

**Notes:**
Why are we doing this?

The diamond control system will have a lot of serial interfaces

When Mark Heron presented this slide at PSI last year you could hear the sound of air being sucked through teeth.

## Serial Interfaces

**Need to support serial interfaces to equipment**
**Advantages:**
**Increased functionality per connection**
**Minimises calibration errors from Control System ADCs**
**Widely accepted use of RS232/422 etc**
**Integration of systems**
**Faster commissioning**
**Disadvantages:**
**High processor load**
**Development to support vendor protocols**
**Asynchronous I/O**
**Need signals for fast logging and interlocks**

- Serial Support for Diamond - Pete Owens - Daresbury Laboratory

- EPICS Collaboration Meeting - May 2002

**Notes:**
There are a number of advantages to using serial interfaces.

 Fewer connections into the IOCs
 Reduces the commisioning effort needed for calibrationg ADCs
 Once you have sorted the protocol out it works

Buth there are a number of drawbacks
 with an interrupt for every character this can make for a high processor load
 All the IO is slow and asynchrenous - preventing  fast feedback
 Vendor protocols can be awkward to say the least and tend to be more suited to console displays rather than computer intefaces.

## Vacuum Equipment Test Rack

- MKS 937A - *multi-sensor vacuum gauge system*
- Balzers TPG 300 - *pressure gauge controller*
- Varian Dual - *ion pump controller*
- Digitel MPC - *ion pump controller*
- Mitsubishi ‘A’ Series PLC - *valve control*

- Serial Support for Diamond - Pete Owens - Daresbury Laboratory

- EPICS Collaboration Meeting - May 2002

**Notes:**
We have put together a test rack with a range of vacuum kit we found lying around the SRS - all communicating via serial line.

## Vacuum Equipment Test Rack

- VME 64x Crate
- Processors:
- MVME 167 & PPC 604
- IP Carriers:
- Hytec VICB8002
- Greenspring VIPC601
- Serial Interface Card:
- Greenspring IPOctal - *8 channel IP card*

- Serial Support for Diamond - Pete Owens - Daresbury Laboratory

- EPICS Collaboration Meeting - May 2002

**Notes:**
We made up a couple of IOCs - one with a Power PC, the other a 68k
Used a greenspring IP Octal 8 channel RS 232 IPO card

## EPICS Devices

- devAscii - *Allan Honey/Jeff Hill - KECK *
- Stream Device - *Dirk Zimoch - DELTA*
- MPF - *Mohan Ramanathan - APS *
- ornlSerial - *John Sinclair - Oak Ridge*
- tyGSOctal - *Peregrine McGehee - Hawaii*

- Serial Support for Diamond - Pete Owens - Daresbury Laboratory

- EPICS Collaboration Meeting - May 2002

**Notes:**
We had a look to see what was available in the EPICS community and found these 4 devices. All approaches also use the tyGSOctal  driver to handle the Greenspring IP card.
I’m not going to talk in detail about any of these devices. That has already been done elsewhere. 
I am going to relate our experiences as EPICS novices using these four devices. How easy were they to build,to understand, to extend and so on.

## devAscii

*Allan Honey/Jeff Hill - KECK Observatory *
- De-facto standard
- Format string in INP or OUT field
- Special records for terminators, timeout etc.

**field(INP,"@/tyGS/0/0 <R2><%f>")**

- Serial Support for Diamond - Pete Owens - Daresbury Laboratory

- EPICS Collaboration Meeting - May 2002

**Notes:**
This is THE standard EPICS serial interface.

Most of you are probably more familiar with it than I am.

It works by putting  printf/scanf format descriptors into the OUT/INP fields

## devAscii - Experience

- Implemented database for MKS 937A
- Good points
- easy to use
- widely used
- Not so good
- special records
- Limitation
- checksums or complex protocols

- Serial Support for Diamond - Pete Owens - Daresbury Laboratory

- EPICS Collaboration Meeting - May 2002

**Notes:**
So what did we find.

It worked.

It was fairly easy to understand - though the special records were a bit confusing at first.

All you need to do is to edit a .db file

Limitation was the inability to generate checksums and handle delays.

## Stream Device

*Dirk Zimoch - DELTA*
- _[http://www.](http://www.delta/uni-dortmund.de/controls/pub/doc/streamDevice)__[delta](http://www.delta.uni-dortmund.de/controls/pub/doc/streamDevice/)__[.](http://www.delta/uni-dortmund.de/controls/pub/doc/streamDevice)__[uni](http://www.delta/uni-dortmund.de/controls/pub/doc/streamDevice)__[-](http://www.delta/uni-dortmund.de/controls/pub/doc/streamDevice)__[dortmund](http://www.delta/uni-dortmund.de/controls/pub/doc/streamDevice)__[.de/controls/pub/](http://www.delta/uni-dortmund.de/controls/pub/doc/streamDevice)__[doc](http://www.delta/uni-dortmund.de/controls/pub/doc/streamDevice)__[/](http://www.delta/uni-dortmund.de/controls/pub/doc/streamDevice)__[streamDevice/](http://www.delta/uni-dortmund.de/controls/pub/doc/streamDevice)_
- Device support for common record types.
- Allows to connect records to multiple hardware via arbitrary field bus architectures (*CAN & GPIB supported*).
- Bus data must appear as a stream of bytes.
- Protocol defined in a file.

- Serial Support for Diamond - Pete Owens - Daresbury Laboratory

- EPICS Collaboration Meeting - May 2002

**Notes:**
Next thing we looked at was Stream Device

The main difference between this and devAscii is that the protocols are defined in a file rather than in database files

## Stream Device - Protocol File

**# Stream Device Protocol for the MKS 937A Multi-Sensor System**
**terminator   = CR;**
**replytimeout = 1000; # milliseconds**
**extrainput   = Ignore;**
**pressure { out "R\$1"; in "%f"; }**
**enable   { out "%{X|E}CC\$1"; in "OK"; }**
**status { **
**    ****out "R\$1"; **
**    ****in "%{HI|A|Lo|F|H|W|L|CON|P|NOG|M|NOT|Not|C}"; **
**}**

- Serial Support for Diamond - Pete Owens - Daresbury Laboratory

- EPICS Collaboration Meeting - May 2002

**Notes:**
This is an example protocol file

You  would write one file for each type of equipment you can control

It can include deelays and multi-stage protocols

All the info is in one place rather than distributed throughout the database

still uses scanf type format statements with nice extensions such as a choice shown here to fill and mbbi record

## Stream Device - Experience

- Added bus support for tty devices
- modular design, good documentation
- Produced protocol files for:
- MKS 937A, Varian dual, TPG 300
- Good points
- protocol files, multi-stage protocols, delays...
- Limitation
- checksums

- Serial Support for Diamond - Pete Owens - Daresbury Laboratory

- EPICS Collaboration Meeting - May 2002

**Notes:**
What did we do?

First we had to add bus support for tty devices. (the original only provides support for CANbus & GPIB). 
The code was well structured and documented making this easy to do.

We produced protocol files for a number of devices.
This is very straight forward.

We liked
  Protocol files - everything in one place
 Multi-stage protocols in out in out

Same limitation as devAscii - checksums

## MPF (Message Passing Facility)

*Mohan Ramanathan - APS*
- _[http://www.aps.anl.gov/aod/people/mohan/](http://www.aps.anl.gov/aod/people/mohan/)_
- Client/server design
- Server side independent of EPICS, giving configuration flexibility.
- Support available for Digitel MPC
- Custom record

- Serial Support for Diamond - Pete Owens - Daresbury Laboratory

- EPICS Collaboration Meeting - May 2002

**Notes:**
Existing driver support for Digitel MPC Ion Pump Controller, using MPF (Message Passing Facility), obtained from Mohan Ramanathan at APS 
Client/server design
Server side independent of EPICS, giving configuration flexibility. 

## MPF - Experience

- Implemented support for Varian Dual
- Software complex to build and modify
- Mods to C++ module for the server side, handling the hardware interface
- Mods to C++ module for the client side, scheduling command requests
- Mods to C module for custom record support
- Mods to build files
- Mods to include files

- Serial Support for Diamond - Pete Owens - Daresbury Laboratory

- EPICS Collaboration Meeting - May 2002

**Notes:**
The code built and worked fine for the Digitel MPC

So we thought we would see what it was like to extend to a different piece of kit. (in this case the Varian Duel Ion pump controller)

This involved a fair bit of non-trivial coding. We had to create a custom record AND build the client and server sides of MPF by hacking the existing code. (compared to an afternoon knocking up a stream device protocol file)

## MPF - Evaluation

- Good points
- flexibility
- custom record for Digitel MPC included
- well-structured software design.
- Bad points
- development overhead for new devices
- over-engineered for diamond project.

- Serial Support for Diamond - Pete Owens - Daresbury Laboratory

- EPICS Collaboration Meeting - May 2002

**Notes:**
The MPC custom record replaces about 50 standard epics records in the database.

It is very flexible in that any protocol can be parsed

The server-side could be on a non-EPICS system.

On the other hand - it was very hard work to extend to new devices

## ornlSerial

*John Sinclair - Oak Ridge*
- _[http://www.](http://www.sns.gov/projectinfo/ics/epicsCollaborationMtg/serialSupport.ppt)__[sns](http://www.sns.gov/projectinfo/ics/epicsCollaborationMtg/serialSupport.ppt)__[.](http://www.sns.gov/projectinfo/ics/epicsCollaborationMtg/serialSupport.ppt)__[gov](http://www.sns.gov/projectinfo/ics/epicsCollaborationMtg/serialSupport.ppt)__[/](http://www.sns.gov/projectinfo/ics/epicsCollaborationMtg/serialSupport.ppt)__[projectinfo](http://www.sns.gov/projectinfo/ics/epicsCollaborationMtg/serialSupport.ppt)__[/](http://www.sns.gov/projectinfo/ics/epicsCollaborationMtg/serialSupport.ppt)__[ics](http://www.sns.gov/projectinfo/ics/epicsCollaborationMtg/serialSupport.ppt)__[/](http://www.sns.gov/projectinfo/ics/epicsCollaborationMtg/serialSupport.ppt)__[epicsCollabMtg](http://www.sns.gov/projectinfo/ics/epicsCollaborationMtg/serialSupport.ppt)__[/](http://www.sns.gov/projectinfo/ics/epicsCollaborationMtg/serialSupport.ppt)__[serialSupport](http://www.sns.gov/projectinfo/ics/epicsCollaborationMtg/serialSupport.ppt)__[.](http://www.sns.gov/projectinfo/ics/epicsCollaborationMtg/serialSupport.ppt)__[ppt](http://www.sns.gov/projectinfo/ics/epicsCollaborationMtg/serialSupport.ppt)_
- Device Manager for configuration
- Baud, parity, etc.
- Generic interface module
- Device specific plugin modules
- Construct and parse I/O strings

- Serial Support for Diamond - Pete Owens - Daresbury Laboratory

- EPICS Collaboration Meeting - May 2002

**Notes:**
This was developed at Oak Ridge specifically to overcome the limitations in devAscii in terms of delays and checksums.

It provides a mechanism whereby device specific plugin  modules can be added to customise the geniric serial interface device.

Each custom module provides a standard set of functions to generate and parse the strings being sent to and returning from the device.

It depends on the “device manager” application., This is quite a neat bit of code which handles the configuration of baud-rates, parity and so on on the serial line rather than cluttering up the startup script.

## ornlSerial - Experience

- Implemented plugin module for MKS 937A
- Added record support for standard ai & ao
- Coding straightforward
- tyGSOctal doesn’t implement
- ioctl (..., SIO_HW_OPTS_SET, ...)

*Device Manager*

- Serial Support for Diamond - Pete Owens - Daresbury Laboratory

- EPICS Collaboration Meeting - May 2002

**Notes:**
We found this straiht forward to use.

We implemented a plugin  for the MKS 937A.
And extended record support for ai and ao records (ORNL use their own)

The device manager didn’t do anything useful fo us because tyGSOctal doesn’t implement the relevent ioctl calls. But that didn’t prevent ornlSerial from working.

## ornlSerial - Evaluation

- Good points
- Useful for complex protocols (eg. checksums needed).
- ORNL features
- Non standard use of DISA field (warm start)
- Non standard ai/ao records
- However
- requires some programming for device-specific modules.

- Serial Support for Diamond - Pete Owens - Daresbury Laboratory

- EPICS Collaboration Meeting - May 2002

**Notes:**
This is a good way of handling complex protocols checksums and the like, which are beyond the capabilities of devAscii or stream device.

It does require some coding, but just the minimum needed to parse the strings, while the generic module does most of the work.

We did find one or two ORNL quirks.
 The DISA field is used unconventionally so that the IOC comes up in a disabled state. This is used to provide a ‘warm start’  feature.
 There was no record support for bog-standard ai and ao records - but it was easy enough to add ourseles.

## Summary

- All software built and worked
- minor glitches 68k / PPC
- Where existing support exists - use it
- For new development we like:
-  stream device *for most cases*
-  ornlSerial *for complex protocols/checksums*

- Serial Support for Diamond - Pete Owens - Daresbury Laboratory

- EPICS Collaboration Meeting - May 2002

**Notes:**
symFindByName doesn’t work on PPC - use symFindByNameEPICS

## Possible Developments

- Stream Device
- bus support module for device manager
- tyGSOctal
- SIO_HW_OPTS_SET ioctl call
- hot swap support
- ornlSerial
- record support for waveform record

- Serial Support for Diamond - Pete Owens - Daresbury Laboratory

- EPICS Collaboration Meeting - May 2002

**Notes:**
Although the device manager didn’t work for us it seems like a good idea To make it work will require:

 implementing the relevwent ioctl calls on tyGSOctal
 another bus support module for stream device.

VME64x and the Hytec IP carrier we used support hot-swap so it would be nice to add hot-swap capabilty to the tyGSOctal driver (though probly not straight-forward).

If we added waveform record support to ornlSerial then we could use this a basis for communicating with modbus devices.

## Serial Support for Diamond

- The End