SteveChandler Posted October 20, 2011 Report Share Posted October 20, 2011 I have two devices. One has an RS232 interface and the other has an Ethernet interface. The API is identical. They accept the same commands and return the same responses. The only difference is the hardware interface. I have a parent class with a dynamic Query.vi method which is overridden by a serial child class and an Ethernet child class. The parent has a bunch of static methods that send commands to the query method, parse the results and return the data. Easy stuff. However I can not figure out how to create a dynamic Initialize method since one takes a VISA resource name and baud rate and the other takes an IP address and Ethernet port. Different connector panes. All I can think of is to put both the serial and Ethernet configuration parameters on the connector pane but that seems sick and wrong. The way I am doing things works. I have a static initialize method for each child. But that does not allow me to only load one child class into memory. It's not a big deal and is more of a curiosity. Quote Link to comment
Tim_S Posted October 20, 2011 Report Share Posted October 20, 2011 Hrm... The only way that I can see to have a dynamic input is to use a variant. It's not my first choice as I'd probably create the child object, use property nodes to set the child-specific parameters, then convert it to the parent object. Tim Quote Link to comment
jgcode Posted October 20, 2011 Report Share Posted October 20, 2011 Hrm... The only way that I can see to have a dynamic input is to use a variant. A few other options could be to: Pass in configuration data as a Class Use a Factory Pattern Read configuration data from disk inside e.g. Init method 2 Quote Link to comment
SteveChandler Posted October 21, 2011 Author Report Share Posted October 21, 2011 Johnathan, For some reason I never thought of the first one. I will probably go with the last one. I will probably use an INI configuration file that has a parameter for which type of device and it's settings. Awesome. Quote Link to comment
Tim_S Posted October 21, 2011 Report Share Posted October 21, 2011 Pass in configuration data as a Class Use a Factory Pattern Read configuration data from disk inside e.g. Init method Hrm... I'm going to have to go back and look at the Factory pattern. The reading of the configuration is a nice, clean option. I'm not sure how passing the configuration data as a class would work. Does anyone have an example? Tim Quote Link to comment
Daklu Posted October 21, 2011 Report Share Posted October 21, 2011 If I know at edit-time exactly which object I need I stick with a static creator. If I won't know until run-time then I'll use a config object like Jon suggested for single objects or a factory for more complex setup processes aggregate several other objects. I don't typically have the instrument class load configuration info directly from disk. That's a detail I don't want in that class. Instead I put the load/save functionality in the config object. Quote Link to comment
Daklu Posted October 21, 2011 Report Share Posted October 21, 2011 Does anyone have an example? I can't post the source code, but here's part of the initialization routine for an app I'm working on now. My SystemConfig creator takes a path to an xml file as its input and loads/parses all the configuration data for the entire system. The "Get StageConfig" method returns the configuration data specific to the motion control system as a StageConfig object. That object is passed to the "Create Stage" method as an input. You can see I also extract other config information from the SystemConfig object for other aspects of the system. Quote Link to comment
jgcode Posted October 21, 2011 Report Share Posted October 21, 2011 No probs. Johnathan It's 'Jonathon' actually Quote Link to comment
Tim_S Posted October 21, 2011 Report Share Posted October 21, 2011 I can't post the source code, but here's part of the initialization routine for an app I'm working on now. Interesting. Thanks for posting the example. Tim 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.