Runtime created button arrays as parameters
ajish.raju
Posts: 185
I am able to create runtime-created button arrays. But not able to pass them as parameters in module like UI module.
Do I need to do the function for creating the button arrays in the module itself.
Do I need to do the function for creating the button arrays in the module itself.
0
Comments
I have not done this but I would think the button array is "filled in" after the events are created,
so I would think that you would need to recreate the events at run time in the module;
i.e. call rebuild_events(); in the Module DEFINE_START like:
DEFINE_START
{
wait WT_1000_MSEC
{
rebuild_events();
}
}
Netlinx isn't a dynamic system, so trying to do anything at runtime is usually not worth it. You can usually design around this limitation in most cases. I can't think of any reason I would ever need to create button arrays at runtime. Why do you feel the need to do that?
Paul
I use snapi constants for comm modules but for ui modules, is it better to use g4api constants. Since we can use 4000 channel codes per tp port, is there a standard for which device to use which channel codes.
I was not aware of that.
I thought that the module is running in its own address space and therefore would requires an r_e of its own.
I did not test this - just assumed... DOH!!!
I will now have remove a line of code from a few modules...
Thanks again.
At this point in time I have not had any reason to r_e other than on reboot.
// used to create button_event arrays at runtime by specifying a starting channel and array size
//
// example usage:
//
// DEFINE_CONSTANT
// btnVOL_UP = 1 // channel of first VOL_UP button
// btnVOL_UP_MAX = 16 // 16 buttons total
//
// DEFINE_VARIABLE
// volatile integer btVOL_UP[btnVOL_UP_MAX]
// DEFINE_START
// {
// fnMAKE_BUTTON_ARRAY(btVOL_UP,btnVOL_UP)
// rebuild_event()
// }
{
STACK_VAR INTEGER Y
FOR (Y=0;Y<MAX_LENGTH_ARRAY(BUTT);Y++)
BUTT[Y+1]=BASE_BUTT+Y
SET_LENGTH_ARRAY (BUTT,MAX_LENGTH_ARRAY(BUTT))
}
This is the function that i am using to create the button arrays.
SET_LENGTH_ARRAY (BUTT,MAX_LENGTH_ARRAY(BUTT))
This line won't do anything. If Netlinx knew the correct max_length_array, then you wouldn't need to set it. Its like asking "Tell me the length of this array so I can set it to that value".
Paul
If you declare an array with a constant, then that's its effective and maximum length. You don't need to initialize it. iBtns[cnMaxBts] has an effective and max length of cnMaxBtns.
Paul
Nope, its working length is 0 and if you do a length_array on it, it will return 0. If you populate it with values and then do a rebuild_event on it nothing will happen since it has no working length.
If you drop that var array into debug and right click the length and uncheck total length you will see a length of 0, its working length. If you check total length you will see its defined max length.
You can use it with out a set working length if you want as long as you don't run functions on it like length_array or rebuild_event().
Paul
If you initialize (populate with values) a var array anywhere other than define_variable it will not have length unless you use set_length_array somewhere. It will only have the max length that it was defined with. You can still use the array, read from or write to elements of the array but it still doesn't have a working length as returned from the length_array function.
I agree that for most situations defining var arrays used with event handlers should be initialized when defined and quite frankly there's no real need for button arrays at all if channel numbers match index positions, for that just use 0, catch all, since it uses less resources and catches everything.