Home AMX User Forum NetLinx Modules & Duet Modules

Using a module within another module

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...

Comments

  • rfletcherrfletcher Posts: 217
    Based on the information in netlinx keywords help, declaring modules in other modules looks like its generally a bad idea as all declarations of a given module in a program must not be separated by decelerations of other modules.

    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
  • catalinocatalino Posts: 25
    This is possible- You would simply define it as a module and pass its VDV as a parameter from the main code. That way you are really just passing it twice, but this is the only way to ensure that you don't accidentally invoke the same module call twice. I do this using a queueing communications module that I built.
    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.
  • tom82tom82 Posts: 17
    @rfletcher - thanks for the reply. Yes, I just found this bit in the Netlinx help (it's not entirely easy to navigate).

    @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.
  • nicholasjamesnicholasjames Posts: 154
    This was also discussed in this thread: Why Must Multiple Modules Be Defined Together?
  • nicholasjamesnicholasjames Posts: 154
    tom82 wrote: »
    @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.
    Clever fix. Never thought of that.

    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.
  • PhreaKPhreaK Posts: 966
    You want to check out 'dynamic_virtual_device'. It's not documented but it works. Use like so:
    define_device
    fooBar = dynamic_virtual_device
    
    and it will assign a unique virtual device in the dynamic virtual device range. Have a look in [post=54099]this thread[/post] for more info.
  • tom82tom82 Posts: 17
    PhreaK wrote: »
    You want to check out 'dynamic_virtual_device'. It's not documented but it works.

    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.
Sign In or Register to comment.