12-21-2011 04:07 PM
Hi everyone
I have a basic/principal question regarding subvi's and associated error handling.
Say I have an DLL which contains a function that takes input a and b, outputs c and d and that I want to wrap this function call (plus additional logic) into a SubVI. I can imagine this done in two ways with error handling:
Which one is the most "correct" (or pretty or smart) way to do it?
Best regards
Wuhtzu
12-21-2011 07:11 PM - edited 12-21-2011 07:13 PM
It is best to put all front-panel controls and indicators on the top level of a subVI (the only exception to this is the main VI).
(EDIT: that means put the controls and indicators outside the case structure, as in subvi 2)
That said, if your subVIs contain only the DLL call, then there is no need for the case structure. The Call Library Function Node will not execute if there is an error on the error in terminal.
12-22-2011 04:05 AM
First off, I agree with nathand that you do not need the case structure (the Call Library Function Node handles it).
Second, if you are wrapping DLL functions, take a look at the import DLL tool. (Tools->Import->Shared Library in the menus). It will create wrappers for your DLL functions -- then you just have to test them and make some tweaks
For example, if you have a parameter which is a pointer, the tool will make you an input and an output (since it can't tell which it is meant to be, and might be both). Often you really just want it as an input or just as an output, so you have to change that (and make sure, if an output, that you have someplace to put it; in some cases you will need to make a constant of that type and pass it into the Call Library Function node, and then pass it out.
I have had a lot of success using this tool, and it saves a lot of repetetive grunt work.
B.
12-22-2011 05:38 AM
Hi Wuhtzu
I would recommend a combination of the first and the second solution.
This means:
1) I would like to have the controls inside the no-error case, because the program should only read the value if there is no error. If you have the controls outside and attached to the terminals of the while loop LabVIEW will still have to read the value of the controls even though they are not used in the particular case. (Try this with the highlighting in the block diagram).
2) I would though place the indicators on the outside because they should be updated with either a proper value or an error message. Meaning they have to be updated for both cases.
Best regards,
Anders Rohde
Application Engineer
National Instruments, DK
12-22-2011 09:37 AM
@A.Rohde wrote:
1) I would like to have the controls inside the no-error case, because the program should only read the value if there is no error. If you have the controls outside and attached to the terminals of the while loop LabVIEW will still have to read the value of the controls even though they are not used in the particular case. (Try this with the highlighting in the block diagram).
This is not good advice. Reading controls at the top-level should be efficient whether or not the values are used, but there can be a cost to putting controls inside the case structure as explained in the "clear as mud" thread to which I linked in my first reply.