3 arrayindex() instruction – Campbell Scientific Wireless Sensor Network (CWB100, CWS220, and CWS900) User Manual
Page 41

Wireless Sensor Network
4.3 ArrayIndex() Instruction
The ArrayIndex function is used to return the index of a named element in an 
array which would otherwise be unknown. The value can then be further 
processed in the program because of its known position in the array. If the 
named element is not found, the function returns 0 (this will result in a 
Variable Out of Bounds error). 
In a wireless sensor network where auto-discovery is being used, the sensor 
measurements are returned in the destination array in the order in which the 
sensors are discovered by the base. It is not known until the sensors are 
discovered where in the array each sensor's measurement values will be stored. 
The names of the values returned by the sensors are known, however. Thus, 
the ArrayIndex function can be used to return the correct index value so that 
further processing such as output processing or unit conversion can be 
performed. 
The instruction has the following format:
ArrayIndex (Name)
Name: A string that contains the name of the value for which an index is 
desired. All CWS sensors have a default sensor name, and a fieldname for 
each returned value. For instance, a CWS900 with a sensor name of 
CWS900_3AF has a 109 probe attached and returns four default values: Ts 
(109 temperature), Ti (internal temperature), BV (battery voltage), and SS 
(signal strength). Thus, the default name for the sensor's temperature 
measurement might be CWS900_3AF_Ts. This would be entered as a string in 
the ArrayIndex function: 
Const NumValues = 12 
Public CWSArray(NumValues) 
Public Tair_F 
 
DataTable (WSN5min,True,1000) 
 DataInterval (0,1,Min,0) 
 Sample (1,CWSArray(ArrayIndex("CWS900_TS")),FP2) 
 FieldNames (CWS900_Temp) 
 Sample (1,CWSArray(ArrayIndex("CWS655_VWC")),FP2) 
 FieldNames (CWS655_VWC) 
EndTable 
 
BeginProg 
 Scan (60,Sec,0,0) 
 CWB100 (3,CWSArray()) 
 Tair_F = CWSArray(ArrayIndex("CWS900_TS")) * 1.8 + 32 
 CallTable (WSN5min) 
 NextScan 
EndProg 
 
In this example wireless sensor data is written to a destination array called 
CWSArray. Because the default measurement name is known, it is entered in 
quote marks in the Name field of the ArrayIndex instruction. The datalogger 
can then search for that name in the destination array and reference its position 
33
