Home AMX User Forum AMXForums Archive Threads AMX Applications and Solutions

AMX programming help (calls to .axs file)

Definite newbie to amx programming.

I am trying to gain the format of calling a subroutine that exists in an .axs file from an external source/application. Currently I have an external .net program that can SEND_STRING commands and turn lights on and off and such. It uses the general format of SEND_STRING (DEVICE, STRING COMMAND).

But how do I call a subroutine? I assume I SEND_STRING, but I am not calling a specific device, I am calling the axs file. I hope I have given enough details, but probably not. Thank you very much for ANY input.

Here is a representation of the subroutine below:

'ALL OFF'
{
LIGHT_STRING ="LITES[2].ROOM,'.',PRESET[8],'.ACTI'"
CHECKSUM = (3 + LENGTH_STRING(LIGHT_STRING))
LIGHT_STRING = "$EE,CHECKSUM,$00,$00,$40,LIGHT_STRING,$00,$00 "
SEND_STRING LIGHTS, "LIGHT_STRING"
LIGHT_STRING ="LITES[3].ROOM,'.',PRESET[8],'.ACTI'"
CHECKSUM = (3 + LENGTH_STRING(LIGHT_STRING))
LIGHT_STRING = "$EE,CHECKSUM,$00,$00,$40,LIGHT_STRING,$00,$00 "
SEND_STRING LIGHTS, "LIGHT_STRING"
LIGHT_STRING ="LITES[4].ROOM,'.',PRESET[8],'.ACTI'"
CHECKSUM = (3 + LENGTH_STRING(LIGHT_STRING))
LIGHT_STRING = "$EE,CHECKSUM,$00,$00,$40,LIGHT_STRING,$00,$00 "
SEND_STRING LIGHTS, "LIGHT_STRING"
}

Comments

  • DHawthorneDHawthorne Posts: 4,584
    There is no direct way to call a function or "call" that resides inside a module. I am assuming your axs file is a module defined in the main program. If not, you have to convert it to one. Then create a virtual device, and pass it to that module as an argument. Within your module, you need to put a DATA_EVENT that acts on the COMMAND handler for that virtual device. Parse the DATA.TEXT variable for that event to act on SEND_COMMANDs from your main program.
  • Some thoughts for you, largely covering good programming practice:

    (1) You repeat some fairly dense code three times in that routine. It would be best to use a separate subroutine to build the "Lights Off" string and another (which would be called by other code also) to add the checksum and send it.

    (2) The checksum isn't a checksum, it appears to be a data length indicator.

    (3) You are sending three strings one after another without any sort of queueing or waiting for an acknowledgement from the device. It may work on this occasion but it's usually a dodgy way to do it.

    (4) Any routine that does an "All" function ought not enumerate what "All" means - it ought to run through a table from beginning to end. That way if the number of lights changes later, this code isn't broken.

    I note however that "All" on this occasion does not include LITES[1]...

    (5) I am beginning to wonder if this is Axcent code rather than NetLinx code, can you please advise?

    (6) It would be best to make the lights control code into a separate module. By that I mean the subroutines that build and send the commands, not the code that decides what needs switching on and off, which belongs in your mainline.

    However the quick-and-dirty approach would be to put the code in your mainline or into an .axi (include) file and include that file in your "mainline".

    This makes your subroutine immediately available to be called from your mainline.

    (7) And finally, your reference to a .net program has me totally puzzled.
Sign In or Register to comment.