Changeset 14


Ignore:
Timestamp:
Feb 14, 2009 10:31:56 PM (15 years ago)
Author:
hammonds
Message:

Add in functions to create and then parse data from channel specifying the structure to be created by DBR type. This is added to aid in getting data from a channel using the expanded data types like DBR_CTRL_FLOAT.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • caPython/captr.i

    r8 r14  
    1313
    1414#include <ctype.h>
     15
     16
     17static PyObject *ptrvalue2(void *_PTRVALUE, int TYPE, int COUNT) {
     18    PyObject *d = NULL;
     19        if(dbr_type_is_plain(TYPE)) {
     20            d = unpackPlainGet((union db_access_val *)_PTRVALUE, TYPE, COUNT);
     21        }
     22        else if(dbr_type_is_STS(TYPE)) {
     23            d = unpackStatusGet((union db_access_val *)_PTRVALUE, TYPE, COUNT);
     24        }
     25        else if(dbr_type_is_TIME(TYPE)) {
     26            d = unpackTimeGet((union db_access_val *)_PTRVALUE, TYPE, COUNT);
     27        }
     28        else if(dbr_type_is_GR(TYPE)) {
     29            d = unpackGraphicGet((union db_access_val *)_PTRVALUE, TYPE, COUNT);
     30        }
     31        else if(dbr_type_is_CTRL(TYPE)) {
     32            d = unpackControlGet((union db_access_val *)_PTRVALUE, TYPE, COUNT);
     33        }
     34        else
     35            printf("getCallback: Unknown DBR type for get!\n");
     36
     37        return d;
     38}
    1539
    1640
     
    270294
    271295/*------------------------------------------------------------------
     296  ptrcreate_by_dbr(type, value=0, numelements=1)
     297  Attemts to create a new object appropriate for the given DBR type
     298  This is like ptrcreate exept that type is given by DBR type and this
     299  does allow for the creation of more complicated data types needed by
     300  more complicated DBR types like DBR_CTRL_XXX
     301--------------------------------------------------------------------*/
     302   static PyObject *ptrcreate_by_dbr(int type, PyObject *_PYVALUE, int numelements) {
     303   PyObject *obj = NULL;
     304   void * val;
     305/* Check to see if DBR type is valid */
     306   if (INVALID_DB_REQ(type)){
     307     PyErr_SetString(PyExc_TypeError, "Value for Type is out of range.");
     308        return NULL;
     309   }
     310   val= malloc(dbr_size_n_macro( type, numelements));
     311/* Attempt to Classify DBR type */
     312   if (type == DBR_STRING) {
     313     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_string_t *"), 0);
     314   }   
     315   else if (type == DBR_SHORT) {
     316     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_short_t *"), 0);
     317   }   
     318   else if (type == DBR_INT) {
     319     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_int_t *"), 0);
     320   }   
     321   else if (type == DBR_FLOAT) {
     322     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_float_t *"), 0);
     323   }   
     324   else if (type == DBR_ENUM) {
     325     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_enum_t *"), 0);
     326   }   
     327   else if (type == DBR_CHAR) {
     328     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_char_t *"), 0);
     329   }   
     330   else if (type == DBR_LONG) {
     331     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_long_t *"), 0);
     332   }   
     333   else if (type == DBR_DOUBLE) {
     334     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_double_t *"), 0);
     335   }   
     336   else if (type == DBR_STS_STRING) {
     337     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_sts_string *"), 0);
     338   }   
     339   else if (type == DBR_STS_SHORT) {
     340     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_sts_short *"), 0);
     341   }   
     342   else if (type == DBR_STS_INT) {
     343     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_sts_int *"), 0);
     344   }   
     345   else if (type == DBR_STS_FLOAT) {
     346     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_sts_float *"), 0);
     347   }   
     348   else if (type == DBR_STS_ENUM) {
     349     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_sts_enum *"), 0);
     350   }   
     351   else if (type == DBR_STS_CHAR) {
     352     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_sts_char *"), 0);
     353   }   
     354   else if (type == DBR_STS_LONG) {
     355     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_sts_long *"), 0);
     356   }   
     357   else if (type == DBR_STS_DOUBLE) {
     358     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_sts_double *"), 0);
     359   }   
     360   else if (type == DBR_TIME_STRING) {
     361     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_time_string *"), 0);
     362   }   
     363   else if (type == DBR_TIME_SHORT) {
     364     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_time_short *"), 0);
     365   }   
     366   else if (type == DBR_TIME_INT) {
     367     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_time_int *"), 0);
     368   }   
     369   else if (type == DBR_TIME_FLOAT) {
     370     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_time_float *"), 0);
     371   }   
     372   else if (type == DBR_TIME_ENUM) {
     373     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_time_enum *"), 0);
     374   }   
     375   else if (type == DBR_TIME_CHAR) {
     376     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_time_char *"), 0);
     377   }   
     378   else if (type == DBR_TIME_LONG) {
     379     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_time_long *"), 0);
     380   }   
     381   else if (type == DBR_TIME_DOUBLE) {
     382     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_time_double *"), 0);
     383   }   
     384   else if (type == DBR_GR_STRING) {
     385     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_gr_string *"), 0);
     386   }   
     387   else if (type == DBR_GR_SHORT) {
     388     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_gr_short *"), 0);
     389   }   
     390   else if (type == DBR_GR_INT) {
     391     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_gr_int *"), 0);
     392   }   
     393   else if (type == DBR_GR_FLOAT) {
     394     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_gr_float *"), 0);
     395   }   
     396   else if (type == DBR_GR_ENUM) {
     397     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_gr_enum *"), 0);
     398   }   
     399   else if (type == DBR_GR_CHAR) {
     400     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_gr_char *"), 0);
     401   }   
     402   else if (type == DBR_GR_LONG) {
     403     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_gr_long *"), 0);
     404   }   
     405   else if (type == DBR_GR_DOUBLE) {
     406     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_gr_double *"), 0);
     407   }   
     408   else if (type == DBR_CTRL_STRING) {
     409     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_ctrl_string *"), 0);
     410   }   
     411   else if (type == DBR_CTRL_SHORT) {
     412     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_ctrl_short *"), 0);
     413   }   
     414   else if (type == DBR_CTRL_INT) {
     415     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_ctrl_int *"), 0);
     416   }   
     417   else if (type == DBR_CTRL_FLOAT) {
     418     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_ctrl_float *"), 0);
     419   }   
     420   else if (type == DBR_CTRL_ENUM) {
     421     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_ctrl_enum *"), 0);
     422   }   
     423   else if (type == DBR_CTRL_CHAR) {
     424     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_ctrl_char *"), 0);
     425   }   
     426   else if (type == DBR_CTRL_LONG) {
     427     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_ctrl_long *"), 0);
     428   }   
     429   else if (type == DBR_CTRL_DOUBLE) {
     430     obj = SWIG_NewPointerObj(val, SWIG_TypeQuery("dbr_ctrl_double *"), 0);
     431   }   
     432     
     433   Py_INCREF(obj);
     434   return obj;
     435
     436}
     437/*------------------------------------------------------------------
    272438  ptrset(ptr,value,index = 0,type = 0)
    273439
     
    473639                     PyObject *ptrset,
    474640                     PyObject *ptradd,
    475                      PyObject *ptrfree 
     641                     PyObject *ptrfree,
     642                     PyObject *ptrcreate_by_dbr,
     643                     PyObject *ptrvalue2
    476644{
    477645#if defined(SWIGPYTHON)
     
    508676
    509677PyObject *ptrvalue(PyObject *ptr, int index = 0, char *type = 0);
     678// Returns the value that a pointer is pointing to (ie. dereferencing).
     679// The type is automatically inferred by the pointer type--thus, an
     680// integer pointer will return an integer, a double will return a double,
     681// and so on.   The index and type fields are optional parameters.  When
     682// an index is specified, this function returns the value of ptr[index].
     683// This allows array access.   When a type is specified, it overrides
     684// the given pointer type.   Examples :
     685//
     686//    ptrvalue(a)             #  Returns the value *a
     687//    ptrvalue(a,10)          #  Returns the value a[10]
     688//    ptrvalue(a,10,"double") #  Returns a[10] assuming a is a double *
     689
     690PyObject *ptrvalue2(void *ptr, int type , int count);
    510691// Returns the value that a pointer is pointing to (ie. dereferencing).
    511692// The type is automatically inferred by the pointer type--thus, an
     
    532713
    533714PyObject *ptrcreate(char *type, PyObject *value = 0, int nitems = 1);
     715PyObject *ptrcreate_by_dbr(int type, PyObject *value = 0, int nitems = 1);
    534716// Creates a new object and returns a pointer to it.  This function
    535717// can be used to create various kinds of objects for use in C functions.
Note: See TracChangeset for help on using the changeset viewer.