D2000 OBJApi - Interface structures

From the version D2000 V9.02.034, there is available both 32 and 64-bit version with modified header file for use in the projects with the interpretation of text strings in 8-bit form (ANSI) or 16-bit form (wide character UNICODE), according to the parameter of the project "Character Set" in MS Visual Studio.

UniVal structure


UniVal contains all information about the value and status of a given object of the D2000 system.

Declaration in C language:

typedef struct _UniVal
 {
     GenValueType gvaltyp;
     unsigned int status;
     tLimitStatus limitStatus;
     tProcAlarmType procAlarmStatus;
     ValueType type;
     double valtime;
     double procAlarmTime;
     unsigned int Flags;
     VOBJ Indirect;
     union
     {
         tBVal Boval;
         int Intval;
         double Realval;
         StVal Stval;
         struct
         {
             AlVal Alval;
             double AlTimes[4];
         } a;
         PrVal Prval;
         double TmAval;
         double TmRval;
         tQValue QVal;
         char *TxtVal;
         ArrayRecPtr ArrayValPtr;
         struct
         {
             ArrayRecPtr recordValPtr;
             HOBJ StructTypId;
             int ColsNr;
         } r;
     } v;
 } UniVal;

Description of individual structure parts:


The variable part, holding its own object value:


!!! WARNING !!!
Since the D2000 version 7.0, the item a.AlTimes is not used and therefore has been renamed to a.AlTimes_Unused. The items of the array are filled with the value of 0.0.

Warning for some value types:

UniVal contains only references to values for objects of Text and Array types. Values are created dynamically and it is necessary to release them calling the function FreeData. Exceptions are asynchronous calling the function NewValueProc (ObjAPI releases the values after return from the callback) and the function ListOfObjects (values are released by calling the function FreeData that releases structures of ListObjData type).

Representation of arrays and structures


Arrays and structures are represented by a value array of UniVal type, before which there is low (lowIndex) and high (hiIndex) indexes. Array items are indexed from 1. Before hiIndex, there are the following individual values in rows in successive steps.

typedef struct _ArrayRec
 {
     int lowIndex;
     int hiIndex;
 } ArrayRec;
 typedef ArrayRec * ArrayRecPtr;

Access to a structure item (row, column) is represented by the following function:

UniValPtr GetRecordItem(UniVal value, int row, int col)
 {
     UniValPtr uni_Ptr;
     int valueIdx;
     valueIdx = (row-1)*value.v.r.ColsNr+col - 1;
     // first value address
     uni_Ptr = (UniValPtr)((char *)value.v.r.recordValPtr +
               sizeof(*value.v.r.recordValPtr));
     uni_Ptr = &(uni_Ptr[valueIdx]);
     return uni_Ptr;
 }

When calling interface procedures, it is important to correctly enter the indexes !!!