Jump to content

Choose Child Implementation based on configuration file

Recommended Posts

I am struggling with how I handle the situation in the title.


We have a number of devices that use different IR protocols.  I have a Parent Class (IR), and multiple child classes (DeviceA, DeviceB, etc).


I have a Test Sequence Editor that we use on our test program, and an option I want to add is IR Command selection.  I would also add a IR Parameter section to allow for specific inputs based on the command selected.


So the Test Step would have: IRCommand: 'DeviceA,60' (for Protocol 'DeviceA' and to send command 60) and maybe IRParameter is a string 'ABCDEF'.


Each command can have different inputs and outputs (string, numeric, etc).


I figured I could use the 'To More Specific' class to choose the child (see pic below), but I am not sure how I can setup the message correctly.




I currently have it implemented where I have a case structure in my program for each command.  By this I mean, case 60 uses the Command 60 implementation of the IR Parent class, and each child is dynamically dispatched.


However, I would prefer to move this into a class somehow, instead of copy a case structure into each program (defeats purpose of just updating class and not each program that uses this).


I attached a simple example (please excuse the horrible wiring, it was a fast example)




Edited by dblk22vball
Link to comment

There is a function called get lv class default value by name which you might be able to use. It requires that the class is already in memory, but if you follow a standard naming convention "DeviceA.lvclass", "DeviceB.lvclass" your user can just type in "A" or "B", you can format that into your class name, and then use that function to grab the right class.


We've also done something more general for our configuration editor framework here: https://github.com/NISystemsEngineering/CEF/tree/master/Trunk/Configuration%20Framework/class%20discovery%20singleton

Basically it lets you add a search folder and will try to locate the desired class by qualified name, by filename, or by unqualified name and then pass out the result. Its not particularly fancy but it helps avoid simple errors like case sensitivity and the like. (As a side note if you're likely to have classes where case sensitivity matters or if you have classes with the same unqualified name (Blah.lvclass) but a different qualified name (A.lvlib::Blah.lvclass vs B.lvlib::Blah.lvclass) then you shouldn't use this. But then you also probably shouldn't be doing those things.)

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.

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.