09-16-2016 04:18 PM
How can I have a subVI with variable number of input ports which can be changed in the other VI that uses the subVI?
Solved! Go to Solution.
09-16-2016 04:22 PM - edited 09-16-2016 04:23 PM
@Mmehrabin wrote:How can I have a subVI with variable number of input ports which can be changed in the other VI that uses the subVI?
Oftentimes the question asked is the "wrong question". I would ask you why you need this functionality, because I have a feeling that the solution to your real problem might be a whole lot easier than you imagined. 🙂
So what is it that you are trying to accomplish?
09-16-2016 04:27 PM
Actually, I am working on a system which should detect some signals that are simultaneous. Thus to make it modular, I need it works for any number of signals. It can be similar to some controls in LabVIEW whose input ports are variable.
09-16-2016 04:29 PM - edited 09-16-2016 04:31 PM
Ahh, so you mean something like the "Index Array" function where you can drag the icon lower edge to have as many outputs as you need?
09-16-2016 04:30 PM
Absolutely.
09-16-2016 04:33 PM
I am not aware of such functionality existing for user-made Vis, but can you bring in an array of data and iterate over it in a loop?
09-16-2016 04:35 PM
It is possible but I want to do that in VI Scripting. Do you have some information in this case?
09-16-2016 04:38 PM
@Mmehrabin wrote:It is possible but I want to do that in VI Scripting. Do you have some information in this case?
Sorry, I did not know your level of LabVIEW expertise so I imagined the simplest solution. I am not well-versed in scripting. My apologies.
09-16-2016 04:39 PM
Thank you.
09-16-2016 07:37 PM - edited 09-16-2016 07:38 PM
You can't actually do what you're trying to do, the way LabVIEW is set up doesn't allow for user-created VIs with arbitrary inputs. And to be honest, there's probably a better way to do whatever it is you want to do.
If you really truly want to do this though... you can kind of come close.
1. Create a new VI
2. Change its connector pane to the one with the most possible inputs and outputs (8-6-6-8, 28 terminals)
3. Create controls/indicators for whatever non-scaling inputs/outputs you want, then hook them up (i.e. error in/error out, reference wires, etc)
4. Hook them up to the connector pane
5. Count how many inputs are left and create one control input for each of them and wire them all up
6. Drop your VI on another VI's block diagram as a SubVI
7. Notice that when you mouseover it, it looks like a pincushion
8. Right-click the VI and uncheck "View as icon"
9. You can now "drag down" at the bottom of the VI
The terminals in the "drag down" section are like Bundle by Name or Property Nodes in that you can click them to reassign them to anything not already chosen. The default is to do all of the inputs alphabetically, then all of the outputs alphabetically. Whether or not you rename the terminals you use to have them appear in the order you prefer is up to you.
As for all of the terminals, the best you can do to detect if they are wired is to set them to a default value that should never be used. If it's floating points, you can use "NaN" or "Inf". If it's a cluster you made, add one more boolean element that is only True in the defaults to this VI input.
Then just wire all of the identical terminals together into an array, filter out the elements that seem unwired, and do all of your processing on the remainder.