LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

pointer on cluster and retrieve pointer value

Hi,

 

I am trying to adapt a program called GeoTrans in LabVIEW. For that, I created a DLL from the source files of the program.

So now, my first problem: how do I get the value from a pointer?

 

eg code:

long DLLexport Get_Datum
( const File_or_Interactive State,
  const Input_or_Output     Direction,
  long                      *Index )
/*
 *  The function Get_Datum returns the index of the current datum for the
 *  specified state.
 *  State      : Indicates whether the datum is to be used for interactive
 *               or file processing                                    (input)
 *  Direction  : Indicates whether the datum is to be used for input or
 *               output                                                (input)
 *  Index      : Identifies the index of the current datum             (input)
 */
{ /* Get_Datum */
  long error_code = ENGINE_NO_ERROR;
  if (!Engine_Initialized)
    error_code |= ENGINE_NOT_INITIALIZED;
  if (!Valid_Direction(Direction))
    error_code |= ENGINE_INVALID_DIRECTION;
  if (!Valid_State(State))
    error_code |= ENGINE_INVALID_STATE;
  if (!error_code)
  {
    *Index = CS_State[State][Direction].datum_Index;
  }
  return (error_code);
} /* Get_Datum */

 

Then, I need to get the value attached to the *Index pointer, so that I can use it later here:

 

long DLLexport Set_Datum
( const File_or_Interactive State,
  const Input_or_Output     Direction,
  const long                Index )
/*
 *  The function Set_Datum sets the datum for the specified state to the
 *  datum corresponding to the specified index.
 *  State      : Indicates whether the datum is to be used for interactive
 *               or file processing                                    (input)
 *  Direction  : Indicates whether the datum is to be used for input or
 *               output                                                (input)
 *  Index      : Identifies the index of the datum to be used          (input)
 */
{ /* Set_Datum */
  long error_code = ENGINE_NO_ERROR;
  if (!Engine_Initialized)
    error_code |= ENGINE_NOT_INITIALIZED;
  if (!Valid_Direction(Direction))
    error_code |= ENGINE_INVALID_DIRECTION;
  if (!Valid_State(State))
    error_code |= ENGINE_INVALID_STATE;
  if (!Valid_Datum_Index(Index))
    error_code |= ENGINE_INVALID_INDEX_ERROR;
  if (!error_code)
  {
    CS_State[State][Direction].datum_Index = Index;
  }
  return (error_code);
} /* Set_Datum */

 

 

----> How do I do that?

 

Second question: the C program contains a bunch of typedef struct -- that I just decided to transform into clusters in LabVIEW; because I did not know any other way to do it.

 

eg: typedef struct Mercator_Tuple_Structure
{
  double  easting;     /* meters */
  double  northing;    /* meters */
} Mercator_Tuple;

Put this into Cluster. now, I need to feed this structure as a pointer:

 

long DLLexport Get_Mercator_Coordinates
( const File_or_Interactive State,
  const Input_or_Output     Direction,
  Mercator_Tuple            *coordinates)
/*
 *  The function Get_Mercator_Coordinates returns the Mercator projection
 *  coordinates for the specified state.
 *  State          : Indicates whether the coordinates are to be returned for
 *                   interactive or file processing                    (input)
 *  Direction      : Indicates whether the coordinates are to be returned for
 *                   input or output                                   (input)
 *  coordinates    : Mercator projection coordinates to be returned    (output)
 */
{ /* Get_Mercator_Coordinates */
  long error_code = ENGINE_NO_ERROR;
  if (!Engine_Initialized)
    error_code |= ENGINE_NOT_INITIALIZED;
  if (!Valid_Direction(Direction))
    error_code |= ENGINE_INVALID_DIRECTION;
  if (!Valid_State(State))
    error_code |= ENGINE_INVALID_STATE;
  if (!error_code)
  {
    if (CS_State[State][Direction].type != Mercator)
      error_code |= ENGINE_INVALID_TYPE;
    else
      *coordinates = CS_State[State][Direction].coordinates.Mercator;
  }
  return ( error_code );
} /* Get_Mercator_Coordinates */

 

So now, how to I get the coordinates??? Also, how to I feed the cluster as a pointer?

Or maybe there's a better way to do this?

 

HELP!

 

Thanks,

 

Montezumist.

0 Kudos
Message 1 of 3
(2,246 Views)

oops, here is where I need to use the value of the pointer on Index.

 

long DLLexport Get_Datum_Index ( const char *Code,
                       long *Index )
/*here,  the index is the output*/
  long error_code = ENGINE_NO_ERROR;
  long temp_error;

  if (!Engine_Initialized)
    error_code |= ENGINE_NOT_INITIALIZED;
  else
  {
    temp_error = Datum_Index (Code, Index);
    if (temp_error == DATUM_INVALID_CODE_ERROR)
      error_code |= ENGINE_INVALID_CODE_ERROR;
    else if (temp_error != DATUM_NO_ERROR)
      error_code |= ENGINE_DATUM_ERROR;
  }
  return (error_code);
} /* Get_Datum_Index */

 

How do I get the value of Index out???

0 Kudos
Message 2 of 3
(2,238 Views)

Hi, here are three things to know about pointers.

 

if "index" is a pointer, you declare it as int *index.  It stores the memory address of an integer somewhere.  When you call index in the main code body, it is done in three ways

 

typing *index returns the integer value at the memory location that is the numbe stored in index

 

typing index returns the number that is the memory location

 

if the vlaue at that memory location has a name itself (it doesn't need to)  you can get its memory location using "&".  Example

 

int X = 5      //  X is assigned a random memory address

 

index = &X    // index gets the value of the memory address X is stored in

 

*index   // this will return the value of X

 

 

So to get a pointer of your cluster, simply assign an index (without the *) as &"your cluster name"

 

To get the value of the memory address just use the pointer name without the *

 

Does this answer you question?

 

Chris Bakker
SET Americas
CEO

0 Kudos
Message 3 of 3
(2,212 Views)