Array of doubles filled by DLL contains weird values

Hello everyone
I am working on a DLL invocation which needs to resize and fill an array of doubles named 'values' (2nd to last parameter). I have defined the signature as follows:
_declspec (dllexport) uint8_t readDoubleArray(uint8_t handle, LStrHandle lPath, int64_t startTime,
int64_t endTime, DblArrHdl *values, LongArrHdl *timebase);
Where DblArrHdl is
typedef struct {
int32_t dimSize;
double doubles[1];
} DblArr;
typedef DblArr **DblArrHdl;
In the invocation I read doubles from a database, and resize the double array as follows:
int size = doubleArray.size();
if (NumericArrayResize(0x0A, 1, (UHandle*)values, size) != noErr) {
setLastError(MG_ERR_LABVIEW_ERROR, "Failed to allocate memory");
return FALSE;
 I set the size, and copy the values:
(**values)->dimSize = size;
for (int i = 0; i < size; i++) {
(**values)->doubles[i] = doubleArray[i];
When I use the DbgPrintF to validate the values it gives me a value around 120000 which is correct. However, when returned by labview the array contains strange data, like 5.38564E-315. Here is print out of the 'values' array after it has been through the DLL:
Here is how I wired it, ignore the clustering, it occurs in the array of values which exits the DLL call.
I have no idea how this can be. I followed the examples on the site. I also tried the normal DSSetHandleSize, but it didn't change anything. Any idea what I did wrong?
Thanks in advance,
Vincent
Message Edited by DaVince on 10-22-2008 10:10 AM
Solved!
Go to Solution.
Attachments:
doubleArrayWeird.png ‏7 KB
wireUpDoubles.png ‏18 KB

You're right, this not directly described...  
First you should read how LabVIEW stores data in memory,
then read about structure packing pragma,
and finally take a look to C/C++ preprocessor reference,
then you will get feeling how to solve this problem...
Otherwise own DLLs used in LabVIEW code pretty rarely, and Double precision also not very often...
The same trouble you may get with clusters, but here behaviour described:
"...The memory layout of a cluster depends on the platform you are running. LabVIEW may add padding between cluster elements so that those elements are aligned to certain address boundaries. Address boundaries relate to the concept of natural alignment. A piece of data is aligned on its natural boundary if the address at which it begins is a multiple of the size of the data. For example, a 4-byte integer is aligned naturally if it begins at an address which is a multiple of four. Most compilers have an upper limit on this boundary at which the restriction is relaxed. For instance, an 8-byte integer may be aligned on a 4-byte boundary. For the platforms on which LabVIEW runs, the alignment constraints are as follows:
(Windows) Data is aligned only to 1-byte boundaries.
(Mac OS and Linux) Data is aligned naturally up to 4-byte boundaries.
(VxWorks PowerPC) Data is aligned naturally up to 8-byte boundaries.
On all platforms, clusters adopt the alignment of their most restrictively aligned element..."
best regards and happy wiring...
Andrey.
Message Edited by Andrey Dmitriev on 10-23-2008 03:38 PM

Similar Messages

  • Transfering elements to new array and doubling values.

    Hi my problem is that I need to ask a user to enter 5 integers that stores them in an array. Transfer them to a new array by doubling the values when trasferred.
    Please help I have 3 errors.
    class arrays
         public static void main (String[] args)
              int numbers[] = new int [5];
              byte array1Size = 0;
              int input = 0;
              char goon = 'y';
                   //create and initialise an array of 5 integers
                   int array1[] = new int [5];
                   // loop and fill each element
                   for (int x = 0; x < array1.length; x++)
                        System.out.println("Enter a number: ");
                        array1[x] = EasyIn.getInt();
                        // Filling array
                        if (array1Size >= array1.length)
                             //Make a new array doubling the values od the integers
                             int array2 [] = new int [2 * array1.length]; // 10 integers
                             //Copying integers
                             System.arrayCopy (array1, 0, array2, 0, array1.length);
                             //Make old reference point to new array
                             array1 = array2;
                        else
                             //normal
                             do
                                  System.out.print("Enter an integer: ");
                                  input = EasyIn.getInt();
                                  anotherArray[anotherArraySize] = input;
                                  anotherArraySize++;
                                  System.out.print ("Another number? Enter Y or N: ");
                                  goon = EasyIn.getChar();
                             }     while(goon = = 'y' | goon = = 'Y');
    the errros >>>
    G:\Java\Practical 7\Practical74.java:33: '.class' expected
                             int array2 [] = new int [2 * array1.length]; // 10 integers
    ^
    G:\Java\Practical 7\Practical74.java:33: not a statement
                             int array2 [] = new int [2 * array1.length]; // 10 integers
    ^
    G:\Java\Practical 7\Practical74.java:41: 'else' without 'if'
                        else
    ^
    3 errors
    Tool completed with exit code 1
    Thanks

    Hi,
    it seems you forgot the curly braces in the if-else statement:
    if (array1Size >= array1.length){
    //Make a new array doubling the values od the integers
    int array2 [] = new int [2 * array1.length]; // 10 integers
    //Copying integers
    System.arrayCopy (array1, 0, array2, 0, array1.length);
    //Make old reference point to new array
    array1 = array2;
    else{
    //normal
    do
    System.out.print("Enter an integer: ");
    input = EasyIn.getInt();
    anotherArray[anotherArraySize] = input;
    anotherArraySize++;
    System.out.print ("Another number? Enter Y or N: ");
    goon = EasyIn.getChar();
    } while(goon = = 'y' | goon = = 'Y');
    }

  • How to write a 2-D Array of Doubles to a binary file in LabView 8.5?

    Okay, this is driving me nuts. I got a program that worked fine in LabView 8.0 but refused to write any data after my institute upgraded to LabView 8.5. The data is stored in a 2-D array of doubles and is supposed to be written to a binary file, that has been correctly opened and got a header written to it containing some meta-data of the measurement. But when the doubles from the array should be written to the file, nothing happens. All I get is an (except for the header) empty file of 786 kB. I found out that writing works if I convert the data from the array to singles right before wiring them to the "write to binary file" VI, but for several reasons I need the data as doubles. Can anyone help me? I've tried everything anyone has written here about writing to binary files and more.
    Remember, it worked perfectly fine with an older version of LabView. Any ideas?

    It is possible that you run into a known memory optimization bug.
    Try to place an "always copy" primitive as discussed here.
    Message Edited by altenbach on 11-18-2008 09:11 AM
    LabVIEW Champion . Do more with less code and in less time .

  • 2 D array of doubles

    I was wondering how to pass a 2D array of doubles through JNI?
    I am doing this so that I can change the 2D array to a Variant that contains a 2D array of SAFEARRAYS of doubles. Then I am going to invoke a method of a 3rd party software through COM.

    It's possible, but I believe that you'll be crazy using such an array in JNI (dereferencing lots of things etc.) and the performance will be very poor.
    You can do the following thing:
    - Convert the 2D array into a 1D array in Java code. It's faster in the Java side than doing it using JNI (basically you'll need to use a lot of System.arraycopy() calls and some multiplications and additions).
    - Transfer the 1D array to the JNI code
    - Convert it back to the Variant or SAFEARRAY(double) 2D array - I believe that if you've done the things right you'll need only to do a straight memcpy in the JNI code.

  • Cluster array to c structure in DLL

    Hello,
    I have a problem which I am stuck at so I would really appreciate any help.
    I have this function that i need to access in Labview.
    ViStatus _VI_FUNC Ki_GetSystemInfo (ViSession instrumentHandle,
    void *systemInfo);
    Now the structure for systeminfo is as follows:
    typedef struct _SYSTEM_INFO
    char pchModelNum[MODEL_NUM_LEN];
    char pchSerialNum[SERIAL_NUM_LEN];
    char pchSysSoftwareVer[SOFTVER_LEN];
    char pchPlatformVer[PLATVER_LEN];
    char pchOpSystemVer[SYSTVER_LEN];
    int bCardType[MAX_SLOTS]; // Enum slot_types
    } systeminfo;
    When i use the call Library Node function to access the above function what
    should be mine
    input and out paramteres. I tries making cluster of 5 st
    rings and an array
    of integers
    It doesnt seem to work. Any help shall be appreciated.
    Premal

    Hi Premal,
    Try to use arrays of [U8] instead of strings. Also, pay attention to INT - is OS dependent (assuming that you are using win9x/NT/2000, use [I32]). If you try with strings, be sure that the input string contains enough characters to store the result.
    Hope this helps
    p.s.: take a look on those articles mentioned in "cluster array to c structure in DLL" [http://exchange.ni.com/servlet/ProcessRequest?RHIVEID=101&RPAGEID=137&HOID=506500000005000000C05C0000&HTHREAD=000023744&UCATEGORY_0=_49_%24_6_&UCATEGORY_S=0]

  • Reading arrays of double from S7 with OPC & Datasocket

    Hi friends:
    We are developing an application with a S7-315-2DP PLC and a PC with a PCI1500PFB. We use the OPC server from Applicom. We read the data very quickly with the datasocket (arrays of boolean, arrays of doubles ...and so on, and a very big amount of data over 100 ms) but when we try to write arrays datasocket faield and we have to write item on item and the speed decrease. For intance, if we try to write doubles ( 50 items) the refresh period is over 5 seconds ( some times more since we launch the data and we read the same data on the PC). Perhaps we failed configuring the OPC but there isn´t many things to configure, perhaps the problem is the board configuration .. I don´t know.
    We
    try to find some examples that write an array of doubles on one time but..
    Thank you for yours answers.
    Javi

    Hi Javi,
    I'm not aware of any known issues writing to the Applicom OPC server. In LabVIEW there isn't anything special you need to configure to be able to write arrays of doubles through DataSocket. You can test this by using the DataSocket Server Manager, make a new member that is an array of doubles, and try reading and writing to that member. You may also want to check to make sure the data member the OPC server is expecting is an arry of doubles and not an array of singles or integers.

  • Resizing an array of struct inside a DLL using the memory manager

    Hi all,
    I dug deep inside the boards, but wasn't able to find a solution for my problem.
    I'm building a dll, which does some imageprocessing and should return an array of structs to labview, with one struct for every element in the image.
    As I don't know the number of elements beforehand and the limit of the number is numbers of magnitude larger then the expected one, I don't want to allocate such a huge chunk of memory prior to the dll call in labview.
    In a former version I used a 2d array for the elements, where each row holds the values of every element. Here I used the NumericArrayResize-function, which worked quite well. But I have to add more sub-processes and using structs (or clusters in labview) appears to be more usefull and cleaner for me, in addition I had to cast some of the elements back and foreward a few times.
    So one element-struct should hold 2 singles and 1 uint32. My question is now, how can I resize this array of struct with memory manager functions as the NumericArrayResize-functions does not suit this purpose?
    (Accessing a given array of structs inside the DLL and after that reading the changed values in Labview is surprisingly easy )
    Thanks in advance
    Solved!
    Go to Solution.

    Well, I was able to solve it myself. I found this thread, where the first post of rolfk made me thinking. It appeared to me, that the numericarrayresize-function behaves very similar to the realloc-function of c. So I used the type unsigned int 8 (which is just one byte) and multiplied it by the number of bytes used by one struct, in my case 12 bytes (4+4+4) and then multiplied it by the number of structs (elements in the image) i have. Luckily it worked and the memory block was resized exactly as I wanted it to be. Important to note: do not forget to adjust the size element of the handle, otherwise Labview does not know about the changed size.

  • Store an array containing CLLocation values, in NSUserDefaults

    Hi,
    Am working with location based application and need to store an array containing cllocation values, in userdefaults , have tried using :
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:yourArray forKey:@"clArray"];
    [defaults synchronize];  
    but it gives following error :
    [NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '( "<MapLocationVO: 0x169440>" )' of class '__NSArrayI'
    thanks in advance
    Regards

    Hi,
    from NSUserDefaults Class Reference:
    +The value parameter can be only property list objects: NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary. For NSArray and NSDictionary objects, their contents must be property list objects. See “What is a Property List?” in Property List Programming Guide.+
    The only way is to archive the array into an NSData-Object and store that data-object.
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:yourArray];
    [[NSUserDefaults sharedUserDefaults] setObject:data forKey:@"arrayKey"];
    Dirk

  • I need to display an array of doubles on a table and I am loosing my percision

    Hello,
    I need to display an array of doubles on a table but I am losing my decimal precision. I am converting the array to a string in order to display it on the table with a number to decimal function. This is where I lose my precision since that control converts the double into an integer and then into the string. What control do I need to use instead of that in order to preserve my decimal precision all the way to the table? I have attached my VI. Thanks in advance!
    Gregory Osenbach, CLA
    Fluke
    Attachments:
    canalyzer_prototype_1.vi ‏52 KB

    Thank you both for the quick response. Its just the info I needed!
    Gregory Osenbach, CLA
    Fluke

  • Converting 1d array of double

    I have a 1-D array of double inside of a while loop.  I would like to control the execution of the while loop based on one of the numeric values in that array (like I would stop the while loop if the numeric value in the array is less than or equal to 0).  How should I go about doing this? 
    I cant link the array directly to the "less than or equal to 0" icon because it requires a single double.  Any help would be much appreciated.  Thanks. 
    Jerry

    qiora wrote:
    I cant link the array directly to the "less than or equal to 0" icon because it requires a single double. 
    Of course you can connect an array to "less than or equal to 0". The output will be a boolean array that you can feed into a "OR array elements" or "AND array elements" to get a true if either (1) at least one array element matches or (2) all elements match, respectively.
    qiora wrote:
    I would like to control the execution of the while loop based on one of the numeric values in that array (like I would stop the while loop if the numeric value in the array is less than or equal to 0). 
    If it should be based on one specific element (e.g. element(0) or element(5)), you need to get that element using "index array" and do the comparison.
    The implementation will depend on your exact requirement. Your question is quite ambiguous.
    LabVIEW Champion . Do more with less code and in less time .

  • Problem installing creative cloud.  AdobePIM.dll contains an error

    I am trying to instal creative cloud on a Windows 7 64bit PC.  the installation is not working because it keeps saying the file AdobePIM.dll contains an error and then the file creative cloud helper.exe cannot start due to an incompatibility with 64bit.  I have tried a few times but I think it keeps finding the same corrupted file not re downloading it.
    How can I delete the corrupted download and force it to start again?

    I am not having success with the chat.  No reply.
    I cannot get to Creative Cloud through the uninstal programs route as it does not show there.
    Do you think I can delete the folders which were created during the failed installation?  They have today's date as the folder creation date.  They are
    c:\Program Files (x86)\Adobe
    c:\Program Files (x86)\Common Files/Adobe
    I may have to open windows in safe mode to do this.  Will I affect the registry by deleting a program which was not installed successfully.

  • I want to cast Array to double[]

    I make an windowsForm class for draw graph.
    It has an input param
    public FormGraph(string title, string name1, Array data1)
    I need data of double[] type for draw graph. But I think users are want to input double[] or int[] ect...
    So I try to get data as Array type and cast it to double[].
    double[] series1 = (double[])data1;
    But it throw exception about fail to cast.
    How can I cast variable type of array to double[]?

    Another option is to combine Generics with this.
    You can use generics to allow the users to pass different types of data to a method, but type specific in a different way.
    public FormGraph<T>(string title, string name1, IEnumerable<T> data1)
    var series1 = data1.Select(x => Convert.ToDouble(x)).ToArray();
    Muthukrishnan Ramasamy
    net4.rmkrishnan.net
    Use only what you need, Reduce global warming

  • Converting array of Double Precision values to U16 for MODBUS

    Hello,
    I am trying to send over pressure and temperature information via the Input Register array in MODBUS TCP.  My question is, how to I properly send over an array of double precision values without loosing my data?
    For example, my array of data looks like:
    12.0001
    32.001
    0.00051234
    0.0014838
    1.02
    12.0232
    31.920
    Thanks so much.

    Thank you Ravens Fan for replying.
    I missed one extra point of data.  Below is what I'd like to send:
    12.0001
    32.001
    0.00051234
    0.0014838
    1.02
    12.0232
    31.920
    2046
    The array above is an array of double precision values.  I will convert that array to an array of single precision floating data to reduce data size.
    Since I have eight pieces of single precision floating point data now, I will need to write to 16 registers correct?  What is the best method to split up each piece of data into two consecutive registers?
    Attached is a Slave Send Data.VI that I want to send this data through.  The end goal is to have a Master PC (not using labview, but a MODBUS utility) to read my MODBUS TCP message from the "Slave Send Data.vi" 
    Thanks
    Attachments:
    Slave Send Data.vi ‏15 KB

  • Creating polygons with an array of doubles instead of ints

    Hi,
    I want to create a polygon using:
    Polygon u = new Polygon(xPoints, yPoints, numTs);
    my problem is that my x & y points are stored in double arrays not ints. Is there a way to create a polygon using double arrays instead of ints?
    cheers,
    elmicko

    or cast them as int. imaginr posX, posY, width and height are doubles.
    Rectangle rect = new Rectangle( (int)posX, (int)posY, (int)width,(int)height );or, with an array of doubles:
    Rectangle rect = new Rectangle( (int)array[0], (int)array[1], (int)array[2],(int)array[3] );

  • Creating an array of doubles which represent an asymptotic curve.

    I want to populate an array with doubles with represent a value between 0.0 and 1.0 where array[0] = 0.0 and array[10000] = 1.0.
    I don't this array to follow a linear scale i.e. array[i+1] = array[i] + 0.0001.
    I want it to follow a distribution something like this:
    http://www.fao.org/docrep/x5685e/x5685e9k.gif
    How would I go about this?
    Thanks.

    Write a function that has the shape that you want.
    Evaluate that function at 10000 values, like say 0..9999, or .0001 up to .9999 if you prefer.
    Stick those values into an array.
    Is your question that you don't know how to write down a function that has some given shape? The picture that you sent us to is rather low on details. It has a single Label Linfinity. How rapidly does this function approach this value? Do you care? The picture appears to have an infinite slope at the origin. Do you need this? Do you just want some random function that goes through 0 and 1, is strictly increasing and basically smooth and concave to the right? You say it is an asymptotic curve, presumably approaching 1 and then you nail the 10000th value in your array to be exactly 1.0, so clearly you don't appear to care that your function actually reaches its asymptotic values.
    A function that has roughly the shape you want is the square root. Yes, that function does not have a horizontal asymptote but then again neither does your array. So just use f(x) = sqrt(x)/100.0 and evaluate between 0 and 10000.
    If you need something better than that, you will need to explain in more detail what exactly constitutes better.

Maybe you are looking for