Example source code resources

Rich AbelRich Abel Junior MemberPosts: 104
I'm new to Netlinx programming and wishing I had more sample sources to review. I have all of the AMX documentation, but wish I had more samples to review to understand the application of the various elements of Netlinx.

Today I've been creating a new Function and I find that it partially works. However it doesn't seem to be accepting the second paramater that it passed to it. Real world examples of multi-paramater function would help supplement the AMX docs and on-line help.

Any suggestions on where to look?

Thanks
Rich Abel

Comments

  • jeffacojeffaco Junior Member Posts: 121
    Sourceforge?

    Well, there's the NetLinx library that I created up on SourceForge:

    http://sourceforge.net/projects/netlinx-modules/

    It has bunches of source code up there. Notable examples:

    SlimServerMod, a module to drive the SqueezeBox from Slim Devices. See this screen shot.

    TimeSyncMod, a module that syncronizes the system time via a variety of SNTP servers. This is the basis for i!-TimeManager (which code was also included in the schedule module AMX wrote).

    AudiotronMod, a module that drives the Audiotron from Turtle Beach. This is notable because the Audiotron's API was implemented via HTTP, so AudiotronMod drove the device via HTTP.

    SyslogMod, a module that allows logging to a syslog server. All of the modules on SourceForge optionally use this to allow for rich debugging of the code.

    RadioRA, a module that drives Lutron's RadioRA controller. It's better than the one AMX provides in two ways: (1) Source code is provided, and (2) It supports multiple RS-232 controllers on multiple home codes (for a virtually unlimited number of switches); AMX only supports one.

    All of the above modules use the networking capabilities of NetLinx heavily (except RadioRA - it just uses RS-232).

    Unfortunately, I'm the only one that puts code up on SourceForge. I'm perfectly willing to put other folks' code up on SourceForge, but nobody else ever wants to contribute.

    -- Jeff
  • ldeblank@jnv.nl[email protected] Junior Member Posts: 58
    Function

    Hello Rich,
    Here a small function to show how to use with multiple parameters.

    // the function remove astring from a array
    DEFINE_FUNCTION CHAR[3] fn_REMOVE_STRING (BUFFER_ARRAY[15],SEARCH_STRING[15])
    {
    REMOVE_STRING(BUFFER_ARRAY,SEARCH_STRING,1)
    RETURN BUFFER_ARRAY
    }


    // the way the function is called
    DATA_EVENT[vdv_dev]
    {
    STRING:
    {
    IF (FIND_STRING(DATA.TEXT,'DEVICE=',1))
    {
    dev_NUMBER=fn_REMOVE_STRING (DATA.TEXT,'DEVICE=')
    }
    }
    }

    Good luck
  • Rich AbelRich Abel Junior Member Posts: 104
    Function that doesn't seem to second paramater

    Thanks for the suggestions and the example.

    Here's the specific Function that generated my interest in looking at examples. The integer Param doesn't appear to be passed to ProjCmd.

    DEFINE_FUNCTION integer ProjCmd(CHAR Cmd[3],INTEGER Param)
    LOCAL_VAR integer retcode
    {
    proj_return='' // clear input buffer
    send_string 0,"'!1',$20,Cmd,$20,Param,$0D" // debug code
    send_string dvPROJ,"'!1',$20,Cmd,$20,Param,$0D"
    wait 30
    {
    if(Cmd='U2A') // Quick Align: unique timing, wait 3 s after retn
    {
    SEND_STRING 0, "'Quick Align Detected, waiting 3 sec',$0D"
    wait 30
    {
    If(proj_return="'@1',$20,'0',$0D")
    {
    wait 30 // Wait for QA to complete
    {
    retcode=1
    }
    }
    if(find_string(proj_return,"'@1',$20,'A'",1))
    {
    retcode=0 // function error return
    SEND_STRING 0,"'Projector Command Error:',proj_return"
    }
    }
    }
    else // Std. funct. ret in 3 s
    {
    wait 30
    {
    If(proj_return="'@1',$20,'0',$0D")
    {
    retcode=1 // normal
    }
    }
    if(find_string(proj_return,"'@1',$20,'A'",1))
    {
    retcode=0 // error
    SEND_STRING 0,"'Projector Command Error:',proj_return"
    }
    }
    }
    RETURN retcode
    }

    Calling code:
    button_event[dvTP,3] // select component video input
    {
    push:
    {
    ProjCmd('U1A',2)
    }
    }
  • ldeblank@jnv.nl[email protected] Junior Member Posts: 58
    integer

    Hi Rich,

    Your function definition shows:
    DEFINE_FUNCTION integer ProjCmd(CHAR Cmd[3],INTEGER Param)

    Try the following:
    DEFINE_FUNCTION ProjCmd(CHAR Cmd[3],INTEGER Param)

    Good luck
  • mpullinmpullin Obvious Troll Account, Marked for Deletion Posts: 949
    Hi Rich,

    Your function definition shows:
    DEFINE_FUNCTION integer ProjCmd(CHAR Cmd[3],INTEGER Param)

    Try the following:
    DEFINE_FUNCTION ProjCmd(CHAR Cmd[3],INTEGER Param)

    Good luck

    I don't think this is the problem. DEFINE_FUNCTION expects that you give it a return type, in this case INTEGER. The protocol for DEFINE_FUNCTION is this:
    DEFINE_FUNCTION [<return type>]<name>[(<param1>,<param2>, ? <paramN>)]
    { (* statements *) }
    

    However I see two potential problems with your code.

    1) You are declaring a LOCAL_VAR outside the brackets. This is only supposed to work for DEFINE_CALL routines. Try moving the declaration to inside the bracket.

    Also, because you're not using this variable across different calls to this function, a STACK_VAR would be more efficient. STACK_VARs only live as long as the function call is being run. LOCAL_VARs are initalized the first time the function is run, and then they live for as long as the program runs.

    2) Your function returns an integer, but your code isn't doing anything with it.
    If you don't need to use the 1 or 0 that your code returns outside of the function itself, you might as well change this to a DEFINE_CALL.
    If you do need that 1 or 0 you should create a variable in your main code to put it in, e.g.
    button_event[dvTP,3] // select component video input
    {
         push:
         {
              STACK_VAR INTEGER result
              result = ProjCmd('U1A',2)
              // result now contains a 1 or 0 depending on the success of ProjCmd
         }
    }
    
  • Rich AbelRich Abel Junior Member Posts: 104
    Suggestions

    Thanks for the suggestions. I did finally get the code working....I needed to change the second paramater to a CHAR since it becomes part of a string.

    I do intend to use the return value. To find my problem I was testing the function in a separate piece of code.

    I'll look at the STACK VAR approach.

    This is a great resource...much appreciated.

    Rich
  • youstrayoustra Junior Member Posts: 135
    Anyone have a copy of syslogmod?

    I can't find mine and I don't see it on sourceforge anymore. Looks like jeffaco's gone dormant. I'm hoping someone out there has a copy they can share/post.
  • mpullinmpullin Obvious Troll Account, Marked for Deletion Posts: 949
    I can't believe I actually recommended to someone to use a DEFINE_CALL.

    .. Oh wait, this thread was from 2005. -_-
  • chillchill Luddite Posts: 186
    mpullin wrote: »
    I can't believe I actually recommended to someone to use a DEFINE_CALL.

    .. Oh wait, this thread was from 2005. -_-

    What's wrong with define_call? It's just a subroutine. Use define_function if you need to return a value, define_call if you don't.
    .
  • HedbergHedberg Junior Member Posts: 671
    i've gotten into the habit of using define_function every time and define_call never. What's the advantage to define_call if there is no need for a returned value?
  • chillchill Luddite Posts: 186
    There's no advantage either way. It just "looks funny" to me to use a function as a subroutine. As you put it, it's a habit I've gotten into.
    .
  • feddxfeddx Junior Member Posts: 140
    chill wrote: »
    There's no advantage either way. It just "looks funny" to me to use a function as a subroutine. As you put it, it's a habit I've gotten into.
    .

    I bounce between them. But as I'm not mentally stable, this practice should be discouraged.
Sign In or Register to comment.