Parse array of variants

I have an application where we read binary data over Ethernet at a fast rate (~500 Hz). This data consists of many hundreds of measurements and other variables of all different types (floats, ints, strings, etc). I already have the code to parse this data and store it as an array of variants.
Now, I would like to take that array of variants and map each element to a specific variable.
Because the data is stored in a predefined sequence (Element #1 = speed, Element #2 = power, Element #3 = ...), I considered looping over the array of variants and using a case structure with a case for each index of the array (see attachment). However, this is very cumbersome as the case structure has hundreds of cases (one for each array element) and it is impossible to insert a new element in the case structure without manually re-numbering all of the cases.
Can anyone point me to a simpler implementation? If I was using C, I would probably memcpy the binary data directly into a byte-aligned structure. Is there an equivalent in LabVIEW using clusters? 
(Note: using LabVIEW 2014)
Solved!
Go to Solution.
Attachments:
variant_to_data.png ‏7 KB

I suppose that what you can do - similar to what you wanted to do in your first post about copying it into a structure in C - is create a type definition for your data structure coming across the network, which would be a cluster of all of your values, and then TypeCast / Unflatten From String into that.  From your image, it looks like you have at least 122 values.  That will be one big cluster, but I suppose that if that is your data structure, then that is your data structure.
By creating a Type Definition, you can gain some maintanability in that if you ever need to reorder, add, or remove data, removing it from your TypeDef should propagate everywhere, and giving every element a name and always using Unbundle by Name ensures that you are always getting the relevent element at each point of use even after changing anything.
Attached is an example of a Cluster TypeDef, and two code snippets follow:
The former uses the Unflatten From String function.  Usually the way to go with unflattening strings.
The latter uses TypeCast.  Functionally identical in this exact case, but probably not advised in this case as:
You don't have options of specifying byte ordering
You don't have options of specifying if the string contains the length at the beginning
You don't have error out to indicate that the conversion was unsuccessful
For some reason you cannot wire non-fixed-size clusters to the TypeCast function.
I do wonder if anyone has a good solution for the initial problem, though.  Consider what if one's data was actually being sent as an array of variants by some other application - how would one best handle that?
Attachments:
Cluster_Type_Definition.ctl ‏9 KB

Similar Messages

  • VB Web service with arrays as variant type - access from java

    Hi, I have a VB service as an activex.dll running on IIS. My first experience with VB.
    The input type is variant, as VB will only handle arrays of that type. All works well with
    a VB client. It takes 2 arrays in and returns an array. The WSDL file using a complex
    type of
    <complexType name='ArrayOfanyType'>
         <complexContent>
              <restriction base='SOAP-ENC:Array'>
                   <attribute ref='SOAP-ENC:arrayType' wsdl:arrayType='anyType[]'/>
              </restriction>
         </complexContent>
    </complexType>
    I take this WSDL file to the client side, change the type to
    <complexType name='ArrayOfinteger'>
         <complexContent>
              <restriction base='SOAP-ENC:Array'>
                   <attribute ref='SOAP-ENC:arrayType' wsdl:arrayType='integer[]'/>
              </restriction>
         </complexContent>
    </complexType>
    and then generate the Java proxy using jdeveloper 9031. All is good and I call the service
    and get a response, which in turn gives me a result. the result.getvalue fails with a caste
    exception, [LObject[] to Integer[]. The return value is there, but it's type is Object, which I can
    see by inspecting response in the debugger. I am getting
    pretty sure it is not a Java Object, but a dom or sax Object. The DOM DocumentBuilder
    works for String to get the values, but not for this Object type. Does anyone know how to
    parse out an Object Type with DOM or SAX?

    A java type "Object" is parent class of all java instances - to parse it with DOM or SAX requires you to cast it to the required object type by that parser api - eg "Document" - check out the DOM and SAX api docuemntation.

  • How can I convert an array with varying length into a cluster

    Hi,
    I need to convert an array of n elements into a cluster. Usually, it only involves the "Array to Cluster" function. But since the array length is not constant and the number of elements in the function is constant and can not be changed programaticaly, I need to find another way to do that.
    Any ideas?
    Thanks.

    Hi,
    I also tried to do this but without success. I think that's not possible.
    For me it's a general problem using labview. I often wanted to generate standard controls dynamically which is not possible (or I haven't found the solution yet). So I think that's the reason why you can't create a cluster during runtime (the program would have to add controls dynamically to the cluster).
    Do you have an upper limit for your array-size? Although it needs a lot more memory, it would be a possibility to create the cluster with the maximum number of elements.
    If you don't have a maximum, you will have to look for another way, I'm afraid.
    Thomas
    Using LV8.0
    Don't be afraid to rate a good answer...

  • How can I convert array of database variant to cluster?

    When I use the Database Connectivity Toolkit to read a recordset from a database, I just use a SQL query.  This returns an array of variant data.  I have always just indexed this array in a sequence structure that has the database variant conversion function in it and build a cluster from that.  There has got to be an easier way, but I can't find it.  Of course, my recordset has various data types in it.  Any ideas?

    Here is the  seed of an idea I had been nocking around.
    Compose an SQL query based on the cluster elements. I chose to use the caption of the cluster elements so that the unbundles have the names I want but the caption can be set to match the collumn names from the table. (If you really want to get fancy, update the captions of the cluster of the typedef before the application opens)
    Do the query and get your array of variants. They should be returned in the order of the query (which we composed based on the cluster order)
    Pass the array of variants into another foor loop that uses the Class ID to do the variant conversion.
    Come to think of it....
    Just wiring the variants to the geneic value refs of the cluster may be good enough.?????
    In theory if "cluster" is a type def, new fileds can be added to tthe typedef and it should get updated from the DB.
    Maybe turn this into a template?
    Your thoughts?
    Ben
    Message Edited by Ben on 01-03-2007 09:02 PM
    Message Edited by Ben on 01-03-2007 09:04 PM
    Message Edited by SarahM on 01-08-2007 12:24 PM
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction
    Attachments:
    Cluster.JPG ‏92 KB

  • Variant to numeric array

    hi,
           i will try to converte variant to int array.but will get the following error.
    Solved!
    Go to Solution.
    Attachments:
    variant to int.JPG ‏96 KB

    Have you tried to use the "Database Variant To Data.vi" ? 
    Have you probed the variant data comming from the database?
    Are you sure it is a array of numbers?
    It could be an array of variants, and each variant is an array of number.
    It could also be an array of variant, and each variant is an array of variant that represent a number.
    These options it NOT the same as an variant that is a double array of numbers, as you are doing right now.

  • Updating array data in sql database

    HI,
    Im facing problems in updating array data in SQL database.
    As of now, i am able to write an "insert" query and insert array data in an image datatype field. Im using image datatype because the array size is very big(around 80,000 x and y values).
    Althoug inserting data is easy im unable to write a query to update this data.
    Referring to the help of SQL server and Labview database connectivity toolkit, i came across a method of accessing image datatype....using textpointers, which are 16 bit binary values and using the WRITETEXT function instead of the UPDATE function.
    but the problem im facing is that ive to pass the array as a 2d string array in the query as a result the updated array is retrieved in the form of a string a
    nd not as an array. how do I get over this problem?

    Hi Pavitra,
    I'm not very clear on how you have inserted the data into your application, but I do know that when you call the UPDATETEXT or WRITETEXT function you use the TEXTPOINTERS to point to the first location of a 1d array. So, depending on how you've stored the data, you may have problems updating your data if you're looking at it as a 1d array instead of how you originally formatted it. If you are able to successfully access the data as a 1d array, you can use the database variant to data type vi and pass in a string array constant for the data type. This will convert the variant datatype into whatever you specify. You may have to index the row and column of the variant (you receive a 2d array of variant) first before you convert. If possible, can yo
    u provide some more detail and maybe some example code of how you perform the insert and plan to do the update? I can probably give you a better solution if I know how you are formatting the data. Thanks!
    Jeremy L.
    National Instruments
    Jeremy L.
    National Instruments

  • Deleting data from a 2D array based on the id of the second column

    Hello
    I hope someone can help me. I have come across a hurdle in the programming of my application.
    1.
    I have a 2D array, the first column of this array contains my data and the second column contains an id, which is either 0 or 1.
    I have sorted this 2D array based on the id column so that the data corresponding to the 0’s is on top part of the array and the data corresponding to the 1’s follows it (on the bottom of the array).
    I want to delete that data (rows) of this sorted array that correspond to the 1’s and keep only the data (rows) that correspond to the 0’s.  
    So I would end up with a new 2D array that has only the data that I want on the first column and 0’s on the second column.
    I have hundreds of these 2D arrays resulting from my program (using a for loop) hence I want to automate this procedure. The length of the selected data arrays will vary.
    2.
    Once I can do this I will want to remove the id column (with the 0’s) from the 2D array and would like to build a new array with only the data from the first column (which may be of different length).
    So I want to end up with a 2D array with columns corresponding to the selected (1st column) data from the (original) 2D arrays. These data may be of different lengths so when building this new array I may need to do some padding. Will labview do this automatically?
    I hope that this is clear.
    Best wishes,

    Attached is a different approach - you don't need to do any sorting.
    The outer FOR loop assumes you have all the arrays available at once. If you are reading a file, modify it accordingly.
    You may or may not want the TRANSPOSE function on the final results, depending on what you want to do with it.
    Yes, when you assemble N-dimensional arrays into (N+1)-dimensional arrays, LabVIEW automatically pads for you.
    Enjoy.
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks
    Attachments:
    Extract Marked Data.vi ‏40 KB

  • How many elements in an array?

    Sounds like a simple question, right?
    Apparently not.
    LV 2010
    I have a huge data structure, stored in DataLog files (thousands of them).
    I want to convert this structure to Name/Value pairs ("Operator_Name", "Joe Smith"), for use in a TDMS file.
    The structure is a cluster, with various clusters inside that, and inside those are DBLs, strings, BOOLs, other clusters, arrays, you name it.
    My strategy is to obtain the CONTROLS[ ] property of the outermost cluster and call this VI.
    The VI processes each control, decoding what type it is and handling it accordingly.
    It works fine for STRINGs, NUMERICs, ENUMs, BOOLEANs, COMBOBOXes, TIMESTAMPS, and CLUSTERs.
    For those simple ones, I use the LABEL.TEXT as the NAME and get the value (based on what type it is) as the VALUE.
    For a CLUSTER, I get the CONTROLS[ ] array of the cluster and call myself recursively, to handle all the elements within the sub-cluster.
    That all works fine.
    But to handle an ARRAY, I'm stumped.
    Attached is the code showing the case for an ARRAY.
    What I'm doing is getting the CLASS NAME of the current control.
    I LEGALIZE the label name (turn spaces into underscores, and maybe other special handling later).
    For an ARRAY, I cast the generic CTL reference into an ARRAY reference, and get its VALUE.
    I want to loop over each element of the array, and modify the name by the index number, and process each element.
    There are arrays of STRINGS, arrays of DBLs, arrays of CLUSTERs - all types.
    The question is - how many array elements are there?
    The constant "10" in this diagram is a dummy - just there to see if it works.
    it does work, except that I get 10 sets of answers, whether the real array has 2 or 20 elements.
    I thought the array's VALUE would be an ARRAY of VARIANTs, but no - it's a single VARIANT.
    I can't use VARIANT to DATA on the array's VALUE - I don't know what TYPE the array is.
    I thought maybe the ARRELEM refnum would be NIL if I was past the end, but that's not the case - there's only one refnum for any array element, whether it exists or not.
    If I check for errors, it complains that I cannot set the INDEXVALS property of a strict typedef array, even though it works just fine.
    If there was a method to SELECT ALL on the array, I could use the SELECTION SIZE to figure out how many elements there are, but I see no such method.
    The NUMBER OF ROWS / COLUMNS refers to the number of VISIBLE rows/columns, and has nothing to do with how much data is present.
    So... How do I find out how many elements are in the array?
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks

    The ArrElem reference property is not a reference to any particular element of the array. 
    On the contrary, it is a reference to the element addressed by the current ARRAY INDEX(es).
    That's why my code above can read out the values for element 0, element 1, etc.  I've verified that this works.
    There is only one set of PROPERTIES for the array elements; if you use the ArrElem refnum to set a background color of blue, then ALL elements turn blue, but you can obtain the VALUE of a given element by setting the ARRAY INDEX(es) and accessing via the ArrElem.
    I was thinking that maybe LabVIEW did a trick by setting this to NIL to indicate "no such element", but that's not the case.
    In any case, the question remains: How do I determine how many elements there are?
    The VALUE of the array is a variant: just what is in that package?
    As I said, I don't see how to use VARIANT TO DATA; I don't know what kind of data it is.
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks

  • Setting Values in an Array of Clusters via COM

    Hello everybody,
    I need some help concerning LabView and COM (ActiveX).
    I'm working on NT 4.0 with LabView 5.1 and I've written a COM-Client in Visual
    C++ 6.0 which controls LabView.
    I can set the values of normal Controls, Arrays and Clusters.
    But I'm not able to set values for an array of clusters.
    Does anybody know how to do this ?
    Or is it impossible ?
    Many thanks in advance,
    Ralf Erdmann

    >> I need some help concerning LabView and COM (ActiveX).>> I'm working on
    NT 4.0 with LabView 5.1 and I've written a COM-Client in Visual>> C++ 6.0
    which controls LabView.>> I can set the values of normal Controls, Arrays
    and Clusters.>> But I'm not able to set values for an array of clusters.>>
    Does anybody know how to do this ?>> Or is it impossible ?>> >>With no more
    information, the my answer is, I'm not sure. It is generally>possible to
    set controls by constructing a matching Variant. Make the>array a safe-array,
    the cluster a safe-array, and the elements of the>cluster be variants of
    compatible types to what is in the array.>>If you can't get it to work from
    this, you may want to include the>LV datatype in an email and contact support.>>
    Please allow
    me to get more precise.
    For my testings I used a cluster with just one element (type double)
    in an one-dim array with just this cluster as only element.
    A LV-Cluster is represented as an array of variants in COM.
    So I have an array of arrays. With an array beeing no datatype
    I don't know how to put an array into an array to
    construct a variant to pass to LV.
    How can I solve this?
    Thanks for help.
    Ralf Erdmann

  • Queue of arrays without dynamic memory allocation

    Hey folks,
    I'm working on optimizing a timing critical VI. This VI is the
    producer in a producer consumer architecture. I'm trying to populate
    a queue from file in a manner that is as efficient as possible. My
    current plan of attack is:
    - read block of data from file and populate array (pre-allocated).
    - add array (always of the same size) to Queue with a max size defined
    (e.g. 50 elements)
    - This is in a while loop as is the standard producer consumer model.
    To improve the performance I would like to ensure that there is no
    dynamic memory allocation on the Queue's behalf. This is easily done,
    from what I understand, if the data type in the queue is of the same
    type (e.g. double, int). However, since the size of an array can vary
    does this mean that any queue of arrays will always dynamically
    allocate memory? Is there a way to ensure that the queue will always
    use the same memory as in a circular queue?
    Thanks,
    Steve

    Duplicate.
    Try to take over the world!

  • Trouble creating Variant format for ActiveX Function (MintMT Controller)

    Hello!
    I am creating a VI to control 2-axis motion using the MintMT activeX library and have run into a problem.  I was able to easily call and execute functions from Labview until I ran into one (VectorA) that requires an array of variant input.  I cannot format my input correctly and have exhausted myself trying different combinations of building this array and converting to variant type (To Variant). I also have wired Labview arrays directly (with no luck). The arrays are very small (only 2 elements). Finally I tried the OpenG library (Cluster to Varray and Array to Array of Vdata) without success.  The error code is: LabVIEW:  (Hex 0x80070057) One or more arguments are invalid.
    Any advice?
    Attached is the documentation for the function:
    VectorA
    Prototype:
    VB      VectorA(nNumberOfAxes As Integer, nAxesArray As Variant,
                    fPosArray As Variant)
    Delphi  VectorA : (nNumberOfAxes: Smallint; nAxesArray: OleVariant;
                       fPosArray: OleVariant)
    C++     void VectorA(short nNumberOfAxes, VARIANT nAxesArray, VARIANT fPosArray);
    C       void VectorA(__int16 nNumberOfAxes, __int16 *nAxesArray, float *fPosArray);

    Hi Mr. NiceGuy,
    The code from the manufacturer has a To Variant converter between the arrays and the Property Node. I'd recommend converting the arrays to variants in your code. You can find that To Variant VI on the Functions Palette » Programming » Cluster, Class, & Variant »Variant. Let us know if that works.
    Hillary
    Regards,
    Hillary E
    National Instruments

  • VARIANT data in TestStand

    I want to control a program using ActiveX in TestStand. I can successfully obtain a reference to the VI object in the program. The server program was written in LabView and allows the Call method of ActiveX to control the program. The Call method requires two parameters. Both are of data type VARIANT (parameterNames, parameterValues). The parameterNames are basically strings, but the parameterValues are mixed type(string, int, bool,etc).
    Is there a way to create a data type of VARIANT in TestStand to pass data through the ActiveX adapter??
    Note that I can do this in LabWindowsCVI, but I was trying to avoid writing a special DLL and use the TestStand Adapter.

    Bob asked what you meant by mixed data types. To clarify, the LabVIEW ActiveX server has a call method. It's second parameter is a varaiant array of variants, where the elements can be different (mixed) data types. Each data type corresponds to the LabVIEW control specified in the first parameter of the Call method, which is a variant array of strings.
    As Bob explained, the ActiveX automation adapter is able to automatically convert TestStand properties to variants, when the data type of the properties are support ActiveX data types (e.g. most scalars and arrays of these scalars).
    For the first parameter of the Call method you can send in an TestStand array of strings. This array will automatically be converted to a variant array of BSTRs be
    fore being passed to the Call method.
    Currently TestStand does not support a variant data type. Therefore, it is impossible to create an array of variants so that the array can in turn be converted to a variant by the ActiveX Automation adapter.
    In general, the ActiveX automation adapter does handle sending data from/to an ActiveX server. The issue of passing arrays of variants has not occurred very often. We have encountered it once internally at NI, but I believe that you are the first customer to ask about passing arrays of variants.
    In terms of the big picture, I don't understand why you are calling a VI using the AcitveX automation adapter instead of the the LV adapter. If the vendor has already created a VI to call another VI through the LV ActiveX server (why does he/she do this?), then perhaps you should just call the vendor's VI directly.

  • How to dump array created by 'getrows method' into spreadsheet??

    hi,
    I'm sorry but I'm not goot as English.
    I'm trying to dump oo4o dynasets into farpoint spreadsheet without looping.
    first, I created the array of variant type through the 'getrows' method of oo4o.
    the 'getrows' method copies records from a Dynaset into a two-dimensional array. The first subscript identifies the field and the second identifies the row number.
    Then I found the method 'setarray' of spreadsheet but this method dumps a array into spread
    beginning with the row number. In result the spreadsheet views the recordset that the rows
    and the columns are exchanged.
    Please, Advice about my trying.

    MESSAGE FROM THE FORUMS ADMINISTRATORS and COMMUNITY
    This thread will be deleted_ within 24 business hours. You have posted
    an off-topic question in an area clearly designated for discussions
    about the features and functionality of the forums site. Community
    members looking to help you with your question won't be able to find
    it in this category.
    Please use the "Search Forums" element on the left panel to locate
    a forum based on your topic. A more appropriate forum for this post
    could be:
    New to Java http://forum.java.sun.com/forum.jspa?forumID=54

  • Exchanging 2 D array between VBA and labview

    I have a project : half part is VBA writen, half part is  Labview coded. Both parts are writen to operate manually. The first one prepares data and charts them on charts sheets, the second one smooths data with ready made labview curves fitting VIs. So I want operator could use them seamless, that means calling labview from VBA 2007 code collecting X,Y data into a 2 D array, then send it to labview DLL smooth the curves and send back an array with smoothed data to excel through VBA.
    My concern is how to declare 2D array parameters in VBA  and in Labview in order to work fine (array of variants or doubles, parameters declared by ref or by val)
    I have seen similar topics in NI forum but they dealt with VB.net and not VBA .
    I run office 2007 and labview 2009 full dev. system with application builder.
    Regards

    bassevellois wrote:
    Thank you for the answers.
    The examples provided with labview for ActiveX exchanges are not very clear. I want to use labview as ActiveX server and Excel through VBA as client.
    There's only one example that I know of that ships with LabVIEW and it shows how to access LabVIEW from VB using LabVIEW's ActiveX server. It opens a VI and runs it. Doing it from VBA is very similar. You want to add the reference to the ActiveX Server in your VBA project. If you're controlling the LabVIEW development environment directly, then the library to include in your list of references will be "LabVIEW x.x Type Library". If you are controlling a LabVIEW-build app, then the library name will be whatever you specified when you built the app. 
    I have no idea of creating and exposing classes, methods or properties needed in VBA from my Labview VI which was at the beginning a standalone application.
    I don't quite understand what you are referring to. The ActiveX Server in LabVIEW and a LabVIEW-built app are pre-defined. You do not export anything from your LabVIEW VI. The available properties and methods are a function of the LabVIEW ActiveX Server, not of your VI. If you are building an app then you just need to enable the ActiveX server for the application, and that's done in the build specification. 
    How to reproduce my example:
    Make sure you've enabled the ActiveX Server in LabVIEW. 
    Download the attached 2D_VBA_Test VI to your C:\Temp folder. You can save it anywhere, but you'd have to change the path in the Excel VBA macro.
    Download the attached Excel workbook.
    Open the workbook and click the button. If LabVIEW is not running it should launch LabVIEW, and open the VI and populate the front panel array with the values from the spreadsheet. 
    Attachments:
    2D_VBA_Test.vi ‏6 KB
    VBA to Excel.xls ‏24 KB

  • What kind of variant is used for "DB insert data.vi"

    How can a variant from "fetch All.vi" be converted into a variant ok for "DB insert data.vi"?
    In the attached files I try to doublicate a record in a database. Does anybody know how to make it run?
    Attachments:
    Test_InsData.vi ‏52 KB
    DB.UDL ‏1 KB
    DB.mdb ‏128 KB

    Umi,
    From the 2D array of variants you obtain from the fetch all.vi, you need to extract each value, knowing each variant datatypes and build a cluster of data or variant to use in DB insert data.See VI attached.
    Regards,
    Cyril Bouton
    Applications Engineer
    National Instruments
    Cyril Bouton
    Active LabVIEW Developper
    Attachments:
    Test_InsData.vi ‏69 KB
    Test_InsData2.vi ‏69 KB

Maybe you are looking for