Home AMX User Forum NetLinx Studio

DEVCHANs and Modules??

Hi,

I was creating my first module, I thought something simple would be good to start with...Anyways, I quickly realized that you cannot create a devchan array in the module itself. I put it into the main program and everything works correctly, however It for some reason bothers me leaving it there. I was wondering what some alternatives are and also if leaving it there is as big of a deal as Im making it out to be. If anybody has a better way to go about doing this Their input would be greatly appreciated. Thanx in advance.

Below is the function in the module that handles the tp input
devchan name is dcBLURAY

define_function fnBluray()
{
stack_var integer x
nBlurayInp=get_last(dcBLURAY)
for (x=1;x<=40;x++)
{
if (x==nBlurayInp)
{
pulse [dvBluray,nBlurayInp]
}
}
}

Comments

  • AMXJeffAMXJeff Posts: 450
    SCOTTYP wrote: »
    Hi,

    I was creating my first module, I thought something simple would be good to start with...Anyways, I quickly realized that you cannot declare a devchan array in the module itself. I put it into the main program and everything works correctly

    you can pass the devchan array into the module...

    // module header
    MODULE_NAME='WHATEVER' (DEVCHAN dcButtonList[])

    // main code
    DEFINE_START

    DEFINE_MODULE 'WHATEVER' modwhatever(dcVCRButtons)
  • SCOTTYPSCOTTYP Posts: 32
    Yeah..I was able to pass ther array into the module. I wanted to create the array in the module???
  • a_riot42a_riot42 Posts: 1,624
    SCOTTYP wrote: »
    devchan name is dcBLURAY
    
    define_function fnBluray()
    {
        stack_var integer x
        nBlurayInp=get_last(dcBLURAY)   
        for (x=1;x<=40;x++)
        {
    	if (x==nBlurayInp)
    	{
    	    pulse [dvBluray,nBlurayInp]
    	}
        }
    }
    

    Not sure what you are up to here. What's the point of the for loop?
    Paul
  • DHawthorneDHawthorne Posts: 4,584
    GET_LAST isn't going to work properly inside a function. It is intended only to be inside an EVENT handler, and acts on the parameters of the event. You can't guarantee, once scope has passed out of the handler to the function, that the value is going to be correct anymore. If your function is called from the event handler, use GET_LAST to pass the value to the function, don't call it from inside the function.

    And I echo the question about that FOR loop - looks like it does nothing, unless you only posted a partial code block. If that's all there is to it, you could have done the whole thing without a function at all in a single line of code: pulse[dvBluray, get_last(dcBLURAY)] .
  • AMXJeffAMXJeff Posts: 450
    SCOTTYP wrote: »
    Yeah..I was able to pass ther array into the module. I wanted to create the array in the module???

    Do not understand why anyone would want to do this, it causes the module to be not as portable. But, I am assuming you can't do it because the DEV is a variable and not a constant.

    In this case you can do an interger array of buttons (channels).
    DEFINE_VARIABLE
    
    INTEGER nButtons[] =
    {
       100,
       101,
       102
    }
    
    DEFINE_EVENT
    
    BUTTON_EVENT[dvTP,nButtons]
    {
        PUSH:
        {
             STACK_VAR INTEGER nIndex;
    
             nIndex = GET_LAST(nButtons);
        }
    }
    
    
  • SCOTTYPSCOTTYP Posts: 32
    As you can probably see by now I am somewhat new to this.....As I stated this is my first attempt at a module. I am going to try and be as detailed as possible this time. I posted my code so you can critique my form. As per daves suggestion I got rid of the function and put it into a button event. Just so we are on the same page this module works....I am navigating a dvd menu as we speak (with the function and the loop). I realize there are better ways (much easier as I see now), this is just the first thing that came to mind and I went with it (speaking of the loop). What I was trying to do is create In module for all of our Bluray players, combo units and vcrs on Campus (I work for a school). I looked up the standard api for disc devices and just wanted to be able to create an ir file per those api standards, upload the ir file to the controller, replace the device and be done when a device goes bad.
    I took out the loop, and was going to try and use an integer array like jeff suggested ... Im hoping this question doesnt make you guys dumber just by reading it but: I was using the devchan so I could use the get last and know what bluray function was pushed (because I numbered the channels in the ir file to match the channels of the TP buttons)....When using the get_last on the integer array ( like jeffs example) how does the get_last know what button I pushed?? Im not enirely sure that will even make sense to someone other than me, but I gave it my best shot. Thankyou Jeff, Dave, and Paul for your responses....Oh, and how do you get seperate sections for your code to pop up in the post?? The only options I see are adding attachments?? Id like to make this as painless as possible for you and im hoping that at least one of you couldnt figure that out at one point..maybe
  • AMXJeffAMXJeff Posts: 450
    SCOTTYP wrote: »
    When using the get_last on the integer array ( like jeffs example) how does the get_last know what button I pushed??

    Get_Last works on any array that was used in the parameter section of any event. It is smart enough to know how to compare dev arrays, integer array or devchan arrays.
  • SCOTTYPSCOTTYP Posts: 32
    Thanx alot Jeff...I get it and it worked great!
  • a_riot42a_riot42 Posts: 1,624
    My advice is don't use devchans at all. I have been writing code for 10 years and AMX for 5 and have never once used a devchan. They are almost as evil as combines.
    Paul
  • dchristodchristo Posts: 177
    a_riot42 wrote: »
    They are almost as evil as combines.

    Could you elaborate a little more? Why do you consider DevChan's evil?

    --D
  • a_riot42a_riot42 Posts: 1,624
    dchristo wrote: »
    Could you elaborate a little more? Why do you consider DevChan's evil?

    --D

    I consider them evil because they reduce the decoupling that good programming should adhere to. I also can't think of a good reason to ever use them. If you know of one, please let me know.
    Paul
  • DHawthorneDHawthorne Posts: 4,584
    a_riot42 wrote: »
    I consider them evil because they reduce the decoupling that good programming should adhere to. I also can't think of a good reason to ever use them. If you know of one, please let me know.
    Paul

    I thought they were a great idea when first introduced, but after doing a project almost entirely in devchans, and losing most of the hair I still have left, I abandoned them almost entirely. There are one or two situations where they are convenient, but mostly I stay well away. It is, quite simply, much easier to deal with integer arrays for channels, and dev arrays for devices, and pretty near no advantage to a devchan except a tiny bit less typing.
  • Spire_JeffSpire_Jeff Posts: 1,917
    a_riot42 wrote: »
    I consider them evil because they reduce the decoupling that good programming should adhere to. I also can't think of a good reason to ever use them. If you know of one, please let me know.
    Paul

    I can think of one good place to use devchans, and that would be when I use AMX relay ports. This allows me to create an easy way to remember and control the relays. As I think about it, you could do it with a dvRelay and constants, but either way accomplishes the goal. It's just a question of which do you prefer:
    pulse[dcDrapesOpen];
    

    or
    pulse[dvRelay,DrapesOpen];
    

    Jeff
  • a_riot42a_riot42 Posts: 1,624
    DHawthorne wrote: »
    I thought they were a great idea when first introduced, but after doing a project almost entirely in devchans, and losing most of the hair I still have left, I abandoned them almost entirely. There are one or two situations where they are convenient, but mostly I stay well away. It is, quite simply, much easier to deal with integer arrays for channels, and dev arrays for devices, and pretty near no advantage to a devchan except a tiny bit less typing.

    That was my experience exactly when handed a project to finish that another programmer started who thought devchans were a good idea. I can see for relays they might be slightly helpful, but then then why have two ways to accomplish the same thing? It just adds confusion so I have banned them from our programming along with combines.
    Paul
Sign In or Register to comment.