Using a module within another module
tom82
Posts: 17
I'm fairly new to the world of NetLinx so this may be a stupid question and/or idea, but here goes...
How do you use/address/initialise a module from inside another module?
Basically, I've written a generic PJLink module for projector control, but now want to use it inside an NEC Projector module. That way I only have to implement the commands that aren't already covered by PJLink (it's all a bit OOP). My issue is how do I address it? Ideally it would use a different port on the virtual device, but that doesn't seem to be possible. If I just pick a device number for the PJLink virtual device, then what's to stop it clashing if you've got multiple instances of the module?
Any guidance/suggestions welcome...
How do you use/address/initialise a module from inside another module?
Basically, I've written a generic PJLink module for projector control, but now want to use it inside an NEC Projector module. That way I only have to implement the commands that aren't already covered by PJLink (it's all a bit OOP). My issue is how do I address it? Ideally it would use a different port on the virtual device, but that doesn't seem to be possible. If I just pick a device number for the PJLink virtual device, then what's to stop it clashing if you've got multiple instances of the module?
Any guidance/suggestions welcome...
0
Comments
This means that if you embed module A in another module B:
1. You must be sure to place any declarations of module B that occur in your main program immediately after the declaration of module A.
2. You can only include a single instance of module A in a given program.
3. You can not embed module B in any other modules you might use at the same time as module A
Hope this is helpful.
-Ryan
So for example you'd have:
/**** MAIN.axs *****
vdvDevice1
vdvDevice1PJLink
dvDevice
DEFINE_MODULE 'Device 1' dvMod(dvDevice, vdvDevice1,vdvDevice1PJLink)
/**** DEVICE1.axs ****
MODULE='Device 1'(DEV dvDevice, DEV vdvDevice, DEV vdvPJLink)
//Blah blah constants & variables go here.
DEFINE_MODULE 'PJLink' dvPJLink(vdvDevice,vdvPJLink)
Or something like that depending on your implementation. Keep in mind that the NetLinx Compiler may break itself doing the "Build Active System" because it will attempt to compile things in the wrong order. I have yet to find a way to make them compile in order so you will have to manually compile the system in order for it to work.
@catlino - again, thanks. I had thought of this as a work around, although it's not quite as 'neat' as I would have liked! I also came across the compiler problem - It seems to compile them alphabetically, so I've stared sticking a number at the start of the module name (e.g. m01_PJLINK) to force the compiler to use the right order. Again, an annoying and unnecessary workaround but it does appear to work.
Another workaround is to place the modules in separate systems or project in your workspace, but use the module's AXS as the Main Source instead of placing it in the Modules folder. Then use the tko in your main project. Step 2, copy and paste the systems and projects in the order you want them compiled.
I know it sounds ridiculous, but it works. If you open up an APW file in a text editor, you'll see how it orders and references the files. While the APW does list the files in alphabetical order, projects and systems are listed in the order in which they were added. So, if you want Module B to compile before Module A, copy the system for Module A, and paste it back into your workspace. Though the workspace tree in NetLinx always displays them alphabetically, the APW file will shuffle it to the end, compiling it last.
Thanks Phreak - that's exactly what I was looking for - works brilliantly! There are still some workarounds I've had to put in for other bits and pieces (like sending in an IP device to use - 0:FIRST_LOCAL_PORT+x:0) so that multiple IP devices don't clash, but the dynamic_virtual_device works a charm.