V4 CA example timeStamp, sevr, status, data

From EPICSWIKI

EPICS: timeStamp, severity, status, data example

July 28 2005


Overview

NOTE: This proposal has nothing to do with the discussion about dataAccess. The code that implements statSevrTimestampData can be implemented via dataAccess.

This describes an example of code for a CA client that wants to get the timeStamp, severity, status, and data value. The example wants to receive a scalar that has a primitive data type.

The code is psuedo code that could be translated into Java or C++. Primitive data types are passed by value and all objects by reference. The primitive data type are: octet, int16, int32, int64, float32, and float64. Each primitive type has an associated object type, i.e. Octet is an object containing an octet.

The code assumes that some library defines and implements statSevrTimestampData, which is code that knows how to call Channel Access to read and monitor a process variable that has a timeStamp, severity, status, and an scalar primitive type.

Example code

The following is the psuedo code to read the timestamp, status, severity, and an array of data.

The following is the class definition created by the user code:

    class MyTsStatSevr implements TsStatSevrDataCallback{
        TsStatSevrData tsStatSevrData;
        float64 value; 
        void success(TsStatSevrDataAccess server) {
            Float64Array array(data);
            server.get(tsStatSevrData,value);
            // all data has been received. Do something with it
        };
        void exception(NaString reason) { /*do something*/};
    };

The code to request a read is:

    MyTsStatSevr myTsStatSevr = new MyTsStatSevr;
    // Must create buffer for TsStatSevr.status
    NaTsStatSevrRequest request = // must locate somehow;
    ...
    request.read(myTsStatSevr);
    ...

Discussion:

  • Most class, struct, and interface definitions except MyTsStatSevr are described below. However EpicsString is not described. It are similar to what was described in previous wikis.
  • TsStatSevrDataCallback contains just two methods: success and exception. MyTsStatSevr implements these. They are callback methods that are called when the requested data is received from the server.
  • The example does not show how to allocate the buffer manager for EpicsString.
  • The example does not show how to connect to the pv or locate interface NaTsStatSevrRequest. This example is only concerned with how data is obtained.

statSevrTimestampData

This section describes the definitions for statSevrTimestampData, which is code that makes Channel Access requests to obtain data as well as the associated timeStamp, status, and severity.

    struct TsStatSevr {
       int16       severity;
       EpicsString status;
       EpicsTimeStamp timeStamp;
    };
    interface TsStatSevrDataAccess {
         void get(TsStatSevr tsStatSevr, Bool value);
         void get(TsStatSevr tsStatSevr, Int16 value);
         void get(TsStatSevr tsStatSevr, Int32 value);
         void get(TsStatSevr tsStatSevr, Int64 value);
         void get(TsStatSevr tsStatSevr, Float32 value);
         void get(TsStatSevr tsStatSevr, Float64 value);
    };
    interface TsStatSevrDataCallback {
        void success(TsStatSevrDataAccess server);
        void exception(NaString reason);
    }


    interface NaTsStatSevrRequest {
        void read(TsStatSevrDataCallback callback);
        void cancel();
    };
  • TsStatSevr is a container that holds the severity, status, and timeStamp. The

container is created by the user.

  • TsStatSevrDataAccess is an interface implemented by statSevrTimestampData.
  • TsStatSevrDataCallback is an interface implemented by the user. When the statSevrTimestampData code receives data from channel access it call this interface so that the user can get the data that was received from the server.
  • NaTsStatSevrRequest is an interface implemented by statSevrTimestampData. The user calls this interface to request data.