Showing results for 
Search instead for 
Did you mean: 

Pico Tech High resolution Data Logger ADC24 - What does this sample code do?


I am programing a PicoTech HRDL ADC24 to log data in LabVIEW15. In the snapshot attached, the stacked sequence sets up the 16 channels (Have they never heard of a For loop??). The outer While loop then runs to take continuous measurements. My question concerns the code inside the red box: What are they doing here? The 'values' array is split into two before the index (noOfValuesPerCh*noOfChannels), which makes sense, as this selects the datapoints required from the initial array of size 1000. This 'important array' is then inserted into a differerent array coming from the shift register (i.e holds all the previous datapoints). The appended array then goes to the shift register. My question is: Why are they starting with an array of size 1000? Couldn't they just wire a zero to a build array function and wire that into the function? Then the array being put out would have all the desired datapoints, so n o need for cutting the array, no?
Cheers in advance

0 Kudos
Message 1 of 7

Why do you make it so hard for us to help?  I can't see sufficient detail in that tiny picture to tell anything, to say nothing of being able to examine other parts of the code that might provide a clue (hint -- never show a static picture unless you deliberately want to hide information from your viewer -- attach an entire VI, or (even better) an entire Project as a Zip file resulting from compressing its folder).


However, without seeing the code (I can't make out details), I can venture a guess why someone might allocate an array of 1000 items rather than attempt to build it up one at a time -- "memory efficiency".  If you allocate the entire array at once, then you only make a single trip to the "Memory allocation" well.  If you build it up one element at a time using Build Array, you are allocating/deallocating memory multiple times.


Bob Schor

0 Kudos
Message 2 of 7

Just guessing here. (Rolfk would know the answer.)


The code is calling a dll with an array. The dll probably needs a non-zero value in order to allocate memory. My guess is that if you wire a zero sized array you will get a memory corruption/exception error and LabVIEW will crash.




0 Kudos
Message 3 of 7

@Bob_Schor: the picture is 2076x1027px, which should be quite visible... And of course I would have attached a proper vi, if this would have helped. However, I did not believe it helped as you would need the .dll to stop LabVIEW from complaining. Even with the .dll, you would still need the instruments to run anything and even get to the point of my enquiry. This question was not "Why doesn't this work", in which case your complaint would have been warranted, but a mere "Why would you do that?", were a picture, I believe, is sufficient.

0 Kudos
Message 4 of 7

@mcduff: I had a similar brainwave. I have no knowledge of C (the functions are written in C), but from Java I recall that an error would be thrown if the function tries to insert at an index that is out of bounds. So the array of size 1000 makes sure that there is enough space for the function to write to, I guess.

0 Kudos
Message 5 of 7

@bockdoug wrote:

@mcduff: I had a similar brainwave. I have no knowledge of C (the functions are written in C), but from Java I recall that an error would be thrown if the function tries to insert at an index that is out of bounds. So the array of size 1000 makes sure that there is enough space for the function to write to, I guess.

Yes - you are exactly right. When you pass data into a C DLL in LabVIEW, you do it by passing in a 'placeholder' of the correct size/datatype as you're expecting to be returned by the DLL. It will then tell you how many items were returned so you can 'trim' the array to the correct size afterwards (if it's returning a different number of elements each time rather than a fixed size array). Looking at the function prototype, you have the 'noOfValues' parameter, which should either specify the 'number of items to read' (and as such would be the same as your array size) and/or return the 'number of items I'm giving you' which would allow you to then resize the array accordingly. The headers/documentation for the function would give you that information.

LabVIEW Champion, CLA, CLED, CTD
MediaMongrels Ltd. - NI Alliance Partner (blog)
0 Kudos
Message 6 of 7

Having dealt with some PicoTech equipment in the past, I share your frustration.

(Disclaimer - I haven't looked at this picture. I reckon from the description and my experience of Pico I know what it looks like.)


I will say quite openly that there is nothing that I have encountered when dealing with their products before to prevent you using an array of Zero values.


I often spend time re-writing/re-wrapping their dll calls so that I can call multiple instances should I so wish.


1) The decision to reuse the array is a misunderstood LabVIEW programming practice by Pico to try to prevent multiple instances of the array being defined in memory (on the PC). They reuse an existing array and overwrite the data to try to prevent memory leaks. There is no reason why you cannot define the array yourself as you wish. You just need to be aware that the Pico DLL will be updating the memory space on the PC, so you must handle the reference to it in LabVIEW carefully so that you don't leak memory that you can't clear.

2) The array size of 1000 seems to be a common thing accross their products and is probably to give them the extra 24 elements of the array for thier own data whilst remaining within a 1024 data transmission size.

3) You could Initialise an array of 1000 elements of zeros and pass that in, but not pass in zero via a build array as that will result in a memory leak due to the dll not knowing where save the data in memory on the PC. - (As Sam has said)

4) You will need to post process the results array and "cut it" to get the data which you are interest in only.



CLD; LabVIEW since 8.0, Currently have LabVIEW 2012 - 2016 installed
0 Kudos
Message 7 of 7