LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

typecast does not accept "All" types of data

pawel wrote:

> That was just an example. I was thinking about more advanced solusions,
> which actually involve LV only on one side, so the interface must be well
> defined and understandable for others as well.

The LabVIEW flattened bytestream format is very well defined and also
documented in the online documentation "Search the LabVIEW
Bookshelf->Application Notes and White Papers->LabVIEW Data Storage
Formats". It is the same format LabVIEW will generate when you wire any
datatype to the Write File function for instance.

It has been virtually consistent since LabVIEW 3.0 with one change only
between LabVIEW 4 and LabVIEW 5 where the Boolean was changed from a
16bit signed integer to a 8 bit unsigned integer.

A more well defined binary format is almost unthinkable and LabVIEW at
least supports it out of the box without the need for any bothering on
your part.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 11 of 18
(1,214 Views)
pawel wrote:

> That is correct, but still you can recover the information
> if you know what to expect.

Well theoretically for one string or array indeed, but that is a very
cumbersome work. LabVIEW would have to parse the bytestream both from
beginning and end at the same time to get that information, a lot of
work to do for a Typecast which by definition is more or less a NOP at
runtime (LabVIEW does do some boundary checks on the string possibly
padding strings which are to short to be converted in the desired
datatype, but that is about it)! Also it is even more counterintuitive
that this function would work for clusters with one string but not for
clusters with two strings.

> E.g. your cluster can look like {U32, U32, String1, String2}, where
> you define that the first two U32 tels about the length of String1
> and String2. That would be propably most often meet during the network
> communication and some generic typedefs.

But that is exactly what "Flatten to String" is for!! With that, for
your hypothetical cluster with two strings you do not even need to fill
in any extra integers anywhere which you would have to fill in manually
as well. Flatten to string will simply create a bytestream for you in
the folliwing manner:

int32, string1, int32, string2

and the best of it all "Unflatten from String" will simply return this
back into a proper LabVIEW cluster again.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 12 of 18
(1,382 Views)
Hi Rolf

I think you are right under the condition that you have an influence on the interface to the other parties. Unfortunatelly I need to undergo some restrictions from another custommer and I have an interface strictly defined by them. There is nothing wrong with it, since I can accomplish their expectations, but I wanted to do it with a least trouble and effort :).

To do that I have found a typecast a little too "strict", shall I say. With a bit of more functionality I could make my task much easier and more LV-style. Now I need to do it more C-style, which I do not really care.

kind regards
Pawel
0 Kudos
Message 13 of 18
(1,209 Views)
Hi Rolf again.



@rolfk wrote:
@pawel wrote:

> That is correct, but still you can recover the information
> if you know what to expect.

Well theoretically for one string or array indeed, but that is a very
cumbersome work. LabVIEW would have to parse the bytestream both from
beginning and end at the same time to get that information, a lot of
work to do for a Typecast which by definition is more or less a NOP at
runtime (LabVIEW does do some boundary checks on the string possibly
padding strings which are to short to be converted in the desired
datatype, but that is about it)! Also it is even more counterintuitive
that this function would work for clusters with one string but not for
clusters with two strings.

> E.g. your cluster can look like {U32, U32, String1, String2}, where
> you define that the first two U32 tels about the length of String1
> and String2. That would be propably most often meet during the network
> communication and some generic typedefs.

But that is exactly what "Flatten to String" is for!! With that, for
your hypothetical cluster with two strings you do not even need to fill
in any extra integers anywhere which you would have to fill in manually
as well. Flatten to string will simply create a bytestream for you in
the folliwing manner:

int32, string1, int32, string2

and the best of it all "Unflatten from String" will simply return this
back into a proper LabVIEW cluster again.

Rolf Kalbermatter



Hi Rolf again.

I wrote in the previous post, that it was only an simple egsample (maybe not the best chosen one). As I wrote I need to undergo an dataformat, which was originally created to C++. That includes the Char[*]pointers and "*(TYPE*)&pointer" type casting. The wors is that it includes a lot of string to struct typecasting, which I can not do with LV typecast function. That the whole problem.

But... I almost solved it 🙂

cheers
Pawel
0 Kudos
Message 14 of 18
(1,374 Views)
pawel wrote:

> Hi Rolf<br><br>I think you are right under the condition that you
> have an influence on the interface to the other parties. Unfortunatelly
> I need to undergo some restrictions from another custommer and I have
> an interface strictly defined by them. There is nothing wrong with it,
> since I can accomplish their expectations, but I wanted to do it with
> a least trouble and effort :). <br><br>To do that I have found a typecast
> a little too "strict", shall I say. With a bit of more functionality I
> could make my task much easier and more LV-style. Now I need to do it
> more C-style, which I do not really care.

Hi Pawel

I see! The problem with this is that LabVIEW does not have anything
which can simply represent C style pointers. It is the strict typed
language definition which makes this possible but which is also the
reason that you do not really have to worry about memory allocation and
deallocation anywhere (well you do for performance reasons sometimes but
it is not strictly necessary in order to get a LabVIEW function to work).

For these situations the most simple solution is in fact to create an
interface DLL which translates between LabVIEW and your C interface.

The workaround would be to treat the embedded pointers as uInt32 as far
as LabVIEW is concerned and do some magic with MoveBlock calls as
explained in a different recent post of mine on those uInt32. But you
will find out soon that this is only practical for one or two functions
to do in this way. For more functions whith such parameters you will
inevitably find that starting up a C compiler and creating a DLL/shared
library project instead is a lot simpler, faster and less error prone.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 15 of 18
(1,204 Views)
Hi Rolf

I must admit I was thinking about making LV/C interface by means of dlls, but I dropped the idea from two reasons. One is that I am not much experienced in C (at least not for this tsk - OO programming) and second that I want to prove (partially also to myself) that LV can do as well as VC6 (in terms of functionality and code clearance) and even better. I have proven it many times, but this time situation is different, because, as I mentioned, I am not the designer of the dataformat. I want to show that LV can employ also dataformat designed thiinging in C.

I am very close to this, actually yeasterday I have the first success dataexchange with the VC server, so I am qute close now.

Finally, thank you for an interesting discussion.

kind regards
Pawel
Message 16 of 18
(1,189 Views)
I thought of another possible solution. Rather than writing a DLL in C, you could use the Flatten and then post-process the string. Since your structure is well defined and you cannot tolerate the length fields appended to the string, you can simply remove those offending bytes from the string after Flatten-ing. It would not be too difficult to write a VI that takes in a Variant (really really anything) and then interrogates each data type while taking note of the location of strings, arrays, etc. Then it would do the Flatten, and systematically remove the unwanted length fields. Your receiver would have to expect the string lengths unless the data stream contains some integers to "manually" define the string lengths.

See the Openg.org data type tools in the OpenG Toolkit if you want to hack into those purple wires (Variants).

Dan Press
PrimeTest Corp.
www.primetest.com
Message 17 of 18
(1,177 Views)
Hi Empire

Quite good idea. I will think more about that if I found it necesary. You got 5 starts from me :).

cheers
Pawel
0 Kudos
Message 18 of 18
(1,165 Views)