Home AMX User Forum Duet/Cafe Duet
Options

Duet code example - Extron DVS304

Hi everyone!

This is my first Duet module.
Not all functions are being implemented because just of testing purposes.
Two files attached: the source in txt &the whole Duet project.

Have a nice coding!

p.s. Now i'll try to write an module which deals with two NetLinx devices: IR & TP for example.
Does anyone have an idea how to pass two different NetLinx devices to module and grab them in Duet?

Comments

  • Options
    Spire_JeffSpire_Jeff Posts: 1,917
    I think you would just add another argument to the module declaration and deal with it in Duet like the other devices being passed in... but it has been a while since I worked with Duet. (Something I hope to change next year)

    Just be cautious tho with what you are passing to the Duet side. Once Duet takes control of a device, the NetLinx side no longer receives events from the device (as I recall). This is not a problem if you are coding only in Duet, but could cause problems if you share ports on a touch panel with multiple modules and they are not all Duet modules.

    Jeff
  • Options
    Thanks for advice!

    I just cant take in mind how to declare these arguments (DPS Devices) in Duet.
    Maybe i should do something like that:
    1) Add in *.axs files one more item in DUET_PROPERTIES like "Physical-Device2"
    2) From Duet grab the DPS with props.getProperty("Physical-Device2"))
    ...
    any way i should try it.
  • Options
    You could add a parameter to the module definition, but you would have to manually re-work the associated AXS file for the module which is not an easy task at all. I generally leave that netlinx file alone and pass the parameters directly into the module with a SEND_COMMAND.

    The easiest way that I have found is to use the Set Property command to pass in custom parameters. You do this as follows:

    In Netlinx, simply send the parameters to the Duet Virtual Device:

    SEND_COMMAND vdvDuet," 'PROPERTY-',key,value" where key and value are both strings of what you want to pass in. You can pass a device by converting the D:P:S to Ascii values of the Device, Port, and System.

    Within Duet, then add the method for setProperty as follows:

    public void setProperty(String key, String value) {
    // process key and value here as needed, such as:
    if (key.equals("defineNewDevice")) {
    // define new Netlinx Device, where value="d:p:s" as a string
    }
    }

    To define a NetlinxDevice on the fly, you can do something like the following:

    a) define the NetlinxDevice object:

    NetLinxDevice dvMyDevice;

    b) then in your code, either under the setProperty function or somewhere else, define the device as follows:

    NetLinxDevice dvMyDevice = new NetLinxDevice(new DPS(value), bVirtual);
    // where bVirtual = true for a Virtual Netlinx device or false for an actual device (any device under 32000)
    dvMyDevice.notifyOnline();
    dvMyDevice.initialize();

    You can also add any listeners such as for data events, button events, etc. but do so before the above initialize() statement.

    In fact, I do this so often that I create a function to handle it for me as follows:

    public NetLinxDevice createNetlinxDev(String value, IDataListener iDatal, IButtonListener iBtnl,
    IChannelListener iChanl, ILevelListener iLvll, boolean bVirtual) {
    NetLinxDevice dev = new NetLinxDevice(new DPS(value), bVirtual);

    if (iBtnl != null)
    dev.addButtonListener(iBtnl);
    if (iChanl != null)
    dev.addChannelListener(iChanl);
    if (iLvll != null)
    dev.addLevelListener(iLvll);
    if (iDatal != null)
    dev.addDataListener(iDatal);

    dev.notifyOnline();
    dev.initialize();

    return dev;
    }

    where I can pass in the appropriate values, listeners, etc. as needed and the function returns the device.
  • Options
    Thank you for almost step-by-step guide!
    I'll try to follow it and think that it will be very useful not only for me.
    But at first I just try correcting the AXS file.
    And write about my results here.
  • Options
    Passing in extra parameters via Define_Module

    You actually can pass in additional parameters (beyond the 2 basic devices), but be aware that if you do this, you can no longer use the Regenerate function within Duet. I'm not 100% what all the Regenerate even does, but one thing it will do is re-build part of the default AXS file, which will break any changes you make. to pass in an extra parameter, such as an integer, called myInt, you would use the following define_module (or something close):

    DEFINE_MODULE 'duetModule_dr1_0_0' mdlDuetMod (vdvDuetDev, vdvDeviceDev, myInt)

    In the AXS file for your duet module, you'll make 3 changes:

    a) At the top, change the header to:
    MODULE_NAME='duetModule_dr1_0_0' (DEV dvDuetDevice, DEV dvPhysicalDevice, INTEGER myIntVar)

    b) Expand the CHAR array as needed:
    CHAR DUET_PROPERTIES[10][47] =
    {
    // add your new property here after the nine default properties, such as:
    'MyCustomProp'
    // be sure to add a "," after the ninth property that is in the default list
    }

    c) Define the new property as follows:
    DUET_PROPERTIES[10] = "'MyCustomProp=',FORMAT('%d',myIntVar)";

    Then within Duet, load that property into an Integer variable when you define the module as follows:

    nMyInt = Integer.parseInt(props.getProperty("MyCustomProp"));

    And yes, this does work and seems quite simple. I had not tried this before, but it may be something that I'll use in the future. I suspect that this only works with parameters that are passed in at compile time. I don't know if you would be able to change "myInt" and have the Duet module know that it has changed, but someone will have to test that scenario separately.

    The other method using a SEND_COMMAND and the setProperty method would work at any time after a program starts to change or update any parameter or even to trigger a process within your duet module. I sometimes will pass in a simple value of "0" as a place holder if I just need to trigger a process to start with no data. In that case, the key is the process that I want to trigger.

    Hope this helps.

    Sheldon Samuels
    SchoolView Technologies, LLC
Sign In or Register to comment.