Are there any examples of creating a module?
winstonma
Junior Member
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
-
Check out tech notes 271 (Module Example) and 375 (How to Write Your Own Netlinx Modules)
-
The device driver modules on the AMX website are good examples of module structure and usage.
-
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. -
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) -
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.
-
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
-
Download Denon 3910 modlue from AMX - good example on modlues.
-
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 -
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? -
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.
-
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. -
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? -
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. -
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. -
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...
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums
