Example source code resources
Rich Abel
Posts: 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
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
0
Comments
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
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
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)
}
}
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:
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.
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
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.
http://netlinx-modules.cvs.sourceforge.net/viewvc/netlinx-modules/NetLinx-Modules/SyslogMod/
.. 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.
.
.
I bounce between them. But as I'm not mentally stable, this practice should be discouraged.