Пример #1
0
        private ComputeDeviceState QueryDeviceState(ComputeDeviceInfo currentDeviceInfo, int port)
        {
            bool validPort = currentDeviceInfo.PortList.Any(p => p == port);

            if (!validPort)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("[ERROR] QueryDeviceState(devId={0}, port={1}) Port does not exists", currentDeviceInfo.ComputeDeviceId, port);
                Console.ResetColor();
                return(null);
            }

            if (computeDeviceStateMap.ContainsKey(currentDeviceInfo))
            {
                if (computeDeviceStateMap[currentDeviceInfo].ContainsKey(port))
                {
                    return(computeDeviceStateMap[currentDeviceInfo][port]);
                }
                else
                {
                    return(computeDeviceStateMap[currentDeviceInfo][port] = new ComputeDeviceState());
                }
            }

            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("[ERROR] QueryDeviceState(devId={0}, port={1}) Unable to fetch data", currentDeviceInfo.ComputeDeviceId, port);
            Console.ResetColor();
            return(null);
        }
        public string LoadAlgorithm(string algoId, ComputeDeviceInfo computeDeviceInfo, int port)
        {
            if (!algorithmsDescriptionMap.ContainsKey(algoId))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("[ERROR] ICANSEEUtility.LoadAlgorithm(" + algoId + ", ipAddress=" + computeDeviceInfo.IpAddress + ", port=" + port.ToString() + ")\n - Algorithm Id not found");
                Console.ResetColor();

                return(null);
            }

            string apiCallBody = "{\n\"Fbp\":[\"Start\",\"" + algorithmsDescriptionMap[algoId].GetInitCommand(computeDeviceInfo.IpAddress, port.ToString()) + "\",\"\"],\"RunOnce\": true,\"InfiniteLoop\": false,\"LoopLimit\": 1,\"ReturnResult\": true}";

            Console.WriteLine("[DEBUG] ApiCallBody(" + computeDeviceInfo.IpAddress + port.ToString() + "): " + apiCallBody);

            try
            {
                string result = imageClient.MakePostCall(algorithmsDescriptionMap[algoId].GetUri(computeDeviceInfo.IpAddress, port.ToString()), apiCallBody);
                Console.WriteLine("[INFO] ICANSEEUtility.LoadAlgorithm(" + algoId + ", ipAddress=" + computeDeviceInfo.IpAddress + ", port=" + port.ToString() + ")\n" + apiCallBody + "\n\n" + "Result: " + result);
                return(algorithmsDescriptionMap[algoId].AlgorithmTypeId);
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("[ERROR] ICANSEEUtility.LoadAlgorithm(" + algoId + ", ipAddress=" + computeDeviceInfo.IpAddress + ", port=" + port.ToString() + ")\n" + apiCallBody + "\n" + ex.Message);
                Console.ResetColor();

                return(null);
            }
        }
 private bool IsDeviceFree(ComputeDeviceInfo currentDeviceInfo)
 {
     if (!computeDeviceLocked.ContainsKey(currentDeviceInfo))
     {
         return(true);
     }
     return(!computeDeviceLocked[currentDeviceInfo]);
 }
        private void BtnDisplayImage_Click(object sender, EventArgs e)
        {
            ComputeDeviceInfo firstDevice = controller.utility.computeDeviceInfoList.First();
            int port = firstDevice.PortList.First();

            InputMessage message = new InputMessage(ControlFunction.DisplayImageInServerGUI, new List <string> {
                firstDevice.ComputeDeviceId, port.ToString()
            });

            controller.Hub.Publish <InputMessage>(message);
        }
Пример #5
0
        public bool UnloadAlgorithm(string algoId, ComputeDeviceInfo computeDeviceInfo, int port)
        {
            string result = utility.UnloadAlgorithm(algoId, computeDeviceInfo, port);

            if (result != null)
            {
                return(computeDeviceStateMap[computeDeviceInfo][port].ClearAlgorithm(algoId));
            }

            return(false);
        }
Пример #6
0
        public void AddComputeDevice(ComputeDeviceInfo computeDevice)
        {
            if (!DevicePortAssignmentMapping.ContainsKey(computeDevice.ComputeDeviceId))
            {
                DevicePortAssignmentMapping.Add(computeDevice.ComputeDeviceId, new Dictionary <int, AssignmentConfiguration>());

                foreach (var item in computeDevice.PortList)
                {
                    DevicePortAssignmentMapping[computeDevice.ComputeDeviceId].Add(item, null);
                }
            }
        }
        public string UnloadAlgorithm(string algorithmId, ComputeDeviceInfo computeDeviceInfo, int port)
        {
            if (algorithmsDescriptionMap.ContainsKey(algorithmId))
            {
                bool IsDeviceSupported = false;
                foreach (var deviceId in algorithmsDescriptionMap[algorithmId].SupportedDeviceTypeIdList)
                {
                    if (deviceId == computeDeviceInfo.DeviceTypeId)
                    {
                        IsDeviceSupported = true;
                        break;
                    }
                }

                if (!IsDeviceSupported)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("[ERROR] UnloadAlgorithm(" + algorithmId + ", " + computeDeviceInfo.IpAddress + ", ipAddress=" + computeDeviceInfo.IpAddress + ", port=" + port.ToString() + ") " + ": The device doesn't support the algorithm");
                    Console.ResetColor();
                    return(null);
                }


                string unloadCommand = algorithmsDescriptionMap[algorithmId].GetUnloadCommand(computeDeviceInfo.IpAddress, port.ToString());
                string apiCallBody   = "{\n\"Fbp\":[\"Start\",\"\",\"" + unloadCommand + "\"],\"RunOnce\": true,\"InfiniteLoop\": false,\"LoopLimit\": 1,\"ReturnResult\": true}";

                Console.WriteLine("[DEBUG] ApiCallBody(" + computeDeviceInfo.IpAddress + port.ToString() + "): " + apiCallBody);

                try
                {
                    string result = imageClient.MakePostCall(algorithmsDescriptionMap[algorithmId].GetUri(computeDeviceInfo.IpAddress, port.ToString()), apiCallBody);
                    return(result);
                }
                catch (Exception ex)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("[ERROR] ICANSEEUtility.ExecuteAlgorithmScalar(" + ", ipAddress=" + computeDeviceInfo.IpAddress + ", port=" + port.ToString() + ") " + "\n" + apiCallBody + "\n" + ex.Message);
                    Console.ResetColor();
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("[ERROR] UnloadAlgorithm(" + algorithmId + ", " + computeDeviceInfo.IpAddress + ", ipAddress=" + computeDeviceInfo.IpAddress + ", port=" + port.ToString() + ") " + ": We cannot find the algorithmId");
                Console.ResetColor();
            }

            return(null);
        }
        private void BtnRunTFSSD_Click(object sender, EventArgs e)
        {
            ComputeDeviceInfo firstDevice = controller.utility.GetComputeDevicesList().First();
            PresetDescription preset      = new PresetDescription("1000", "Sample", "Algo3", firstDevice.ComputeDeviceId, firstDevice.PortList.First(), true, false, 1, true);
            string            result      = controller.utility.ExecuteAlgorithm(preset, firstDevice.IpAddress);

            if (result != null)
            {
                Console.WriteLine("[INFO] RunAlgo: " + result);
            }
            else
            {
                Console.WriteLine("Failure");
            }
        }
        public string LoadCamera(int cameraConfigId, ComputeDeviceInfo computeDeviceInfo, int port)
        {
            try
            {
                if (cameraConfigurationsMap.ContainsKey(cameraConfigId))
                {
                    CameraConfiguration cameraConfig = cameraConfigurationsMap[cameraConfigId];

                    string apiCallBody = "BlankValue";

                    // identify the type
                    switch (cameraConfig.Type)
                    {
                    case "camera":
                        apiCallBody = "{\n\"Fbp\":[\"Start\",\"globals()['cap'] = cv2.VideoCapture({{index}})\\nglobals()['refreshCameraCode'] = 'globals()[\\\\'ret\\\\'], globals()[\\\\'imageSrc\\\\'] = globals()[\\\\'cap\\\\'].read()'\\nglobals()['ret'], globals()['frame'] = globals()['cap'].read()\\nglobals()['imageSrc'] = globals()['frame']\",\"\"],\"RunOnce\": true,\"InfiniteLoop\": false,\"LoopLimit\": 1,\"ReturnResult\": true}";
                        apiCallBody = apiCallBody.Replace("{{index}}", cameraConfig.Index.ToString());
                        break;

                    case "mjpgStream":
                        apiCallBody = "{\n\"Fbp\":[\"Start\",\"globals()['cap'] = cv2.VideoCapture({{url}})\\nglobals()['refreshCameraCode'] = 'globals()[\\\\'ret\\\\'], globals()[\\\\'imageSrc\\\\'] = globals()[\\\\'cap\\\\'].read()'\\nglobals()['ret'], globals()['frame'] = globals()['cap'].read()\\nglobals()['imageSrc'] = globals()['frame']\",\"\"],\"RunOnce\": true,\"InfiniteLoop\": false,\"LoopLimit\": 1,\"ReturnResult\": true}";
                        apiCallBody = apiCallBody.Replace("{{url}}", "'" + cameraConfig.Url + "'");
                        break;

                    case "image":
                        apiCallBody = "{\n\"Fbp\":[\"Start\",\"globals()['imageSrc'] = cv2.imread('{{imageLocalPath}}')\\nglobals()['refreshCameraCode'] = 'globals()[\\\\'imageSrc\\\\'] = cv2.imread(\\\\'{{imageLocalPath}}\\\\')'\",\"\"],\"RunOnce\": true,\"InfiniteLoop\": false,\"LoopLimit\": 1,\"ReturnResult\": true}";
                        apiCallBody = apiCallBody.Replace("{{imageLocalPath}}", cameraConfig.Url);
                        break;

                    case "imageShot":
                        apiCallBody = "{\n\"Fbp\":[\"Start\",\"globals()['imageSrc'] = getImageFromShotUri({{shotUri}})\\nglobals()['refreshCameraCode'] = 'globals()[\\\\'imageSrc\\\\'] = getImageFromShotUri({{shotUri}})'\",\"\"],\"RunOnce\": true,\"InfiniteLoop\": false,\"LoopLimit\": 1,\"ReturnResult\": true}";
                        apiCallBody = apiCallBody.Replace("{{shotUri}}", "'" + cameraConfig.Url + "'");
                        break;
                    }

                    Console.WriteLine("[DEBUG] ApiCallBody(" + computeDeviceInfo.IpAddress + port.ToString() + "): " + apiCallBody);
                    string result = imageClient.MakePostCall("http://{{host}}:{{port}}/task".Replace("{{host}}", computeDeviceInfo.IpAddress).Replace("{{port}}", port.ToString()), apiCallBody);

                    return(result);
                }
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("[ERROR] ICANSEEUtility.LoadCamera(val=" + cameraConfigId + ", ipAddress=" + computeDeviceInfo.IpAddress + ", port=" + port.ToString() + ") " + ex.Message);
                Console.ResetColor();
            }
            return(null);
        }
Пример #10
0
        private void BtnInitTFSSD_Click(object sender, EventArgs e)
        {
            ComputeDeviceInfo firstDevice = controller.utility.GetComputeDevicesList().First();
            int port = firstDevice.PortList.First();

            string algoType = controller.utility.LoadAlgorithm("Algo3", firstDevice, port);

            if (algoType != null)
            {
                Console.WriteLine("Success with AlgoType-" + algoType);
            }
            else
            {
                Console.WriteLine("LoadAlgorithm problem");
            }
        }
Пример #11
0
        private void BtnRequestImageMessage_Click(object sender, EventArgs e)
        {
            ComputeDeviceInfo firstDevice = controller.utility.computeDeviceInfoList.First();
            int port = firstDevice.PortList.First();

            string result = controller.utility.RequestCurrentImage(firstDevice, port);

            if (result != null)
            {
                Console.WriteLine(result);
            }
            else
            {
                Console.WriteLine("Failure");
            }
        }
Пример #12
0
        private void BtnLoadCameraConfig_Click(object sender, EventArgs e)
        {
            ComputeDeviceInfo firstDevice = controller.utility.computeDeviceInfoList.First();
            int port = firstDevice.PortList.First();

            string result = controller.utility.LoadCamera(1, firstDevice, port);

            if (result != null)
            {
                Console.WriteLine(result);
            }
            else
            {
                Console.WriteLine("Failure");
            }
        }
Пример #13
0
        private void BtnRunGPUAlgo_Click(object sender, EventArgs e)
        {
            ComputeDeviceInfo firstDevice = controller.utility.GetComputeDevicesList().First();
            int port = firstDevice.PortList.First();

            string result = controller.utility.ExecuteAlgorithmScalar("Algo1", firstDevice, port);

            Console.WriteLine("[INFO] RunAlgo: " + result);

            if (result != null)
            {
                Console.WriteLine(result);
            }
            else
            {
                Console.WriteLine("Failure");
            }
        }
        public string ExecuteAlgorithmScalar(string algorithmId, ComputeDeviceInfo computeDeviceInfo, int port)
        {
            string apiCallBody = "{\n\"Fbp\":[\"Start\",\"\",\"" + algorithmsDescriptionMap[algorithmId].GetScalarExecuteCommand(computeDeviceInfo.IpAddress, port.ToString()) + "\"],\"RunOnce\": true,\"InfiniteLoop\": false,\"LoopLimit\": 1,\"ReturnResult\": true}";

            Console.WriteLine("[DEBUG] ApiCallBody(" + computeDeviceInfo.IpAddress + port.ToString() + "): " + apiCallBody);

            try
            {
                string result = imageClient.MakePostCall(algorithmsDescriptionMap[algorithmId].GetUri(computeDeviceInfo.IpAddress, port.ToString()), apiCallBody);
                return(result);
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("[ERROR] ICANSEEUtility.ExecuteAlgorithmScalar(" + ", ipAddress=" + computeDeviceInfo.IpAddress + ", port=" + port.ToString() + ") " + "\n" + apiCallBody + "\n" + ex.Message);
                Console.ResetColor();
            }
            return(null);
        }
        public string UnloadAllCameras(ComputeDeviceInfo computeDeviceInfo, int port)
        {
            try
            {
                string apiCallBody = "{\n\"Fbp\":[\"Start\",\"globals()['cap'] = None\\nglobals()['imageSrc'] = None\",\"\"],\"RunOnce\": true,\"InfiniteLoop\": false,\"LoopLimit\": 1,\"ReturnResult\": true}";

                Console.WriteLine("[DEBUG] ApiCallBody(" + computeDeviceInfo.IpAddress + port.ToString() + "): " + apiCallBody);

                string result = imageClient.MakePostCall("http://{{host}}:{{port}}/task".Replace("{{host}}", computeDeviceInfo.IpAddress).Replace("{{port}}", port.ToString()), apiCallBody);

                return(result);
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("[ERROR] ICANSEEUtility.UnloadCameras(" + computeDeviceInfo.IpAddress + ", ipAddress=" + computeDeviceInfo.IpAddress + ", port=" + port.ToString() + ") " + ex.Message);
                Console.ResetColor();
            }
            return(null);
        }
        public string LoadTargetDeviceLocalImage(string deviceLocalImagePath, ComputeDeviceInfo computeDeviceInfo, int port)
        {
            try
            {
                string apiCallBody = "{\n\"Fbp\":[\"Start\",\"globals()['imageSrc'] = cv2.imread('{{deviceLocalImagePath}}')\",\"\"],\"RunOnce\": true,\"InfiniteLoop\": false,\"LoopLimit\": 1,\"ReturnResult\": true}";

                apiCallBody = apiCallBody.Replace("{{deviceLocalImagePath}}", "\"" + deviceLocalImagePath + "\"");

                string result = imageClient.MakePostCall("http://{{host}}:{{port}}/task".Replace("{{host}}", computeDeviceInfo.IpAddress).Replace("{{port}}", port.ToString()), apiCallBody);

                return(result);
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("[ERROR] ICANSEEUtility.LoadCamera(val=" + deviceLocalImagePath + ", ipAddress=" + computeDeviceInfo.IpAddress + ", port=" + port.ToString() + ") " + ex.Message);
                Console.ResetColor();
            }
            return(null);
        }
        public string RequestCurrentImage(ComputeDeviceInfo computeDeviceInfo, int port)
        {
            try
            {
                string apiCallBody = "{\n\"Fbp\":[\"Start\",\"PostImage('debug.jpg', globals()['imageSrc'], '" + brokerHubHost + "', " + brokerHubPort + ")\",\"\"],\"RunOnce\": true,\"InfiniteLoop\": false,\"LoopLimit\": 1,\"ReturnResult\": true}";

                Console.WriteLine("[DEBUG] ApiCallBody(" + computeDeviceInfo.IpAddress + port.ToString() + "): " + apiCallBody);

                string result = imageClient.MakePostCall("http://{{host}}:{{port}}/task".Replace("{{host}}", computeDeviceInfo.IpAddress).Replace("{{port}}", port.ToString()), apiCallBody);

                return(result);
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("[ERROR] ICANSEEUtility.DisplayImageWindow(" + computeDeviceInfo.IpAddress + ", ipAddress=" + computeDeviceInfo.IpAddress + ", port=" + port.ToString() + ") " + ex.Message);
                Console.ResetColor();
            }
            return(null);
        }
 public void AddComputeDevice(ComputeDeviceInfo computeDevice)
 {
     ComputeDeviceInfoMap[computeDevice.ComputeDeviceId] = computeDevice;
     helper.AddComputeDevice(computeDevice);
 }
Пример #19
0
 private string GetStringInfo(ComputeDeviceInfo paramName)
 {
     return(GetStringInfo <CLDeviceHandle, ComputeDeviceInfo>(Handle, paramName, CL10.GetDeviceInfo));
 }
Пример #20
0
 private NativeType GetInfo <NativeType>(ComputeDeviceInfo paramName) where NativeType : struct
 {
     return(GetInfo <CLDeviceHandle, ComputeDeviceInfo, NativeType>(Handle, paramName, CL10.GetDeviceInfo));
 }
Пример #21
0
 private bool GetBoolInfo(ComputeDeviceInfo paramName)
 {
     return(GetBoolInfo <CLDeviceHandle, ComputeDeviceInfo>(Handle, paramName, CL10.GetDeviceInfo));
 }
Пример #22
0
 public ComputeErrorCode GetDeviceInfo(CLDeviceHandle device, ComputeDeviceInfo param_name, IntPtr param_value_size, IntPtr param_value, out IntPtr param_value_size_ret)
 {
     return StaticGetDeviceInfo(device, param_name, param_value_size, param_value, out param_value_size_ret);
 }
Пример #23
0
 public static unsafe extern ComputeErrorCode GetDeviceInfo(
     IntPtr device,
     ComputeDeviceInfo param_name,
     IntPtr param_value_size,
     /* void* */ IntPtr param_value,
     IntPtr* param_value_size_ret);
Пример #24
0
 public static extern int GetDeviceInfo(IntPtr device, ComputeDeviceInfo param_name, IntPtr param_value_size, IntPtr param_value, out IntPtr param_value_size_ret);
 public void UnloadAlgorithm(string algoId, ComputeDeviceInfo computeDeviceInfo, int port)
 {
     utility.UnloadAlgorithm(algoId, computeDeviceInfo, port);
 }
Пример #26
0
 public static extern ComputeErrorCode GetDeviceInfo(
     CLDeviceHandle device,
     ComputeDeviceInfo param_name,
     IntPtr param_value_size,
     IntPtr param_value,
     out IntPtr param_value_size_ret);
Пример #27
0
 ComputeErrorCode ICL10.GetDeviceInfo(CLDeviceHandle device, ComputeDeviceInfo param_name, IntPtr param_value_size,
                                      IntPtr param_value, out IntPtr param_value_size_ret)
 {
     return(GetDeviceInfo(device, param_name, param_value_size, param_value, out param_value_size_ret));
 }
Пример #28
0
 public bool UnloadCamera(int cameraId, ComputeDeviceInfo computeDeviceInfo, int port)
 {
     utility.UnloadCamera(cameraId, computeDeviceInfo, port);
     return(computeDeviceStateMap[computeDeviceInfo][port].ClearCamera(cameraId));
 }
 public int CheckDeviceFreeCapacity(ComputeDeviceInfo computeDevice)
 {
     return(helper.CheckDeviceFreeCapacity(computeDevice.ComputeDeviceId));
 }
Пример #30
0
 ComputeErrorCode ICL10.GetDeviceInfo(CLDeviceHandle device, ComputeDeviceInfo param_name, IntPtr param_value_size,
                                      IntPtr param_value, out IntPtr param_value_size_ret)
 {
     return GetDeviceInfo(device, param_name, param_value_size, param_value, out param_value_size_ret);
 }
 public void UnloadDevice(ComputeDeviceInfo computeDevice, List <int> portList = null)
 {
     helper.UnloadDevice(computeDevice.ComputeDeviceId, portList);
 }
Пример #32
0
 private byte[] GetByteArrayInfo(ComputeDeviceInfo paramName)
 {
     return(GetArrayInfo <CLDeviceHandle, ComputeDeviceInfo, byte>(Handle, paramName, CL10.GetDeviceInfo));
 }
Пример #33
0
 public extern static ComputeErrorCode GetDeviceInfo(
     CLDeviceHandle device,
     ComputeDeviceInfo param_name,
     IntPtr param_value_size,
     IntPtr param_value,
     out IntPtr param_value_size_ret);
Пример #34
0
        // Private ExecutePresetHelper
        private string ExecutePresetHelper(string presetId, CameraConfiguration cameraConfiguration, string postScript)
        {
            int  RunCompatibility      = 0;
            bool targetCameraOpen      = false;
            bool targetAlgorithmActive = false;

            PresetDescription presetConfiguration = utility.QueryPresetById(presetId, brokerHubHost, brokerHubPort);

            if (presetConfiguration == null)
            {
                throw new Exception("Preset not found: " + presetId);
            }

            ComputeDeviceInfo computeDevice = utility.QueryComputeDeviceById(presetConfiguration.ComputeDeviceId);
            int port = presetConfiguration.Port;

            ComputeDeviceState currentState = QueryDeviceState(computeDevice, port);

            logger.LogComputeDeviceStateMap(computeDeviceStateMap, string.Format("QueryDeviceState({0}, {1}) = {2}", computeDevice.ComputeDeviceId, port.ToString(), logger._GetShortFormattedComputeDeviceState(currentState)));

            if (currentState == null)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("[ERROR] ExecutePreset(presetId={0}, cameraId={1}) Failure in current state", presetId, cameraConfiguration.Id);
                Console.ResetColor();
                return(null);
            }

            // Any logic for deciding on run
            // Update statusMap with conditions
            if (!(currentState.IsAnyAlgorithmsActive() || currentState.IsAnyCameraActive() || currentState.IsAnyPresetActive()))
            {
                RunCompatibility = 1;
            }
            // If same algorithm, camera is there but preset is over, then run
            else if (currentState.IsAlgorithmActive(presetConfiguration.AlgorithmId) && currentState.IsCameraActive(cameraConfiguration.Id) && !(currentState.IsPresetActive(presetId)))
            {
                RunCompatibility = 2;
            }
            else
            {
                RunCompatibility = 5;

                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("[FIX NEEDED] ExecutePreset(presetId={0}, cameraId={1}) Backdoor activated for allowing execution", presetId, cameraConfiguration.Id);
                Console.ResetColor();
            }

            if (currentState.IsCameraActive(cameraConfiguration.Id))
            {
                targetCameraOpen = true;
            }
            if (currentState.IsAlgorithmActive(presetConfiguration.AlgorithmId))
            {
                targetAlgorithmActive = true;
            }


            // If run compatibility satisfies, run the algorithm in specific compute device
            if (RunCompatibility > 0)
            {
                string result = "";

                // If camera already not loaded, call LoadCamera
                if (!targetCameraOpen)
                {
                    result = utility.LoadCamera(cameraConfiguration.Id, computeDevice, port);
                    if (result == null)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("[ERROR] ExecutePreset(presetId={0}, cameraId={1}) LoadCamera() Failed", presetId, cameraConfiguration.Id);
                        Console.ResetColor();
                        return(null);
                    }
                    else
                    {
                        computeDeviceStateMap[computeDevice][port].SetCameraActive(cameraConfiguration);
                        logger.LogComputeDeviceStateMap(computeDeviceStateMap, string.Format("SetCameraActive={0}", cameraConfiguration.Id + "," + cameraConfiguration.Label));
                    }
                }


                // If preset request to run ScalarExecuteCommand attribute, call the InitCommandFirst
                if (!targetAlgorithmActive)
                {
                    result = utility.ExecuteAlgorithm(presetConfiguration, computeDevice.IpAddress, "InitCommand");

                    if (result == null)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("[ERROR] ExecutePreset(presetId={0}, cameraId={1}) InitAlgo Failed", presetId, cameraConfiguration.Id);
                        Console.ResetColor();
                        return(null);
                    }
                }

                computeDeviceStateMap[computeDevice][port].SetPresetActive(presetConfiguration, utility.GetAlgorithmsList());
                presetCameraMap[presetId] = cameraConfiguration;
                logger.LogComputeDeviceStateMap(computeDeviceStateMap, "SetPresetActive=" + presetConfiguration.Id + "," + presetConfiguration.Name);

                // If preset is one time run, then clear preset from the statusMap
                if (presetConfiguration.ReturnResult && !presetConfiguration.InfiniteLoop && (presetConfiguration.RunOnce || presetConfiguration.LoopLimit == 1))
                {
                    computeDeviceStateMap[computeDevice][port].ClearPreset(presetConfiguration.Id);
                    logger.LogComputeDeviceStateMap(computeDeviceStateMap, "One Run ClearPreset=" + presetConfiguration.Id + "," + presetConfiguration.Name);
                }


                if (postScript == null)
                {
                    result = utility.ExecuteAlgorithm(presetConfiguration, computeDevice.IpAddress);
                }
                else
                {
                    result = utility.ExecuteAlgorithm(presetConfiguration, computeDevice.IpAddress, resultStatementToOverride: postScript);
                }


                if (result == null)
                {
                    computeDeviceStateMap[computeDevice][port].ClearPreset(presetConfiguration.Id);
                    logger.LogComputeDeviceStateMap(computeDeviceStateMap, "Preset Failure ClearPreset=" + presetConfiguration.Id + "," + presetConfiguration.Name);


                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("[ERROR] ExecutePreset(presetId={0}, cameraId={1}) Preset Execution Failed", presetId, cameraConfiguration.Id);
                    Console.ResetColor();

                    return(null);
                }

                return(result);
            }

            return(null);
        }