Jump to content

Overriding a Method


Recommended Posts

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.

Link to comment

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

Link to comment
  • 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

Link to comment

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.

Link to comment

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.

post-7603-0-52938800-1319158679.png

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.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.