05-24-2006 09:27 AM
05-24-2006 03:43 PM - edited 05-24-2006 03:43 PM
Message Edited by Chip Jones on 05-24-2006 03:44 PM
05-24-2006 07:41 PM
LabVIEW, C'est LabVIEW
05-24-2006 09:07 PM - edited 05-24-2006 09:07 PM
Message Edited by Chip Jones on 05-24-2006 09:14 PM
05-24-2006 09:26 PM
05-25-2006 02:09 AM
I can't see the code, but in general, there have been serious changes to the way LV represents and flattens data types in 8.
In general, relying on an error in an unflattening operation to correctly determine the data type sounds like a bad idea to me, because you have no way of being sure that there will be an error and you're relying too much on the internal representation of the various types, which might change.
A common way around this is to create a protocol - the sending side will identify what kind of data it wants to pass (for example, by appending a string of a fixed length to the beginning of the message) and the receiving side will read that part of the string first and know how to unflatten the data. This way you can pass arbitrarily complex structures and not worry about using trial and error. You can search the site for "messaging protocol" to see a nice tutorial implementing a similar approach.
05-25-2006 07:24 AM
05-25-2006 10:01 AM
05-25-2006 10:26 AM
In general, I agree with you and I simply forgot to say so in my last post. However, I don't have 8 and I don't know the extent of the change made to the flattening function in 8, like what kind of error checking it now performs. The fact that you're recognizing data as nonsense does not mean that LV can do that as well.
Basically, a flattening operation should be more than a simple typecast, so I would expect LV to be able to do good typechecking, but if (for example) it stores array data without keeping the type then it could recognize your string as an array, but it wouldn't recognize that it should be an array of numerics and not strings. This is probably something that can only be answered either by looking into the memory management white paper or by getting an answer from someone who played around enough with this (and JP qualifies for that).
05-25-2006 02:39 PM
Good afternoon,
Well, this certainly is an interesting situation. In the example “Unflatten string returns data from previous iterations”, the second iteration of the for loop unflattens a string as an array of strings type, this is obviously a type mismatch so if any data is returned I wouldn’t expect it to be valid. What is even more interesting, is that if you don’t use the auto indexing, but rather explicitly index the array there is no error, but the data returned is like it was in 7.x. I tried to use the flatten function’s “convert 7.x data function with no luck in either case. I filed a bug report on this issue (number 3X0CBC3A), but it seems to me the only workaround for now is going to be just making sure the types match. I know this is going to be inconvenient for you, and for that I apologize.
Incidentally, in many cases I wouldn’t necessarily expect an error to be generated if the types don’t match. This is because the flatten to string function takes your data and converts it to a string which is nothing more than a byte[ ] of data with some size information. When you “unflatten” the function takes the string it is given, and attempts to reconstruct the data in the format that is specified by the “type” input. If it can reconstruct the data from type, regardless of the data returned I wouldn’t expect it to generate an error. Sometimes, however, an error can be detected – if you flatten a double-precision number and unflatten to a single precision number LabVIEW can detect that the incoming data represents something much larger than a single precision number. I suppose that LabVIEW 7 did a better job checking the size of the sting before deciding whether or not to generate an error.
Again, I apologize for the problems this may cause. Please let me know if there is anything else I can help with.