LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

C language *Pointer equivalent in LabVIEW

I am developing LabVIEW drivers to access some hardware.
The company does provide DLL's that will drive their hardware.
This code is written in C, has the include files, and source code
for their test programs. The problem, and my question, is that
their code contains structures with pointers to other structures.
Here is an example:
 
 
if ( SUCCESS != sdpCreate(&SdpRef, &SdpCollect))
 
Where SdpCollect:
 
SDP_COLLECTIONS SdpCollect;
 
typedef struct
{
 SDP_COLLECTION_TYPE Type;
     union
     {
          IO_DEVICE_COLLECTION  *pDeviceCollection;
          CARD_COLLECTIONS        *pCardCollections;
          CARRIER_COLLECTIONS  *pCarrierCollections;
     } Dev;
} SDP_COLLECTIONS
 
typedef enum
{ ...
} SDP_COLLECTION_TYPE;
 
typedef struct _CARRIER_COLLECTIONS CARRIER_COLLECTIONS;

struct  _CARRIER_COLLECTIONS
{
     INT    nSlots;
     struct
     {
          SLOT_STATUS   Status;
          CARD_COLLECTIONS *pCard;
     } Slot[MAX_IP_SLOTS];
     IP_CARRIER CarrierHandle;
};
 
 
typedef enum
{ ...
} SLOT_STATUS;
 
struct _CARD_COLLECTIONS
{
     AXIS_COLLECTION   *pAxisCollection;
     IO_COLLECTION   *pIoCollection;
     THERM_COLLECTION  *pThermCollection;
     SIGNAL_PROC_COLLECTION *pSbCollection;
     IO_CARD  Handle;
};
 
I did not include everything because this gets cumbersome.
The point I am trying to make is that they have imdebed in
their structures, pointers to other structures. I have not used
C in a long time and at least that is what I believe they are
doing. If not, please correct me.
 
Anyway, my problem and question, is there a way in LabVIEW
to put a pointer to a cluster into a element in another cluster
simliar to what is being done in this C code? Is the Reference
structure to a data element the same thing as it's address in
memory? Does one of the control properties return it's address
in memory? Do I need to buy a C compiler and build my own
interface between LabVIEW and their DLL?
 
Thank you for any help you can give.
0 Kudos
Message 1 of 3
(3,286 Views)

I'm not sure what your question is exactly, but you won't be able to pass pointers from LabVIEW to your dll as they won't be sharing the same memory space, and as far as I know there isn't a direct coorelation in LabVIEW to having pointers from one data element to another within LabVIEW's memory space.

P.M.

Message Edited by LV_Pro on 09-12-2005 03:01 PM

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 2 of 3
(3,270 Views)
You have two problems here. First of all, LabVIEW's clusters within a cluster is an aggregate, not a reference (pointer), so simply duplicating the structure as a cluster and passing it off to the DLL won't work. Even if that problem didn't exist, there's also the issue of byte alignment. Most Windows modules use 8-byte structure alignment. LabVIEW uses 1-byte alignment. (More about alignment here and here.) This problem can be worked around by manually padding the 1-byte struct so that every real member ends on the appropriate boundary. Example:

//Structure as given for an 8-byte aligned module
struct given
{
   short  s1;
   long   l2;
   char*  p3;
   char   c4;
   void*  p5;
   double d6;
};

//How to create the structure if compiler is building with 1-byte alignment
struct given_padded
{
   short  s1;   //offset+0
   short  pad1; //offset+2
   long   l2;   //offset+4:  4 byte boundary
   char*  p3;   //offset+8:  4 byte boundary
   char   c4;   //offset+12: 1 byte boundary
   short  pad2; //offset+13
   char   pad3; //offset+15
   void*  p5;   //offset+16: 4 byte boundary
   long   pad4; //offset+20:
   double d6;   //offset+24: 8 byte boundary
}
So, probably what you will need to do is create a helper DLL that can convert LabVIEW's 1-byte aligned aggregated clusters into 8-byte aligned referenced structures and have that DLL call the driver.

Jason

Message Edited by Jason S on 09-13-2005 08:58 AM

Message 3 of 3
(3,243 Views)