Sparkette Posted June 29, 2012 Report Share Posted June 29, 2012 (edited) WARNING! As Aristos Queue stated, this is VERY experimental. I am not an employee of NI and am not responsible for anything bad that happens if you use this. Basically, it's just for experimentation. Just drop that VI snippet into a VI, and it will work with any array type. I copied it from Randomize 1D Array. If you don't know what a generic VI is, click that link. Here's a sample I created that takes a 1D array of any type, and outputs an array which is basically that array concatenated to itself. For example, {1, 2, 3} becomes {1, 2, 3, 1, 2, 3}. Not too useful, but it works as a proof-of-concept. And in case the VI snippet isn't working, you can copy the control and indicator from there. Download link: Duplicate 1D Array.vi Another thing that might work (though I haven't tried it) is to take the DBL out of the array and see if that works with any type as well (not just any array). I can still think of a few uses for this, such as if the value is just going to be typecasted anyway. Like, say, something that converts any data into a hex string. EDIT: Yep, it works, and here you go. Data to Hex String.vi EDIT2: There is actually a much easier way to do this, which is likely how Aristos made the generic controls in the first place. All you have to do is open LabVIEW.ini, add the line "GenericsAreGo=True" somewhere, and you'll be able to right-click a control and select "Generic" to make it generic. EDIT3: Out of curiosity, I tried putting a generic control in a Malleable VI to see what would happen, since Malleable VI's basically do the same thing. Guess what? Crash. Not immediate, but it happened after I moved the subVI on the diagram. Fix your code, NI! (just kidding!) Edited January 14, 2019 by flarn2006 Files moved from external download site to LAVA. Quote Link to comment
Sparkette Posted June 29, 2012 Author Report Share Posted June 29, 2012 (edited) EDIT: I am unable to edit my first post, but I have made .ctl files for this that can be easily added to your palette. Generic Controls.zip Edited July 3, 2012 by crelf Files moved from external download site to LAVA. Quote Link to comment
Yair Posted June 29, 2012 Report Share Posted June 29, 2012 One thing you might wish to look up is Norm's scripting springboard. It's a template VI which has code to operate on a selection in a VI when you press a button. That means you can create a copy of the template, add your code to it and easily test that it works and use it. It's certainly easier than having to drop controls from the palette. And again, to expand on AQ's warning, he didn't just say it was experimental. He basically said the experiment is over and that this tech would not be developed further. Quote Link to comment
Sparkette Posted June 29, 2012 Author Report Share Posted June 29, 2012 Yes, I'm aware of that. That doesn't make it any less fun to mess with though, as long as I'm not doing anything high-risk. Quote Link to comment
asbo Posted June 29, 2012 Report Share Posted June 29, 2012 As a general warning to anyone interested, I guarantee you'll be able to crash LabVIEW with these, so you're nuts if you even think about using this stuff in production code. A few issues I know of: 1) The compiler gets confused when you stack them deeply as subVIs. Not sure why. 2) If you copy your VIs to a new machine where they've never been loaded before, your load time goes through the roof for first load, so much so that most people might believe LV is hung and kill it. 3) These VIs do not play nicely with recursion. It's a very cool toy, but like Yair mentioned the experiment is essentially over. I'd love to see a stable replacement for this kind of concept (think of the possibilities for reuse...). Quote Link to comment
Popular Post Darren Posted June 29, 2012 Popular Post Report Share Posted June 29, 2012 Last year I had a product mostly ready to go that made heavy use of this functionality, but I had to rip it out fairly late in the process because of some fundamental flaws (mainly #1 in asbo's list, but also some other issues). Please don't rely on this functionality in any app that you're not planning to throw away. 3 Quote Link to comment
Sparkette Posted June 29, 2012 Author Report Share Posted June 29, 2012 (edited) One thing I'm still curious about is how NI makes generic VI's. Obviously the controls have to come from somewhere, so how do you make them? Is it like some kind of low-level VI editor that edits the individual data structures in the file? Also, how exactly does the compiler get confused? Edited June 29, 2012 by flarn2006 Quote Link to comment
Rolf Kalbermatter Posted June 30, 2012 Report Share Posted June 30, 2012 One thing I'm still curious about is how NI makes generic VI's. Obviously the controls have to come from somewhere, so how do you make them? Is it like some kind of low-level VI editor that edits the individual data structures in the file? Also, how exactly does the compiler get confused? Well how do you think did they do the first controls of a new data type? Probably something like handcoding with specially compiled LabVIEW that has special tools included. And about how the compiler gets confused, I'm sure you will never hear a detailed info. For one thing this is NI internal, and for another thing unless you understand a project like LLVM from ground up, it would make no sense to you if they would give you a more technical explanation. Go study LLVM and once you understand it, you may be qualified to understand at least in parts what all might go wrong there. Quote Link to comment
Sparkette Posted July 1, 2012 Author Report Share Posted July 1, 2012 Well how do you think did they do the first controls of a new data type? Probably something like handcoding with specially compiled LabVIEW that has special tools included. And about how the compiler gets confused, I'm sure you will never hear a detailed info. For one thing this is NI internal, and for another thing unless you understand a project like LLVM from ground up, it would make no sense to you if they would give you a more technical explanation. Go study LLVM and once you understand it, you may be qualified to understand at least in parts what all might go wrong there. I'd love it if someone from NI could post a few screenshots of that specially-compiled version, just out of curiosity. Quote Link to comment
Darren Posted July 2, 2012 Report Share Posted July 2, 2012 Not a special compiled version, just a certain way we can configure the UI to make controls generic. Quote Link to comment
Sparkette Posted July 2, 2012 Author Report Share Posted July 2, 2012 Not a special compiled version, just a certain way we can configure the UI to make controls generic. Could you post a screenshot of the menu or whatever else it is you use to customize that? It's not like it would give us access to any features NI doesn't want us to have, just satisfy my curiosity about that kind of thing. Quote Link to comment
Darren Posted July 2, 2012 Report Share Posted July 2, 2012 Could you post a screenshot of the menu or whatever else it is you use to customize that? It's not like it would give us access to any features NI doesn't want us to have, just satisfy my curiosity about that kind of thing. No, I can't post a screenshot. Your curiosity will have to be satisfied with "a certain way we can configure the UI to make controls generic". 1 Quote Link to comment
Sparkette Posted July 3, 2012 Author Report Share Posted July 3, 2012 (edited) Aristos Queue mentioned to me that Generic VI's will no longer work in LV2012. It's a shame they couldn't have changed it so it was more stable, but I guess since it's unreleased they don't really have any obligation to. But as consolation (actually just for fun), here's another Generic VI I made that takes a random choice from an array. Random Choice from Array.vi EDIT: Actually that has a glitch where it will sometimes give the default value. This is no fault of the generic VI system; I simply forgot to add a on the blue wire between the and the . But when I tried it afterwards, LabVIEW crashed, which shouldn't come as much of a surprise. But it's a simple enough fix. Edited July 3, 2012 by crelf Files moved from external download site to LAVA. Quote Link to comment
Rolf Kalbermatter Posted July 3, 2012 Report Share Posted July 3, 2012 EDIT: Actually that has a glitch where it will sometimes give the default value. This is no fault of the generic VI system; I simply forgot to add a on the blue wire between the and the . But when I tried it afterwards, LabVIEW crashed, which shouldn't come as much of a surprise. But it's a simple enough fix. I think your proposed fix is not a fix but just a change of the bug. With the fix as proposed by you you end up with an index in the range -1 to n-1 instead of 0 to n. So you replace the invalid index at the end of the range with one before the range. The -1 should be better placed after the Array Size function. 1 Quote Link to comment
Sparkette Posted July 4, 2012 Author Report Share Posted July 4, 2012 I think your proposed fix is not a fix but just a change of the bug. With the fix as proposed by you you end up with an index in the range -1 to n-1 instead of 0 to n. So you replace the invalid index at the end of the range with one before the range. The -1 should be better placed after the Array Size function. Oh yes, that makes sense. And Index Array works the same on an empty array regardless of what index is given, right? Even a negative number? It just gives the default value for the array? Quote Link to comment
vugie Posted July 4, 2012 Report Share Posted July 4, 2012 Oh yes, that makes sense.... But even then it is not a correct solution for choosing a random array element. At least when you want uniform distribution. Look at the histogram made for 20-element array and 1e6 choices: Make a conclusion yourself. BTW, who said it: When you think that something is simple, it means that you don't understand the problem ? Quote Link to comment
Sparkette Posted July 4, 2012 Author Report Share Posted July 4, 2012 Lol, this is turning into the original discussion about Randomize 1D Array. But yeah, I didn't realize that rounded to the nearest integer. I had always thought it just rounded toward 0. I would use , but I would like a universal solution that would work for negative numbers too, even though negative numbers wouldn't come up in that case. I could have it set up so it rounds up if a number is negative, or down if positive (using a case structure or the ever-useful ) but that seems too complicated for a task as simple as generating a random integer between two values—surely there must be a simpler way? Quote Link to comment
Rolf Kalbermatter Posted July 4, 2012 Report Share Posted July 4, 2012 Lol, this is turning into the original discussion about Randomize 1D Array. But yeah, I didn't realize that rounded to the nearest integer. I had always thought it just rounded toward 0. I would use , but I would like a universal solution that would work for negative numbers too, even though negative numbers wouldn't come up in that case. I could have it set up so it rounds up if a number is negative, or down if positive (using a case structure or the ever-useful ) but that seems too complicated for a task as simple as generating a random integer between two values—surely there must be a simpler way? Mathematics is tricky. The round to zero is possible with the floor() operation but is not sufficient. Since Randomize() produces values between 0 and 1 with the ends inclusive, you still can end up with a few potential values outside the range every now and then. Also just as a trivia there are in fact two round() used in mathematics, one rounds 0.5 always up the other towards even numbers. The second is meant to reduce the effect of rounding errors in combined mathematic calculations with multiple roundings occuring. Quote Link to comment
vugie Posted July 5, 2012 Report Share Posted July 5, 2012 ... Since Randomize() produces values between 0 and 1 with the ends inclusive, you still can end up with a few potential values outside the range every now and then. To be precise: 0 <= "Random Number (0-1)" < 1 So rounding towards -Inf is a valid approach Quote Link to comment
Sparkette Posted July 5, 2012 Author Report Share Posted July 5, 2012 (edited) No, I can't post a screenshot. Your curiosity will have to be satisfied with "a certain way we can configure the UI to make controls generic". Is this functionality in the release version of LabVIEW, just not enabled? I mean, like is there any way a hacker could configure the UI like this just by modifying a few bytes or something? EDIT: Yes it is! LabVIEW.ini, "GenericsAreGo=True" Edited August 14, 2015 by flarn2006 Quote Link to comment
Rolf Kalbermatter Posted July 5, 2012 Report Share Posted July 5, 2012 To be precise: 0 <= "Random Number (0-1)" < 1 So rounding towards -Inf is a valid approach I stand corrected. For some reasons I believed it would include 1 in the possible range, and wondered why as that made not to much sense at all. Quote Link to comment
Popular Post Darren Posted July 6, 2012 Popular Post Report Share Posted July 6, 2012 Is this functionality in the release version of LabVIEW, just not enabled? I mean, like is there any way a hacker could configure the UI like this just by modifying a few bytes or something? Your curiosity will have to be satisfied with "a certain way we can configure the UI to make controls generic". 3 Quote Link to comment
Aristos Queue Posted July 6, 2012 Report Share Posted July 6, 2012 EnableFeaturesNotAvailableToAnybodyOtherThanL33tL4bV13WHax0rs=TRUE I don't think that does anything unless you have the RT or FPGA modules installed. Quote Link to comment
Sparkette Posted July 6, 2012 Author Report Share Posted July 6, 2012 That's not a worry AQ, I have a couple of minutes spare this weekend to crack the NI License Manager... I'm pretty sure that's already been done. Quote Link to comment
Aristos Queue Posted July 7, 2012 Report Share Posted July 7, 2012 I meant that I didn't think that any of those features were even compiled into the core LV and were installed by the modules, but I may be wrong. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.