owTempGet (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

All devices with 1-Wire

Firmware version:

1.00 / 1.00.00


owTempGet returns the temperature of a specific 1-Wire temperature sensor. After the owSearch function has been carried out, the temperature of each device on the bus can be read. Place the number (between 1 and the number returned by the owSearch function) specifying which temperature sensor is to be read.

 

The function reads the temperature of the device and returns the temperature in 0.01°C multiplied with 100 - this means that 22.50 degrees will be returned as 2250 and -17.00 degrees will be returned as –1700.

 

The temperature sensors retrieve its power directly from the 1-Wire bus. This is called parasitic power and no external power is needed for remote temperature sensing. A temperature conversion takes approximately 0.8 -> 1.0 seconds in this mode. This is due to the power needed for a temperature conversion when operating in parasitic power mode.

 

 

Input:                

Device : SINT

 

Returns: DINT

The current temperature - coded as Degrees * 100 + Decimal degrees. Example: a temperature of 22.76 Degrees is returned as 2276.

-9999 - General error.

 

Declaration:

FUNCTION owTempGet : DINT;
VAR_INPUT
  device : 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
  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;