Home AMX User Forum NetLinx Studio
Options

1st Programme Help

If anyone could help, this is my 1st amx programme, most of the main stuff is working, i have made the following module and have a problem with the dvHDswitch section i am want to update 8 variables with the current source, i have declared something wrong but don't know quite what. Any help or pointers or advice gratefully received, i don't fancy another late night.



MODULE_NAME='HD SWITCH'(DEV dvMaster, DEV vdvHDswitch, DEV dvHDswitch)
(***********************************************************)
(***********************************************************)
(* FILE_LAST_MODIFIED_ON: AT: 11:33:16 *)
(***********************************************************)
(* System Type : NetLinx *)
(***********************************************************)
(* REV HISTORY: *)
(***********************************************************)
(*
$History: $
*)
(***********************************************************)
(* DEVICE NUMBER DEFINITIONS GO BELOW *)
(***********************************************************)
DEFINE_DEVICE

(***********************************************************)
(* CONSTANT DEFINITIONS GO BELOW *)
(***********************************************************)
DEFINE_CONSTANT

(***********************************************************)
(* DATA TYPE DEFINITIONS GO BELOW *)
(***********************************************************)
DEFINE_TYPE

(***********************************************************)
(* VARIABLE DEFINITIONS GO BELOW *)
(***********************************************************)
DEFINE_VARIABLE

volatile char Output1 // STORES OUTPUT 1 SOURCE
VOLATILE char Output2 // STORES OUTPUT 2 SOURCE
VOLATILE char Output3 // STORES OUTPUT 3 SOURCE
VOLATILE char Output4 // STORES OUTPUT 4 SOURCE
VOLATILE char Output5 // STORES OUTPUT 5 SOURCE
VOLATILE char Output6 // STORES OUTPUT 6 SOURCE
VOLATILE char Output7 // STORES OUTPUT 7 SOURCE
VOLATILE char Output8 // STORES OUTPUT 8 SOURCE
VOLATILE char Power // STORES POWER STATE


(***********************************************************)
(* LATCHING DEFINITIONS GO BELOW *)
(***********************************************************)
DEFINE_LATCHING

(***********************************************************)
(* MUTUALLY EXCLUSIVE DEFINITIONS GO BELOW *)
(***********************************************************)
DEFINE_MUTUALLY_EXCLUSIVE

(***********************************************************)
(* SUBROUTINE/FUNCTION DEFINITIONS GO BELOW *)
(***********************************************************)
(* EXAMPLE: DEFINE_FUNCTION <RETURN_TYPE> <NAME> (<PARAMETERS>) *)
(* EXAMPLE: DEFINE_CALL '<NAME>' (<PARAMETERS>) *)

(***********************************************************)
(* STARTUP CODE GOES BELOW *)
(***********************************************************)
DEFINE_START

(***********************************************************)
(* THE EVENTS GO BELOW *)
(***********************************************************)
DEFINE_EVENT

DATA_EVENT[dvHDswitch]
{
ONLINE:{
SEND_COMMAND dvHDswitch,"'SET BAUD 9600,N,8,1'"
SEND_STRING dvHDswitch,"'SBASKSTA'"
}

STRING:{
stack_var char input[2]
stack_var char output[1]
SEND_STRING 0,"'RX FROM HD SWITCH: ',DATA.TEXT"
if (find_string(data.text,'SBUD00000',1))
{
REMOVE_STRING(DATA.TEXT,'SBUD00000',1)
input=REMOVE_STRING(DATA.TEXT,'0',1)
SET_LENGTH_STRING(input,LENGTH_STRING(input)-1)
output=DATA.TEXT
Output[output]=input
}
}
}


DATA_EVENT[vdvHDswitch]
{
COMMAND:{
stack_var char input[3]
stack_var char output[1]
SEND_STRING 0,"'RX FROM VDV HD SWITCH:',DATA.TEXT"
if (find_string(data.text,'TO',1))
{
SEND_STRING 0,"'TO COMMAND'"
input=REMOVE_STRING(DATA.TEXT,'TO',1)
SET_LENGTH_STRING(input,LENGTH_STRING(input)-2)
output=DATA.TEXT
SEND_STRING dvHDswitch,"'SBI0',INPUT,'O0',OUTPUT"
}
ELSE IF(FIND_STRING(DATA.TEXT,'POWON',1))
{
SEND_STRING dvHDswitch,"'SBSYSMON'"
}
ELSE IF(FIND_STRING(DATA.TEXT,'POWOFF',1))
{
SEND_STRING dvHDswitch,"'SBSYSMOF'"
}
ELSE IF(FIND_STRING(DATA.TEXT,'STATUS',1))
{
SEND_STRING dvHDswitch,"'SBASKSTA'"
}
}
}

Comments

  • Options
    ericmedleyericmedley Posts: 4,177
    xrmichael wrote: »
    If anyone could help, this is my 1st amx programme, most of the main stuff is working, i have made the following module and have a problem with the dvHDswitch section i am want to update 8 variables with the current source, i have declared something wrong but don't know quite what. Any help or pointers or advice gratefully received, i don't fancy another late night.

    MODULE_NAME='HD SWITCH'(DEV dvMaster, DEV vdvHDswitch, DEV dvHDswitch)
    (***********************************************************)
    (***********************************************************)
    (*  FILE_LAST_MODIFIED_ON:   AT: 11:33:16        *)
    (***********************************************************)
    (* System Type : NetLinx                                   *)
    (***********************************************************)
    (* REV HISTORY:                                            *)
    (***********************************************************)
    (*
        $History: $
    *)    
    (***********************************************************)
    (*          DEVICE NUMBER DEFINITIONS GO BELOW             *)
    (***********************************************************)
    DEFINE_DEVICE
    
    (***********************************************************)
    (*               CONSTANT DEFINITIONS GO BELOW             *)
    (***********************************************************)
    DEFINE_CONSTANT
    
    (***********************************************************)
    (*              DATA TYPE DEFINITIONS GO BELOW             *)
    (***********************************************************)
    DEFINE_TYPE
    
    (***********************************************************)
    (*               VARIABLE DEFINITIONS GO BELOW             *)
    (***********************************************************)
    DEFINE_VARIABLE
    
    volatile char Output1      // STORES OUTPUT 1 SOURCE
    VOLATILE char Output2      // STORES OUTPUT 2 SOURCE
    VOLATILE char Output3      // STORES OUTPUT 3 SOURCE
    VOLATILE char Output4      // STORES OUTPUT 4 SOURCE
    VOLATILE char Output5      // STORES OUTPUT 5 SOURCE
    VOLATILE char Output6      // STORES OUTPUT 6 SOURCE
    VOLATILE char Output7      // STORES OUTPUT 7 SOURCE
    VOLATILE char Output8      // STORES OUTPUT 8 SOURCE
    VOLATILE char Power	   // STORES POWER STAT
    
    (***********************************************************)
    (*               LATCHING DEFINITIONS GO BELOW             *)
    (***********************************************************)
    DEFINE_LATCHING
    
    (***********************************************************)
    (*       MUTUALLY EXCLUSIVE DEFINITIONS GO BELOW           *)
    (***********************************************************)
    DEFINE_MUTUALLY_EXCLUSIVE
    
    (***********************************************************)
    (*        SUBROUTINE/FUNCTION DEFINITIONS GO BELOW         *)
    (***********************************************************)
    (* EXAMPLE: DEFINE_FUNCTION <RETURN_TYPE> <NAME> (<PARAMETERS>) *)
    (* EXAMPLE: DEFINE_CALL '<NAME>' (<PARAMETERS>) *)
    
    (***********************************************************)
    (*                STARTUP CODE GOES BELOW                  *)
    (***********************************************************)
    DEFINE_START
    
    (***********************************************************)
    (*                THE EVENTS GO BELOW                      *)
    (***********************************************************)
    DEFINE_EVENT
    
    DATA_EVENT[dvHDswitch]
    {
        ONLINE:{
    	    SEND_COMMAND dvHDswitch,"'SET BAUD 9600,N,8,1'"
    	    SEND_STRING dvHDswitch,"'SBASKSTA'"
    	    }
        
        STRING:{
    	    stack_var char input[2]
    	    stack_var char output[1]
    	    SEND_STRING 0,"'RX FROM HD SWITCH: ',DATA.TEXT"
    	    if (find_string(data.text,'SBUD00000',1))
    	    {
    	    REMOVE_STRING(DATA.TEXT,'SBUD00000',1)
    	    input=REMOVE_STRING(DATA.TEXT,'0',1)
    	    SET_LENGTH_STRING(input,LENGTH_STRING(input)-1)
    	    output=DATA.TEXT
    	    Output[output]=input
    	    }
    	    }
    }
    
    
    DATA_EVENT[vdvHDswitch]
    {
        COMMAND:{
    	    stack_var char input[3]
    	    stack_var char output[1]
    	    SEND_STRING 0,"'RX FROM VDV HD SWITCH:',DATA.TEXT"
    	    if (find_string(data.text,'TO',1))
    	    {
    	    SEND_STRING 0,"'TO COMMAND'"
    	    input=REMOVE_STRING(DATA.TEXT,'TO',1)
    	    SET_LENGTH_STRING(input,LENGTH_STRING(input)-2)
    	    output=DATA.TEXT
    	    SEND_STRING dvHDswitch,"'SBI0',INPUT,'O0',OUTPUT"
    	    }
    		ELSE IF(FIND_STRING(DATA.TEXT,'POWON',1))
    		{
    		SEND_STRING dvHDswitch,"'SBSYSMON'"
    		}
    		    ELSE IF(FIND_STRING(DATA.TEXT,'POWOFF',1))
    		    {
    		    SEND_STRING dvHDswitch,"'SBSYSMOF'"
    		    }
    			ELSE IF(FIND_STRING(DATA.TEXT,'STATUS',1))
    			{
    			SEND_STRING dvHDswitch,"'SBASKSTA'"
    			} 
    }
    
    }


    I think you're inteneding the var Output to be an array.

    So instead of
    volatile char Output1      // STORES OUTPUT 1 SOURCE
    VOLATILE char Output2      // STORES OUTPUT 2 SOURCE
    VOLATILE char Output3      // STORES OUTPUT 3 SOURCE
    VOLATILE char Output4      // STORES OUTPUT 4 SOURCE
    etc..
    

    it should be
    VOLATILE Output[8] //for a single char string or
    
    VOLATILE INTEGER Output[8]  //for an integer array.
    

    oh, and by the way. you can put a bracket [ and the word 'code' and then a closed ] to paste code into a post. It preserves the indentations and makes it easier to read.

    close off the code section by putting a [/ and then the word 'code' and then ]

    hope that helps
    e
  • Options
    Thanks

    Wow that was fast i will give it ago.
  • Options
    Help

    I still get the following 2 compile warnings, and when i request the status of the device i get a set varible error. The matrix respods with 8 lines like so SBUD00000208.

    Converting a string to a [LONG]
    Converting type [string] to [CHAR]
  • Options
    STRING:{
    stack_var char input[2]
    stack_var char output[1]
    SEND_STRING 0,"'RX FROM HD SWITCH: ',DATA.TEXT"
    if (find_string(data.text,'SBUD00000',1))
    {
    REMOVE_STRING(DATA.TEXT,'SBUD00000',1)
    input=REMOVE_STRING(DATA.TEXT,'0',1)
    SET_LENGTH_STRING(input,LENGTH_STRING(input)-1)
    output=DATA.TEXT
    Output[output]=input
    }
    }
    }
    
    The variable you declare as Output[Output]=input is part of the big culprit. You'll need to change some variable names and use an atoi keyword. For your feedback variables that you declare as Output1..Output8, you'll need to redefine those as an array. Something like this would help:
    VOLATILE CHAR cStoredOutput[8][2] = {'00','00','00','00','00','00','00','00'} //use this if you'll possibly have more than 9 output sources in the future
    or
    VOLATILE CHAR cStoredOutput[8]= "'00000000'"  //If you only need a single digit value for the Output.
    
    Then your feedback declaration of Output[output] would almost work. This would change to:
    cStoredOutput[ATOI(output)]=Input
    
    The parameter in the [] brackets needs to be an integer.

    Like Eric said too, using the [ code] and [ /code] (without the spaces) will help to make your post more readable.


    --John
  • Options
    Help

    Point noted about posting code was my 1st post.
  • Options
    Help

    Right so the "atoi" does the char to integer conversion. Does the array need to be defined as as constant allso ?
  • Options
    You're fine with the array as a variable. If you declare it as a constant then you won't be able to change the values.


    --John
  • Options
    Help

    Just when i try and compile now i get the following error

    RHS for [CSTOREDOUTPUT] is not a constant .
  • Options
    Sorry, you'll need to take out the double quotes if you're using it as a 1-dimensional array.
    CHAR cOutputStored[]='00000000'
    

    --John
  • Options
    Thanks

    Thanks all working now, have i adopted a best practise approach to creating a simple comm module as it seems to miss the odd event would a buffer be a better approach?

    Most of may previous programming has been in JS so not so many restraints declaring things.

    Once again thanks.
  • Options
    ericmedleyericmedley Posts: 4,177
    xrmichael wrote: »
    Thanks all working now, have i adopted a best practise approach to creating a simple comm module as it seems to miss the odd event would a buffer be a better approach?

    Most of may previous programming has been in JS so not so many restraints declaring things.

    Once again thanks.

    It's probably a good idea to create a queue for all your messages. (both incoming and outgoing)

    That would avoid any collisions. I use the FIFO method. It's pretty easy to do. You just append messages to the end of the buffer and watch for length to key the routine to spit them out.
  • Options
    Help

    Ill give it a try, sounds a bit complex.
  • Options
    DHawthorneDHawthorne Posts: 4,584
    xrmichael wrote: »
    Ill give it a try, sounds a bit complex.

    A lot of stuff seems a lot more complex than it really is when you first see it. Once you wrap your head around the concept, it will become second nature. A lot of coding technique is exactly like that: first few times around you will be wondering how you got it to work at all, a few dozen times later, you are picking it apart, improving it, modifying at will, and coming up with new implementations.
Sign In or Register to comment.