09-03-2019 02:03 PM
# set the initial value to 0
emc_results.put("number", "0")
# Get the list of devices, only separated by a coma
devicesListRaw = emc_vars["devices"].encode('ascii', 'ignore')
devicesListRaw = devicesListRaw.replace("[", "")
devicesListRaw = devicesListRaw.replace("]", "")
devicesListRaw = devicesListRaw.replace(" ", "")
emc_results.put("devicesList", devicesListRaw)
# Set the maximum loop value to the number of selected devices
emc_results.put("maxNumber", str(len(devicesListRaw.split(","))))
# Get values from the workflow variables
devicesListRaw = emc_vars["devicesList"].encode('ascii', 'encode')
deviceIP = emc_vars["deviceIP"].encode('ascii', 'ignore')
number = int(emc_vars["number"].encode('ascii', 'ignore'))
# If the device's IP is in the list of all devices (as a string),
# increment number by 1.
if deviceIP in devicesListRaw:
print("Last number is : " + str(number))
print("Max number is : " + str(maxNumber))
number += 1
# Set the new value of number into the variable
emc_results.put("number", str(number))
number < maxNumber and number >= maxNumber
9 devices | 10 devices
Last number is : 8 | Last number is : 1
Max number is : 9 | Max number is : 10