From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Proper way to create parameter cluster for external DLL

Hi there, 

 

I am working in progress to to write a Labview program to evaluate programmability of a spectrometer. The example given from the vendor is VB&VC6 based pieces. But we use Labview in our core systems, hence trying to make it work for Labview. 

 

We don't have the DLL source code but a .h file that they provided with the DLL.(tried to use Labview import wizard but always stuck at generating VI. Then we get on manual approach)

 

The DLL takes struct as input parameter for 2 core functions. BOOL __stdcall HAAS_Init(SpectData &spData);  and void __stdcall HAAS_GetSpectData(SpectData &spData);

 

My quick program have successfully get part of the HAAS_init working. But every time HAAS get SpectData is called, the Labview exits with access violation error or just shutdown without any warning. My immediate thought is the array portion in the cluster causing the problem. But i could not think of a better way to put it into the cluster or get around it. 

 

 

 

the attached are the DLL, H file, manual and my VI. The HAAS_GetSpectData part can be run without equipment connected (as far as i tested from VB example) 

 

 

 

thank you

0 Kudos
Message 1 of 14
(3,538 Views)

Is the DLL written in .NET, C, or vb6?

 

If it's written in .NET I would recommend using the .net constructors and property nodes, much easier interface than the dll library calls, which are a pain.

 

If not let me know and we can move to the next idea.

 

Cheers,

 

Tim

0 Kudos
Message 2 of 14
(3,514 Views)

Hi Tim, 

 

It is most likely written in VC from what I have know from the company. 

0 Kudos
Message 3 of 14
(3,506 Views)

Hi,

That is always somehow a pain.

Try reading these articles:

http://digital.ni.com/public.nsf/allkb/5FE3C48E8E1C3D018625722900681AF6

http://digital.ni.com/public.nsf/allkb/6b3c4e8049d01e9186257e9f00771764

CLA, CTA, LV Champion
View Cyril Gambini's profile on LinkedIn
This post is made under CC BY 4.0 DEED licensing
0 Kudos
Message 4 of 14
(3,504 Views)

I got some progress with debugging. but the struct seems becoming more confusing. 

On the upside, it seems to me the int parts of the parameters are coming in correctly. like m_iHaveData is showing 1 as it is supposed to indicating there is feed back results. 

 

The red circled portion of m_fintTime and M_finterval could be where the problems are at. It almost feel like 2 chuck of data got cramped into 2 field. However, the struct in .h file does not say anything like it. 

 

 

 

Capture2.PNG

 

Capture.PNG001.png

0 Kudos
Message 5 of 14
(3,472 Views)

A long time ago, I had to do something like this. I had to insert 'fake' data into my cluster to match expected types inside the DLL. This was due to LV way to organize memory.

I know there is a KB on this, but I can't find it today. I found this, but it is not exactly what I'm searching for.

And also that one with an interesting paragraph : Determining When to Resize Array and String Handles in Shared Libraries

 

Would you mind sharing the .h ?

CLA, CTA, LV Champion
View Cyril Gambini's profile on LinkedIn
This post is made under CC BY 4.0 DEED licensing
0 Kudos
Message 6 of 14
(3,467 Views)

I managed to get some more working until first array @  float m_fRelSpect[4001]

 

here attaches the H file and some of vendor's comment

 

Capture.PNG

0 Kudos
Message 7 of 14
(3,462 Views)

You need to make the m_fRelSpect element a cluster of 4001 elements; it cannot be a LabVIEW array. Easiest way to create such a massive cluster is to wire an empty array to Array to Cluster with the cluster size set to 4001, then create a control from the output and replace the existing array with that new cluster instead the overall cluster.

 

An alternate approach is to determine the size of the complete struct, allocate that many bytes using Initialize Array, and pass that array instead. Then you can parse out individual elements.

 

It's possible your cluster needs some additional padding bytes, I haven't checked.

 

There are lots of threads with similar questions on this forum. In particular look for posts from RolfK.

Message 8 of 14
(3,439 Views)

In fact, I have attempted to put empty array thru array to cluster node then tried to change the size. However, there seems to be a limit to cluster size that 4001 is rejected. I will look into your alternative method and see how that works out. 

 

thank you 

0 Kudos
Message 9 of 14
(3,436 Views)

A bit further cluster approach yield some result but still being quite a painful method. It is now pulling/showing results from DLL. 

It appears that the struct will require a cluster of 29 variables + array of 4001 + array of 15, totaling 4045 elements.

But I am having a hard time to create a cluster of 4045 elements. 

 

The next step is probably trying to create an array that contains both int and float to see what happens. 

 

 

Capture3.PNG002.png

0 Kudos
Message 10 of 14
(3,421 Views)