LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamically load control from variant data at runtime to read binary file

Hi, 

 

I'm trying to load a ".ctl" file at runtime dynamically to read a specified binary file (the data type of the binary file is defined by the ".ctl" file).

With the variant data get from the ".ctl" file, I have an error when I'm trying to read the binary file created with the same ".ctl" file.

 

So I'm trying to rebuild the control from the variant but i don't know how. If you have any ideas to do that ? Or maybe there is another solution ? 

 

I'm working with LabVIEW 2020 x64. 

I have a solution with dynamic VI creation, but it's not working at runtime. And it may be.

 

You have on the project : 

- 3 different .ctl file

- 1 binary file

- 1 VI to create binary file

- 1 VI to read binary file (2 differents ways)

- SubVIs to load .ctl from path, and get data types recursively from a variant.

 

Thank you.

0 Kudos
Message 1 of 12
(2,785 Views)

Noone to help me ?

0 Kudos
Message 2 of 12
(2,710 Views)

I'd try to save variants. As you're reading variants...

 

You'd code has conflicts, and uses OpenG, so it doesn't run for me.

 

Never tried anything like this. It's probably something not a lot of people would do.

 

Is this going to be a lot of data? I'd stick to text based storage if not. Convert to JSON for instance. At least you'd know what's going on in the files.

0 Kudos
Message 3 of 12
(2,703 Views)

Hi, 

There is no conflicts here. 
And I if i try this, this is because I don't already have the data type of the binary file. It's to read a file from a client and make a generic VI to read multiple binary types of files. So I don't know if there is a lot of data too and I can't do this with Json text based too.

 

Thank you to take time for my problem.

 

Regards.

0 Kudos
Message 4 of 12
(2,695 Views)

I think you'll have to loop over the variant elements manually.

 

You already loop over all elements recursively. You might as well read specific data types in that recursive loop. Setting values in variant clusters (e.g. array of variants to variant cluster) is tricky though. AFAIK, it can only be done by flattening the data of the elements and unflattening it back into the variant cluster. Tricky, but doable.

 

I hope the number of supported data types is limited. Then again, if you do it for a double, the single will be a copy. I'd strongly recommend to limit the implementation to two types, perfect it, and then make (unavoidable) copies. A few .vims might help to limit the code being copied to a subVI, but at some point you need each supported type to be implemented somewhere.   

0 Kudos
Message 5 of 12
(2,692 Views)

Hi, 

 

Data supported needs to be string, double, boolean and waveform (array of these too). 

 

My problem is to convert variant of these data to their data dynamically. I don't know how to do that. to rebuild a constant of the total data type. 

 

Ex : 
Variant cluster of 2 elements : variant array of numeric + variant waveform         To            Cluster of 2 elements : array of double + waveform

 

If you have an example of that you are talking but I think it's not solving my problem

 

Thanks

0 Kudos
Message 6 of 12
(2,661 Views)

I never did this for waveforms.

 

To me, they don't add much except complexity.

 

In a way, they are a league of variants on there own.

 

But I expect Data Type Parsing\Get Waveform Information.vi to give results just like a cluster or array.

0 Kudos
Message 7 of 12
(2,650 Views)

My problem is not on the waveform. 
It will be exactly the same than others types. 

 

Just : I don't know the way to do that. 

 

If you have an example maybe with variant of cluster (string, number) to cluster (string, number) to saw how to do that it would be perfect.

 

Thank you

0 Kudos
Message 8 of 12
(2,628 Views)

@Mickaël_Phalanx wrote:

My problem is not on the waveform. 
It will be exactly the same than others types. 

 

Just : I don't know the way to do that. 

 

If you have an example maybe with variant of cluster (string, number) to cluster (string, number) to saw how to do that it would be perfect.

 

Thank you


Setting Variant Cluster Values.png

 

So, the variant in this example is a cluster. You're cluster conversion could be one of the cases, calling the very VI recursively.

 

Now the trick is to get the flattened data, concatenate it to a string, and use the variant data type to convert it back to a variant.

This almost always works, but IIRC there are issues if the cluster contains variants.

0 Kudos
Message 9 of 12
(2,622 Views)

The problem is still the same:

I don't know how the variant is build, so I can't use the "variant to data" function.

I only have a variant as an input.

 

My goal is to build the constant cluster that you have on the left only with types from itself, and I don't know if it's possible.

 

I probably explained my problem wrong:

From a ".exe", I need to import a ".ctl" file that will define the data type of my binary file.

So, I don't have the control in my code in the ".exe".

From the ".ctl" I can only extract a variant on the built software.

So that I would do is to build dynamically the constant type of the ".ctl" from his type that i can extract with my recursive VI

 

What I would like to do is to build dynamically the cluster constant according to the data type store in the variant, that would be extracted with the recursive VI just in case there are nested structures.
 
Or, is there maybe another way to reach the same result ?
0 Kudos
Message 10 of 12
(2,614 Views)