owSearch (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

All devices with 1-Wire

Firmware version:

1.00 / 1.00.00


Each 1-wire device has a unique ROM-number like the iButton. This number is used to point out one specific device of many devices on the bus.

Before any devices can be accessed, the ROM-number has to be discovered. By using the 1-Wire search function, all devices on the 1-Wire bus are discovered and the ROM-numbers are stored in a temporary list placed inside the RTCU device. When the device is powered off, the list is erased and a new search has to be performed on power on. The devices are sorted in the order they are discovered on the 1-Wire net. If a device is removed from the bus, all devices after this one will move one position down the list when a new search is carried out. As the search function is generally intended for 1-Wire use, a family number has to be supplied when making the function call. For 1-Wire temperature devices, the family number is 1.

 

owSearch returns the number of family-specified devices found on the 1-Wire bus. This function is essential in order to access the 1-Wire devices on the 1-Wire bus (except the iButton). Call the function at least at device power-on.

 

Please consult the Logic IO 1-Wire basics application note for information on 1-Wire devices.

 

Input:                

family : SINT

The family of 1-Wire devices to search for.

 1 = Temperature sensors (current only family code 16#28 as maxim's DS18B20).

 

Returns: INT

>= 0


Number of devices found within family range.

-1


General error or not supported on target.

 

Declaration:

FUNCTION owSearch : INT;
VAR_INPUT
  family : SINT;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
VAR
  Temp : DINT;
  tmp : DINT;
  str : STRING;
END_VAR;
 
PROGRAM test;
 
  // Search for temperature sensors
  IF owSearch(family:=1) < 1 THEN
    DebugMsg(message:="No temperature sensor!");
  END_IF;
 
BEGIN
  ...
  // Get temperature of first device
  Temp := owTempGet(device:=1);
  str := strConcat(str1:=owTempGetID(Device:=1),str2:=" = ");
  str := strConcat(str1:=str,str2:=dintToStr(v:=(Temp/100)));
  str := strConcat(str1:=str,str2:=".");
  tmp := (Temp MOD 100) / 10;
  IF tmp < 0 THEN tmp := -tmp; END_IF;
  str := strConcat(str1:=str,str2:=dintToStr(v:=tmp));
  DebugFmt(message:=str);
  ...
END;
 
END_PROGRAM;