InoDrive / UserApp / read_var


InoDrive.UserApp.read_var(self, argv=None, **kwargs)

Read Variable(s) value by Name or ID in User Application, polls Variable List.

Arguments:

self (Object): Reference to User Application Instance.
argv (Tuple or List): Argument can be a single Variable Name (String) or a ID (Integer). Can also be a List of Variable Name’s or ID’s.
**kwarg (Dict):

floatPrecision (Integer): (Optional) Keyword argument to round up floating point value to nearest digit.

Returns: Variable (Boolean, Integer, Floating Point) or Dict:

• If argument is a single Variable Name or ID -> Returns the Variable value.
• If argument is a list of Variable Name’s or ID’s -> Returns Dictionary of Variable Name’s paired with their value.

import CkInoDriveAPI

# Instantiate InoDrive Object and Connect by Name
Drive = CkInoDriveAPI.InoDrive(target='Name', autoConnect=True)

# Retrieve Variable by ID
foo = Drive.UserApp.read_var(0)

# Read Single Variable by Name
foo = Drive.UserApp.read_var('foo')

# Read Multiple Variable’s by ID’s
var_list = Drive.UserApp.read_var([0, 1])

# Read Multiple Variable’s by Name’s
var_list = Drive.UserApp.read_var(['foo', 'bar'])
if var_list is not None:
    for var in var_list:
        print(f"Variable {var}'s Value is: {var_list[var]}")

# Assume Variable Float Returns a Value of 13.44456
# Expected Return is 13.44
float = Drive.UserApp.read_var('Float', floatPrecision=2)