How do I know the source input network variable when using an unqualified nv_update_occurs() event? (KB171)

Question Detail
I am using the when (nv_update_occurs()) event and omitting the particular input network variable parameter for that function. When the event becomes true, how can I tell what input network variable caused this to become true? What about if I use an array of input network variables?
Use nv_table_index() built-in function and nv_in_index built-in variable. nv_in_index is set when the update occurs. If it is compared to the value returned by the nv_table_index(nvi_name) function call (where nvi_name is the name of one of the input network variables) it will evaluate to true or false. See the example code below.
when (nv_update_occurs) { .. .. if (nv_in_index == (nv_table_index(nviMyName))) { // Do something } .. .. } The above works for all input network variables, even for those declared as arrays. If you wish to use the when (nv_update_occurs(nv_array)) event for an entire array of input network variables then you can also use the nv_array_index built-in variable which contains the index (within the array) of the network variable that caused the update. See the example code below.
network input SNVT_switch nviArray[3]; when (nv_update_occurs(nviArray)) { .. .. switch (nv_array_index) // nv_array_index can only be 0,1 or 2 { case 0: ... break; case 1: ... break; case 2: ... break; } .. .. }
Related Products
  • LonBuilder 3.01
  • Neuron C
  • NodeBuilder 1.5
  • NodeBuilder 3.0
  • NodeBuilder 3.1
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


Powered by Zendesk