1st Programme Help
xrmichael
Posts: 79
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'"
}
}
}
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'"
}
}
}
0
Comments
I think you're inteneding the var Output to be an array.
So instead of
it should be
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
Wow that was fast i will give it ago.
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]
Like Eric said too, using the [ code] and [ /code] (without the spaces) will help to make your post more readable.
--John
Point noted about posting code was my 1st post.
Right so the "atoi" does the char to integer conversion. Does the array need to be defined as as constant allso ?
--John
Just when i try and compile now i get the following error
RHS for [CSTOREDOUTPUT] is not a constant .
--John
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.
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.