Home AMX User Forum NetLinx Studio
Options

Are there any examples of creating a module?

I am a newbie on AMX programming. I would like to know if module is similar to class in C++? So I can create a class(module) and then later on create an instance for it? If yes are there any possible sample to show me how to create/call a module?

Comments

  • Options
    Joe HebertJoe Hebert Posts: 2,159
    Check out tech notes 271 (Module Example) and 375 (How to Write Your Own Netlinx Modules)
  • Options
    NMarkRobertsNMarkRoberts Posts: 455
    The device driver modules on the AMX website are good examples of module structure and usage.
  • Options
    winstonmawinstonma Posts: 45
    Thanks for the module example 271. But I wonder if I can do the function call on AMX?

    For example if I have a touchpanel button, once the button is actived. DVD and projector will be both turned on. So I wonder if I can write a module which can provide function call.
  • Options
    SensivaSensiva Posts: 211
    We Call This Macros

    Welcome winstonma...

    We Call this a Macro , so no need to write modules
    if your button channel code is 1
    button_event [TP,1]
    {
    Push:
    {
    On[dvPROJECTOR]
    On[dvDVDPLAYER]
    }
    }

    of course you should do some changes in this code.. i don't know how your devices being controled (IR, RS232,...etc)
  • Options
    winstonmawinstonma Posts: 45
    Yeah but since I use that machine very frequent. So I want to make it a module so I dun need to rewrite that every time (reuseablilty). So I wonder if module will work as a C++ class.
  • Options
    SensivaSensiva Posts: 211
    To be honest

    I have never been working with C classes, but generally you can do whatever you want in modules.. anything applies to the main code applies to the modules

    to make things clear.. modules are separate programs that can run simultaneously with your main program , and you can make run more than one instance of your module.

    Finally .. as long as you can write your own netlinx code.. you can write your own modules :)
  • Options
    adysadys Posts: 395
    Download Denon 3910 modlue from AMX - good example on modlues.
  • Options
    Spire_JeffSpire_Jeff Posts: 1,917
    You can use DEFINE_CALL and DEFINE_FUNCTION like this:

    DEFINE_CALL 'DEVICE POWER' (INTEGER nPWR)
    {
    SWITCH(nPWR)
    {
    CASE 0: //OFF
    {
    PULSE[dvTV,28]
    PULSE[dvDVD,28]
    PULSE[dvVCR,28]
    }
    CASE 1: //ALL ON
    {
    PULSE[dvTV,27]
    PULSE[dvDVD,27]
    PULSE[dvVCR,27]
    }
    CASE 2: //AUDIO ONLY
    {
    PULSE[dvDVD,27]
    PULSE[dvVCR,27]
    }
    }
    }

    DEFINE_FUNCTION INTEGER DEVICE_POWER(INTEGER nPWR)
    {
    SWITCH(nPWR)
    {
    CASE 0: //OFF
    {
    PULSE[dvTV,28]
    PULSE[dvDVD,28]
    PULSE[dvVCR,28]
    }
    CASE 1: //ALL ON
    {
    PULSE[dvTV,27]
    PULSE[dvDVD,27]
    PULSE[dvVCR,27]
    }
    CASE 2: //AUDIO ONLY
    {
    PULSE[dvDVD,27]
    PULSE[dvVCR,27]
    }
    }
    RETURN 1;
    }


    If you need to use these functions in a lot of projects, just put them in a seperate include file and include that file in all projects.

    Jeff
  • Options
    flcusatflcusat Posts: 309
    Spire_Jeff wrote:
    You can use DEFINE_CALL and DEFINE_FUNCTION like this:

    DEFINE_CALL 'DEVICE POWER' (INTEGER nPWR)
    {
    SWITCH(nPWR)
    {
    CASE 0: //OFF
    {
    PULSE[dvTV,28]
    PULSE[dvDVD,28]
    PULSE[dvVCR,28]
    }
    CASE 1: //ALL ON
    {
    PULSE[dvTV,27]
    PULSE[dvDVD,27]
    PULSE[dvVCR,27]
    }
    CASE 2: //AUDIO ONLY
    {
    PULSE[dvDVD,27]
    PULSE[dvVCR,27]
    }
    }
    }

    DEFINE_FUNCTION INTEGER DEVICE_POWER(INTEGER nPWR)
    {
    SWITCH(nPWR)
    {
    CASE 0: //OFF
    {
    PULSE[dvTV,28]
    PULSE[dvDVD,28]
    PULSE[dvVCR,28]
    }
    CASE 1: //ALL ON
    {
    PULSE[dvTV,27]
    PULSE[dvDVD,27]
    PULSE[dvVCR,27]
    }
    CASE 2: //AUDIO ONLY
    {
    PULSE[dvDVD,27]
    PULSE[dvVCR,27]
    }
    }
    RETURN 1;
    }


    If you need to use these functions in a lot of projects, just put them in a seperate include file and include that file in all projects.

    Jeff

    So when you want to do a Power On or a Power Off how do you assign the properly value to the nPWR variable?
  • Options
    NMarkRobertsNMarkRoberts Posts: 455
    You refer to classes which sounds to me like generally available subroutines. The way to do that is to create an include file and include it where you need it.
  • Options
    viningvining Posts: 4,368
    flcusat wrote:
    So when you want to do a Power On or a Power Off how do you assign the properly value to the nPWR variable?

    The simplest way is to have three buttons: system off, watch tv and listen to music (shown below in array positions 1,2,3) and just to confuse matters I chose the random channel number values for the buttons in those positions and on a button push:
    INTEGER nCH_BtnArry[] = // CHANNEL BUTTONS ON TOUCH PANEL
         
         {
         12,	//1-	System off
         14,	//2-	watch tv
         32	//3-	listen to music
         }
         
    BUTTON_EVENT[dvSystem,nCH_BtnArry]
         
         {
         PUSH:
    	  {
    	  DEVICE_POWER(GET_LAST(nCH_BtnArry) - 1) ;
    	  }
         }
    

    The button index position that is returned by the GET_LAST system function - 1 when button channel 12, 14 or 32 is pushed gets passed to the function "DEVICE_POWER" where it is referenced as nPWR.

    Note that this works on the index postion of the pushed button's channel value not the actual button channel it self.
  • Options
    flcusatflcusat Posts: 309
    vining wrote:
    flcusat wrote:


    The simplest way is to have three buttons: system off, watch tv and listen to music (shown below in array positions 1,2,3) and just to confuse matters I chose the random channel number values for the buttons in those positions and on a button push:
    INTEGER nCH_BtnArry[] = // CHANNEL BUTTONS ON TOUCH PANEL
         
         {
         12,	//1-	System off
         14,	//2-	watch tv
         32	//3-	listen to music
         }
         
    BUTTON_EVENT[dvSystem,nCH_BtnArry]
         
         {
         PUSH:
    	  {
    	  DEVICE_POWER(GET_LAST(nCH_BtnArry) - 1) ;
    	  }
         }
    

    The button index position that is returned by the GET_LAST system function - 1 when button channel 12, 14 or 32 is pushed gets passed to the function "DEVICE_POWER" where it is referenced as nPWR.

    Note that this works on the index postion of the pushed button's channel value not the actual button channel it self.

    Ok there is something that I don't understand.
    GET_LAST (nCH_BtnArry) -1. How does this work in plain english?
  • Options
    flcusatflcusat Posts: 309
    flcusat wrote:
    Ok there is something that I don't understand.
    GET_LAST (nCH_BtnArry) -1. How does this work in plain english?

    Never mind. I figured it out. Thanks for the example.
  • Options
    yuriyuri Posts: 861
    winstonma:

    a netlinx module is something like a class in C.
    You can indeed make an instance of it, but you can't reference to variable, functions, calls, whatever from another class/mainline.
  • Options
    adysadys Posts: 395
    yuri wrote:
    winstonma:

    a netlinx module is something like a class in C.
    You can indeed make an instance of it, but you can't reference to variable, functions, calls, whatever from another class/mainline.

    Unfortunately, not like in C++.

    being unable to call module functions is a huge disadvantage and a major hole in the design of AMX module system...
Sign In or Register to comment.