07-31-2023 01:24 AM
Hi,
I'm experimenting with OOP and for an exercise I'd like to create a basic instrument control class for power supplies. In my class hierarchy there are couple methods (Set OCV, Set OVP, Set output state, Set voltage level, Read voltage level etc) , all should be overwritten by the child classes. The private data is only the visa resource name. So far I created to child classes for different power supplies and they work just fine.
This looks OK so far but I'd like to introduce a Max Voltage and Max Current class data as well. Both of these look appicable to pretty much every power supplies so I'd like to put them to the private data of the of the topmost class and the child classes should use data of the parent class. Here comes the problem: it seems that LV classes have no constructor so I dont know how to initialize these values. The Max Current and Max Voltage are not like the VISA resource name. The latter depends on the implementation the previous two should be hard coded values for a given instrument. I could write an Init routine for each child classes but then I need to call those right after the instantiation which doesnt seem right. The initialization of the class data should be the job of the constructor.
How should I do this right?
thanks.
07-31-2023 04:41 AM
Hi 1984,
Unless you are using by-reference class designs such as with G# or GOOP, there is no such thing as a "constructor" for LV classes.
It is your job to implement an "Init" VI that sets the initial values of your private data, and that is perfectly right. A lot of things in LV have the pattern "Init", "DoSomething", "Close".
An alternative could be to have a VI called e.g. "Get Limits" that is specific to each child class and that is called every time you need those voltage/current limits. Then, the limits don't need to be inside the private data and no "Init" method is needed.
Regards,
Raphaël.
07-31-2023 06:56 AM
@1984 wrote:
Hi,
I'm experimenting with OOP and for an exercise I'd like to create a basic instrument control class for power supplies. In my class hierarchy there are couple methods (Set OCV, Set OVP, Set output state, Set voltage level, Read voltage level etc) , all should be overwritten by the child classes. The private data is only the visa resource name. So far I created to child classes for different power supplies and they work just fine.
This looks OK so far but I'd like to introduce a Max Voltage and Max Current class data as well. Both of these look appicable to pretty much every power supplies so I'd like to put them to the private data of the of the topmost class and the child classes should use data of the parent class. Here comes the problem: it seems that LV classes have no constructor so I dont know how to initialize these values. The Max Current and Max Voltage are not like the VISA resource name. The latter depends on the implementation the previous two should be hard coded values for a given instrument. I could write an Init routine for each child classes but then I need to call those right after the instantiation which doesnt seem right. The initialization of the class data should be the job of the constructor.
How should I do this right?
thanks.
At the risk of starting a flame war I'll chime in with my point of view on "Instrument Driver" Classes. NOTE: I am limiting my opinion to ONLY Instrument Class Drivers!
I Don't like them for Test. Period. You wind up wasting your time coding for everything that never happens and nothing that ever happens. It's just plain simpler, faster, cheaper, and saner to document the system minimum measument capabilities and change the hardware and drivers during the regularly scheduled System Obsolescence Reviews.
07-31-2023 07:20 AM
I guess its pretty much impossible / useless to write methods for all the commands of the given power supply. The one I'm working with right now has 100+ and it has specific features other power supplies might not have. So for now I really limit myself for the most obvious features (OVP, OCP, Set V, Set C, Read V, Read C, Read P, Enable/Disable output, Connect / Disconnect, *RST, *IDN? and send custom command). These cover the 95% of the features I have ever used on power supplies.
Once its done we'll evaluate if we want to go with class based drivers.
07-31-2023 07:42 AM
07-31-2023 08:03 AM
I have handled similar needs with a dynamic accessor with "Descendants must override". The top level template class (really, interface) can have an accessor that returns "Max current" of 0 and an error. Descendants override that accessor with their own value. This way it "acts" like it's a private data element of the top level class, but it's actually specified by a child class.
I mainly do this with identifiers that return the test ID name of a test actor override.