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.
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.
12-04-2007 05:32 AM
12-10-2007 05:26 AM
12-10-2007 08:49 AM
Thanks for your suggestion but I'm afraid that if the information to help me is in that article/code then I'm not bright enough to figure it out. The example in the article appears to require the size of the array to be known (the array dimension being part of the TD1 structure). Also, the way in which pointers are handled is so different in C# that I'm struggling to match the two up. Strictly speaking, the problem is probably more with understanding C# than LabVIEW.
Further suggestions welcome.
Cheryl
12-17-2007 04:48 AM
01-02-2008 04:06 AM
Hi Cheryl,
Just wondering if the above links were of any use? If you could let me know how your getting on that would be great, all the best and Happy New Year!
Regards,
01-02-2008 04:43 AM
Dear Rob
And a Happy New Year to you. I'm afraid I haven't got any further with this problem. I have checked out your link to the linked list info but this is not really what I need (I have used linked lists a few years ago so understand the concept). Also, the link in the earlier reply was for C++ code and does not translate to C#.
I have muddled on and managed to find, by experiment, the size of my output arrays in advance. I'm calling LabVIEW dlls which use some of the frequency analysis and order analysis toolkit functions. So, for example, when calculating the order magnitude plot from a set of data I have found that the output array is 77 elements shorter than the input. I'm sure that if I had time to look into all the calculations behind this that I could've determined that number but I'm a bit pushed for time. I determine the size of the input array at run time by reading the data from file then I allocate my output array to be 77 elements shorter. If worst comes to the worst, I thought I could always call the calculations twice, the first time passing back the size of the output array only, allowing me to then allocate the array and then call the function again with the array as output. Not the most efficient process.
To try and keep it simple, a good example would be if I were passing an array of data from C# to a LabVIEW dll which discards all values below a threshold and returns an array of values greater than or equal to that threshold. I don't know in advance how big my output array would be. Where I do know the array sizes I am using code like this:
int iArrayInLength = 100;
double[] adArrayIn = new double[iArrayInLength];
//....populate adArrayIn here from e.g. file or user input
int iArrayOutLength = iArrayInLength - 10;
double[] adArrayOut = new double[iArrayOutLength];
IntPtr ptrdArrayOut = Marshal.AllocHGlobal(iArrayOutLength* 8);
//call dll
MyLabVIEWDLL(adArrayIn, ptrdArrayOut, iArrayInLength, iArrayOutLength);
//retrieve array from pointer
Marshal.Copy(ptrdArrayOut , adArrayOut , 0, iArrayOutLength);
Marshal.FreeHGlobal(ptrdArrayOut );
Obviously, I can't allocate the output array before I pass it without knowing the size and, when creating the LabVIEW dll, the length of the output array is also requested.
I imagine that there is some sort of equivalent to the method using handles in C++ but I just can't work out what it is.
Cheryl
01-02-2008 05:44 AM
Hi Cheryl,
I see your reasoning for not wishing to use Linked Lists, I'm afraid that I've personally done very little c# in the past so am unable to offer you much more assistance with regards to your c# code. I have found a few documents on google relating to Handles in c# via the "ref" keyword but none with example code. I would recommend looking into open source forums for c# and finding out the best way to allocate your array memory.
Apologies I can't be of more help,
All the best,