Home AMX User Forum NetLinx Studio
Options

Creating Module Using Channel Codes

I have used many and written a few "Modules". I have noticed that Modules by AMX use channel codes often and the ones I have created seem no more then include files with CALLs in them.
How can I make one of my "CALLS" a channel Command ?

Comments

  • Options
    jeffacojeffaco Posts: 121
    I'm not quite sure what you're asking.

    If you're asking that you'd like to turn a channel on or off, or to pulse a channel, then you can just pick channel numbers and use them (in the virtual device).

    Then, in the module, use a

    CHANNEL_EVENT [vd, <chan_num>]

    type event to pick that up.

    Depending on what's going on, I may use a "simple" channel type interface to a module, or a more complex mechanism that passes messages that are picked up by the module. It depends on what I'm doing, and if I need more information than a channel will give me.

    Feel free to look at the sources of modules I've posted up on SourceForge if interested for samples of modules that use both mechanisms. I've included the link multiple times in previous messages.

    -- Jeff
  • Options
    hgrace,

    Jeff once again gave a very good answer. I just want to complete with some theory for hopefully a better understanding.

    A module is essentially a namespace, that is, like another main program. Anything defined in the module can only be used in the module, and a module cannot use any variable or device or whatever from the main program. The only "bridge" are the module parameters (for the variable values, the variable names are still separate), and using this you can "delegate" part of the work to a module.
    For example, you could create a module that blinks a lights (using a relay). The module parameter would be the relay DEVCHAN.
    So, in effect, a module has *no* interface.

    Another feature of NetLinx are virtual devices. A virtual device is exactly like a normal device (has an interface of channels and levels, etc), except it does not do anything by itself unless you program what it should do. You can create a virtual device and an event handler for a channel change of that device. Whenever the rest of your code changes the channel, the handler is called.

    What is done very often is to combine a module with a virtual device. The virtual device implements the interface of the module, and is a module parameter (so that it is known from within the module and withing the main program). The advantage of the module is the different namespace for code reusability. Therefore, whatever the names the AMX programmer gave to his variables inside the module, we are sure they will not conflict with names in your main program.

    The point is there is *no* NetLinx language link between modules and virtual devices. You can use both independantly. It is just that combining both makes a good abstraction tool used in many programming languages.

    Hope this helps

    Fred
  • Options
    Example

    Thanks for the replys but Ithink I may not have expressed my question well enough.
    Lets look at an take an example. The AS16 module uses channel code activity for start and stop ramping :

    PULSE [AS16,1] //Start Ch1 Ramp Up
    PULSE [AS16,2] //Stop Ch1 Ramp Up
    or
    SEND_COMMAND AS16, "'VSP<P1>'" // Store Ch1 Preset

    Another device, I have written code for is a RS232 CCTV Multiplexor. My .axi contains many CALLS to send the strings required:

    CALL 'Mplex_2x2' //Switch to 2x2 quad
    CALL 'Cam_1' //Swich Mon to Cam_1

    I would rather send:

    ON [MPX,22] //Switch to 2x2 quad
    ON [MPX,1] //Swich Mon to Cam_1

    If these Commands would then turn channels on I could als ouse them to easily check the status of the last sent command , or the present state.

    Can this be done ?
  • Options
    jeffacojeffaco Posts: 121
    I'm sorry, I'm still not sure what you're asking.

    I described how you can use channel events in your own module (and frthomas gave some additional useful information if you needed background on how modules work). Did you understand that stuff?

    You say:
    I would rather send:

    ON [MPX,22] //Switch to 2x2 quad
    ON [MPX,1] //Swich Mon to Cam_1

    If these Commands would then turn channels on I could als ouse them to easily check the status of the last sent command , or the present state.

    Can this be done ?

    Yes, it can be done, as per what I specified in my first response. You'd use a virtual device, pass that device in on the module definition, and reference it in channel events to pick up if you turned on channel 22, say, or channel 1. In your example, you're better off PULSEing the channels rather than turning it on. If you have multiple channels on in your above context, I'm not sure what that means.

    I routinely use channels to ramp volume on RS-232 devices, for example. I also send commands; again, it depends what I'm doing.

    For feedback from the module, I generally use strings. That is, commands going from my mainline -> module are sent as SEND_COMMAND by my convention, and responses come back as SEND_STRING (from module -> mainline). As a result, for example, I can pick up where the volume is (assuming an RS-232 controlled device, like a Meridian receiver say) and display that via level commands or via other mechanisms. In this way, I can use one virtual device for both directions (commands go TO module, strings come FROM module) and have everything work smoothly.

    Look at my Meridian module at the same location where I mentioned earlier. Here's a short link to it:

    http://cvs.sourceforge.net/viewcvs.py/netlinx-modules/NetLinx-Modules/Meridian/MeridianMod.axs?view=markup

    Go to the very end of that, and you'll see an example of how I can receive a command from mainline, as well as receive channel events.

    I hope this answers your question. If not, can you try again, hopefully being a little clearer in what you're asking?

    -- Jeff
  • Options
    Using your example:

    DEFINE_DEVICE

    MPX = 33333:1:0; // virtual device, any number from 32,768 to 36,863

    DEFINE_EVENT

    CHANNEL_EVENT[MPX, 22]
    {
    ON:
    {
    CALL 'Mplex_2x2' //Switch to 2x2 quad
    // I made the event handler call your procedure here for the
    // explanation, but will probably want to put the CODE of the
    // call here....
    }
    OFF:
    {
    // whatever happens when channel 22 is turned off on
    // your CCTV mux, probably switch to one main screen or
    // something...
    }
    }

    CHANNEL_EVENT[MPX, 1]
    {
    ON:
    {
    CALL 'Cam_1'
    }
    }

    DEFINE_PROGRAM
    ...

    Now in the code you can use ON[MPX,22] and the handler above will be called.
    There is no module above, it is not needed to use virtual devices and channels. You can if you want create a module to hold all of the event handlers for the virtual device MPX (and any variable and call you may need), but that won't bring any benefit other than the namespace as I mentioned. It will be functionally identical to the above.

    Hope this helps

    Fred
  • Options
    Thanks Fred

    Now THAT'S what I'm talkin' 'bout
Sign In or Register to comment.