LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing Cluster Containing Strings in C DLL as Struct

Solved!
Go to solution

So like the attached example? This doesn't seem to work. Though I may be missing something.

0 Kudos
Message 11 of 24
(2,868 Views)
Solution
Accepted by KeenanJohnson

Please be more specific than "doesn't work." Do you get an error, bad data, or some other problem?

 

The number of bytes to copy is 4x the array length, because each array element is 4 bytes. You are only allocating enough space for 1/4 of the array elements, and then only copying 1/4 of them.

Message 12 of 24
(2,865 Views)

Ah yes that appears to have solved it. Thanks so much.

 

How did you figure out all of this? Trial and error? The documentation is pretty poor.

0 Kudos
Message 13 of 24
(2,862 Views)

Mostly from reading lots of posts on this forum, especially the ones by RolfK; but also several years of C programming; a little trial and error; and reading the documentation, even though it's sparse.

0 Kudos
Message 14 of 24
(2,857 Views)

Hello I have a similar problem : using Labview 2012 I have to pass a cluster parameter containing numeric values in C DLL developed with Visual C++ 20120 express (that configure serial channels on a Serial Board) as a Struct so defined :

 

struct ChannelInfoEx

{

ViInt16 interfaceType;

ViInt32 baudRate;

ViInt16 numBits;

ViInt16 stopBits;

ViInt16 parity;

ViUInt16 flowControl;

};

 

This parameter is passed to a VI as a AdaptToType with a format Handles by Value

 

All the fields of the struct (except interfacetype the first one) have a shifted values (stopbits has the value for parity numbits for stopbits and so on).

This problem is raised when I have deleted from the first filed of the struct (ViInt16 channelName) and I have tried to define all the fields as ViInt32 and the parameters are passed correctly.

Someone could help me and explain this strange behaviour ?? It's a Labview bug ??

There is a way to avoid to redefine all the fields as ViInt32 in the DLL ??

0 Kudos
Message 15 of 24
(2,663 Views)

Hello Sergin,

 

This link is going to guide you to a pdf called: Using external code in LabVIEW, there is a complete chapter on how to use external Dlls in LabVIEW

 

 

http://www.ni.com/pdf/manuals/370109a.pdf

Randy @Rscd27@
0 Kudos
Message 16 of 24
(2,649 Views)

Hey, 
I was facing a similar problem. Is the process same for double* pointers? Also what is the process if instead of a pointer i have an initialized array double arr[7]?
Thanks.

0 Kudos
Message 17 of 24
(348 Views)

@satagr wrote:

Hey, 
I was facing a similar problem. Is the process same for double* pointers? Also what is the process if instead of a pointer i have an initialized array double arr[7]?
Thanks.


A double is 8 bytes, So you need to account for that.

 

Fixed size arrays in a struct are inlined. A LabVIEW cluster with that many (7) doubles inside your outer cluster is the closest to this C construct.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 18 of 24
(327 Views)

Thanks! That helps a lot.

What about a cluster inside a cluster?

0 Kudos
Message 19 of 24
(314 Views)

@satagr wrote:


What about a cluster inside a cluster?


Not sure what you are asking here.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 20 of 24
(309 Views)