07-26-2017 01:17 PM - edited 07-26-2017 01:41 PM
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
07-26-2017 01:48 PM
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
07-26-2017 01:56 PM
Hi Tim,
It is most likely written in VC from what I have know from the company.
07-26-2017 02:03 PM
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
07-26-2017 06:27 PM
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.
07-26-2017 07:34 PM - edited 07-26-2017 07:38 PM
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 ?
07-26-2017 07:49 PM
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
07-27-2017 08:35 AM
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.
07-27-2017 12:48 PM
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
07-27-2017 07:03 PM
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.