sosFloatCreate (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

All

Firmware version:

1.00.00


sosFloatCreate will create a new FLOAT object.

If the object already exists, it will be replaced.

Please note that when using this function, math.inc must be explicitly included by the application.

 

Input:

key : STRING

The key for the object to create. May only contain a-z,A-Z,0-9, "." and "_" (maximum of 250 characters).

 

desc : STRING

The description for the object, to show in the IDE (maximum of 80 characters).

 

value : FLOAT default 0

The initial value for the object. The value is not validated, making it possible to use it to e.g. determine unmodified values.

 

min_val : FLOAT default 0

The minimum allowed value for the object. If both min_val and max_val are 0, there will be no limit. NaN is not a valid value for this parameter.

 

max_val : FLOAT default 0

The maximum allowed value for the object. If both min_val and max_val are 0, there will be no limit. NaN is not a valid value for this parameter.

 

Returns: INT

0

- The object is created.

-1

- Generic error.

-2

- Invalid parameter.

 

 

Declaration:

FUNCTION sosFloatCreate : INT;
VAR_INPUT
  key     : STRING;
  desc    : STRING;
  value   : FLOAT := 0.0;
  min_val : FLOAT := 0.0;
  max_val : FLOAT := 0.0;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
INCLUDE math.inc
 
PROGRAM test;
VAR
  rc   : INT;
  temp : FLOAT;
END_VAR;
BEGIN
  ...
  // Create float object
  rc := sosFloatCreate(key := "config.max_temperature", value:=24.5, desc := "Largest temperature measured");
  DebugFmt(message:="sosFloatCreate=\1", v1:=rc);
  // Update float object
  rc:= sosFloatSet(key:="config.max_temperature", value:=26.7);
  DebugFmt(message:="sosFloatSet=\1", v1:=rc);
 
  // Read float object
  rc:= sosFloatGet(key:="config.max_temperature", value:=temp);
  DebugFmt(message:="sosFloatGet=\1 => " + floatToStr(v:=temp), v1:=rc);
  ...
END;
 
END_PROGRAM;