Dynamically load modules
yuri
Posts: 861
Hi all,
I'm working on a project and I want to try something, but before I do, I would like some feedback.
It's a big project and I want to make things as dynamic as possible.
Therefore I want to engineer a single program that can be used in all the rooms (they all differ slightly from each other)
Touchpanel design is already done, I'm building that from a .xml file, works like a charm, and I would like to do the same for programming code.
What I had in mind is the following:
There are several rooms, and in total, there are 3 different types of LCD that can be used in a room.
I wanted to define all 3 modules I have, and make each module useless by setting the device port to a "non existing" port. (6001:1:0 for example)
After I have discovered what type of room it is, I wanted to set the device of the correct module to the "real" port (5001:1:0 for example)
Is this the right way? I understand it may not be the nicest way, but I reckon it should work.
Only thing is, what happens if you define something on a "non existing" port and send data to it?
Will errors be generated?
Maybe there are some better way to achieve what I want to do, hope someone can help me out...
I'm working on a project and I want to try something, but before I do, I would like some feedback.
It's a big project and I want to make things as dynamic as possible.
Therefore I want to engineer a single program that can be used in all the rooms (they all differ slightly from each other)
Touchpanel design is already done, I'm building that from a .xml file, works like a charm, and I would like to do the same for programming code.
What I had in mind is the following:
There are several rooms, and in total, there are 3 different types of LCD that can be used in a room.
I wanted to define all 3 modules I have, and make each module useless by setting the device port to a "non existing" port. (6001:1:0 for example)
After I have discovered what type of room it is, I wanted to set the device of the correct module to the "real" port (5001:1:0 for example)
Is this the right way? I understand it may not be the nicest way, but I reckon it should work.
Only thing is, what happens if you define something on a "non existing" port and send data to it?
Will errors be generated?
Maybe there are some better way to achieve what I want to do, hope someone can help me out...
0
Comments
If your modules are designed with the same basic architecture, and alternative would be to interface with a virtual module in your main code, then combine it with the appropriate "real" device based on your room type. That's how I would do it; it's the one case I would still use COMBINE_DEVICES. You could even hide and show buttons as appropriate and use the same interface for all of them, or, if that doesn't work esthetically, have the module determine what control pages are available and call them as popups as desired. I think that's a more graceful solution than sending to a non-existent port (though you certainly could, that's just my own preference).
I'll give that a try, thanks for the advice!
I use a null device of 0:0:0 which works fine. You can see the way I do it in the code I posted here: http://www.amxforums.com/showthread.php?t=6154
Essentially, I have a small include file whose sole purpose in life is to monitor the devices passed to the module using it. If they change, a rebuild_event() is performed along with any other things required to make the module active.
I trade off having to allocate memory for as many virtual devices as I have modules in the code (which may not be used in a particular system - potentially many dozen) with having a timeline run in each module. I'm not sure that this is the best way of doing things, but I haven't run into any limitations with it so far. Seems to work well on large commercial projects.
I also load my interface definitions from an XML file, so it sounds like we're thinking along the same lines.
I am doing the same thing, read thread: http://www.amxforums.com/showthread.php?t=6154
Solution 1
I used virtual devices at first and passed those to my module. Used combine_devices with the actual port with the virtual port 5001:2:0 with 33100:1:0. The only problem is I didnt' see the traffic on the 5001:2:0 port. I only saw the command and the echo'ed command on the virtual. I module worked sending out commands and controlling the device, I just like to see the feedback.
Solution 2
Another approach I took was changing the variable's value of the device that is passed into the module. The only problem with netlinx and this approach is I have no way to reinitalize the create buffer on the new device. I still was not seeing feedback from the device. Only way to get around this is Duet, not happening. I tried using rebuild_event() but that does not take care of the Buffer problem, only takes care of the touch panels array.
Solution 3
I just passed the same device into all 3 modules. Created a module on/off variable with a virtual command to turn it on/off. When I found out the correct type of display I just enable that module.
Solution 3 - Winner - was the easiest for me to implement without having to go duet and I still see all the traffic on the port because I'm not using virtuals for the actual device.
I'm glad there isn't some sort of hidden way to get this done, because all the options you guys come up with look sure look like mine.
jgreer9514:
I was going to try Solution 2, but now I see that CREATE_BUFFER doesn't work, I won' try that one...
Auser:
I also tried the 0:0:0 solution, and that worked fine. I just thought it may decrease the master's performance if done a lot of times.