LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
0 Kudos
JasonCorwin

Update Type Cast to allow Clusters containing a string or array

Status: Declined

Any idea that has not received any kudos within a year after posting will be automatically declined. 

I use typecast a lot. It's the perfect function to turn clusters into a string and vice versa when doing tcp or udp communication. Unfortunately it breaks when the cluster contains a string or array. If I pass a cluster containing a five character string and a U32, it should give 9 characters out.

 

The main complication seems to be turning that same 9 character string back into a cluster, without size info on the string Type Cast doesn't know how many bytes go to the string. That could be pushed back to the user and require the cluster wired to the 'type' input to have the expected number of characters in the string or elements in the array.

 

I looked at Flatten To String, but if you pass a cluster containing a string it always prepends the string length in the flattened output.

 

I haven't yet had a chance to look at LV2013, maybe it's in there?

4 Comments
tst
Knight of NI Knight of NI
Knight of NI

JasonCorwin wrote:

I looked at Flatten To String, but if you pass a cluster containing a string it always prepends the string length in the flattened output.


I don't understand that "but". What's wrong with this? It does exactly what you need. Are you suggesting that it's better to let the user determine the length rather than to have to have the code pass it automatically? Why? If it's simply to save the 4 bytes in transmission then you might as well convert it to a cluster of N bytes and be done with it.


___________________
Try to take over the world!
AristosQueue (NI)
NI Employee (retired)

The reason it breaks is because your request is impossible and still maintain the meaning of "Type Cast". Strings aren't flat in-line types. You couldn't ever typecast it back because LV wouldn't know where the string ends. Sure, we could amend the rules of Type Cast but your Type Cast trick is a bad idea anyway .Heaven help you if you send messages between two machines with different endianness.

 

There's a reason that we have the Flatten To String primitive for network communications.

ZX81
Member

I agree with the original comment.  I have a case where I receive a block of data from a PLC (no opportunity for flatten-to-string).  Among the bytes I receive is a fixed-length string.  It's actually 16-bits for length, then exactly 32 bytes for characters.  I would like to:

 

Untitled.png

But it won't work.  If the array 'String' was a fixed-length, it ought to work.  But I can't set the string to fixed-length unless it is created in an FPGA context (this isn't).

 

If the string array was fairly short, I could have a list of bytes for it, then assemble it later.

 

My solution isn't as elegant as I'd like, but is usable:

Untitled.png

 

 

___________________
CLD, CPI; User since rev 8.6.
Darren
Proven Zealot
Status changed to: Declined

Any idea that has not received any kudos within a year after posting will be automatically declined.