Home AMX User Forum AMX Technical Discussion
Options

Sending channel arrays to a touch panel

In the docs, it lists
CHAN[ ] – a channel array.
as an allowablet parameter to
ON[DEVICE,CHANNEL]

this works... sometimes

Anyone else ever pulled their hair out over this?
I have to set_length_array before it will update my touchpanel.
Here's a complete demo file. Just make a tp file with buttons 1 through 8.
PROGRAM_NAME='arraytest'
DEFINE_DEVICE
vdv = 33001:1:0
tp = 10001:1:0

DEFINE_CONSTANT
INTEGER BUTTONS[] = {1,2,3,4,5,6,7,8}

DEFINE_VARIABLE
VOLATILE INTEGER hack


DEFINE_EVENT
CHANNEL_EVENT[vdv,1]
{
    ON:{
	ON[tp,buttons] //works
    }
}
CHANNEL_EVENT[vdv,2]
{
    ON:{
	LOCAL_VAR INTEGER i_BtnsToTurnOn[4]
	STACK_VAR INTEGER idx
	
	//turn them all off
	OFF[tp,BUTTONS] //works
	
	//turn 1st 4 on
	FOR(idx=1;idx<=4;idx++){
	    i_BtnsToTurnOn[idx] = idx
	}
	
	IF(hack){
	    SET_LENGTH_ARRAY(i_BtnsToTurnOn,4)
	}
	ON[tp,i_BtnsToTurnOn] //only work after at least 1 set_length_array
    }
}
CHANNEL_EVENT[vdv,3]
{
    ON:{
	STACK_VAR INTEGER i_BtnsToTurnOn[4]
	STACK_VAR INTEGER idx
	
	//turn them all off
	OFF[tp,BUTTONS]
	
	//turn 1st 4 on
	FOR(idx=1;idx<=4;idx++){
	    i_BtnsToTurnOn[idx] = idx
	}
	
	IF(hack){
	    SET_LENGTH_ARRAY(i_BtnsToTurnOn,4)
	}
	ON[tp,i_BtnsToTurnOn] //need set_length_array (stack_var)
    }
}

Comments

  • Options
    a_riot42a_riot42 Posts: 1,624
    I use this all the time, but its not surprising that you need to use set_length_array. Whenever you decide to manually edit arrays on your own, Netlinx doesn't keep track so its up to you to set the length. You could do this using other methods which wouldn't require it though.
    Paul
  • Options
    DHawthorneDHawthorne Posts: 4,584
    a_riot42 wrote: »
    I use this all the time, but its not surprising that you need to use set_length_array. Whenever you decide to manually edit arrays on your own, Netlinx doesn't keep track so its up to you to set the length. You could do this using other methods which wouldn't require it though.
    Paul

    As a rule-of-thumb, if there is a built-in function to manipulate the array (like any of the string functions), the length is set properly. If you manually change any of the elements, you have to set the length yourself. I can't think of any exceptions to this, but it wouldn't surprise me if there were a few odd cases.
  • Options
    a_riot42a_riot42 Posts: 1,624
    DHawthorne wrote: »
    As a rule-of-thumb, if there is a built-in function to manipulate the array (like any of the string functions), the length is set properly. If you manually change any of the elements, you have to set the length yourself. I can't think of any exceptions to this, but it wouldn't surprise me if there were a few odd cases.

    I think the only exception is when using double quotes to concatenate a string. Netlinx must sum the characters in each string and set the length of the new string to that length. I've never actually tested it but I never use set_length_array when using double quotes and I still get the correct result.
    Paul
  • Options
    Joe HebertJoe Hebert Posts: 2,159
    Another way to say it:
    The length will not change if you set/poke individual cells in the array.
    The length will change with any other type of assignment.
  • Options
    travistravis Posts: 180
    But this is just poking individual cells...
  • Options
    Joe HebertJoe Hebert Posts: 2,159
    travis wrote: »
    But this is just poking individual cells...
    Which is why the length will not change…

    Am I missing your point?
Sign In or Register to comment.