LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI of the Day (9/10/2009) - Type Cast

Today a very powerful and flexible function, Type Cast.  One of the most forgiving functions around, it will happily take anything you throw at it and give you a result.  If you aren't careful, it may not be the result you are looking for.  I use this one a lot when I read a binary data file created in another language and need to tell LV its type.  After you read the help, you should know the results you get in the following cases:

 

TypeCast.png

 

Note: When you copy a BD image, coercion dots don't seem to be included.

 

If you want to see more unexpected Type Cast results, check this out. 

 

http://forums.ni.com/ni/board/message?board.id=BreakPoint&message.id=45&query.id=1122782#M45

 

VIOTD groundrules here

Message 1 of 13
(4,521 Views)

Darin.K wrote:

Today a very powerful and flexible function, Type Cast.  One of the most forgiving functions around,...


Hmmm... forgiving?

 

The type cast is the only(?) node in LV that will let you write code that will crash LV.

 

It should be used with caution.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 2 of 13
(4,517 Views)
not so forgiving than lol
Harold Timmis
htimmis@fit.edu
Orlando,Fl
*Kudos always welcome:)
0 Kudos
Message 3 of 13
(4,511 Views)

Ben wrote:

Darin.K wrote:

Today a very powerful and flexible function, Type Cast.  One of the most forgiving functions around,...


Hmmm... forgiving?

 

The type cast is the only(?) node in LV that will let you write code that will crash LV.

 

It should be used with caution.

 

Ben


I say forgiving since it will let you connect pretty much anything to any terminal and dutifully perform its job.  But it does bear repeating, caveat type caster.
 
I have seen plenty of craziness, but I have never managed to crash LV with a Type Cast, any examples?  (To be avoided of course). 

 

0 Kudos
Message 4 of 13
(4,484 Views)

Typecast has always been a favorite for obfuscated LabVIEW code.

 

Some examples:

 

Create text from booleansHelloWorldJP.vi by JeanPierre (posted here)

 

... or from a bunch of zeros and NaNs: HelloWorld02a.vi (posted here)

 

 There are plenty more in that thread.... 😄

Message 5 of 13
(4,484 Views)

How to crash LV in a bunch of steps;

 

Create a queue ref to pass a cluster of some type.

 

Type cast the queue ref as a queue ref for a different type of cluster.

 

Pass that (now bogus) ref to another VI to dequeue data.

 

In my case the data was actually passed but when came to ime for LV to deallocate the buffer, the dereferencing tried to deref a buffer ofa type other than what was in it and.. crash.

 

I need support to figure out what I had done wrong and boy was I embarased.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 6 of 13
(4,471 Views)

Ben wrote:

How to crash LV in a bunch of steps;

 


Reminds me of a (recurring) story from my grad school days.  I would typically work into the late night/early morning to get the DAQ software working.  At some point I'd start running it thinking "It's safe unless someone does A,B,C,D and E.  Nobody in their right mind would do that".  I'd go home to sleep and inevitably the phone would ring a few hours later and it would be my advisor.  

 

"The DAQ crashed"

"What were you doing when it crashed?"

"I just did A,B,C,D then E"

"I'll be in to fix it soon..."

 

My advisor always had the magic touch in the lab, I called him "sh&t-finger" (after I finished my thesis)

 

Now I can imagine some NI engineer thinking, LV is pretty stable unless someone does "A,B,C,D and E and nobody would do that"

Phone rings, "Hi this is Ben...."

 

(Don't worry, you're still goldfinger in my book).  If you ain't crashin' LabVIEW, you ain't tryin.

Message 7 of 13
(4,426 Views)

Altenbach,

 

I like the obfuscated code links from years ago, pretty interesting stuff.  However I am COMPLETELY stumped on how the boolean one works.  Want to spill the secret?

0 Kudos
Message 8 of 13
(4,353 Views)
0 Kudos
Message 9 of 13
(4,348 Views)
Ha well I feel silly.  Probably should have read through all 7 pages of that post.  Thanks
0 Kudos
Message 10 of 13
(4,333 Views)