diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index fd947082..63dbfcff 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -2426,7 +2426,7 @@ namespace Step.NC // Cycle through elements, use the max number of elements between layer components in order to be optimized for (int i = 0; i < GetMaxCountBetweenLayerComponents(layer); i++) { - if (layer.Buttons.ElementAt(i) != null) + if (layer.Buttons.ElementAtOrDefault(i) != null) { // Read enabled from PLC cmsError = numericalControl.PLC_RScadaValue(layer.Buttons[i].Status.MemEnabledIndex, SCADA_MEM_TYPE.BOOL, ref val); @@ -2440,7 +2440,7 @@ namespace Step.NC }); } - if (layer.Images.ElementAt(i) != null) + if (layer.Images.ElementAtOrDefault(i) != null) { // Read isVisible from PLC cmsError = numericalControl.PLC_RScadaValue(layer.Images[i].Status.MemVisibleIndex, SCADA_MEM_TYPE.BOOL, ref val); @@ -2454,7 +2454,7 @@ namespace Step.NC }); } - if (layer.ProgressBars.ElementAt(i) != null) + if (layer.ProgressBars.ElementAtOrDefault(i) != null) { // Read value from PLC cmsError = numericalControl.PLC_RScadaValue(layer.ProgressBars[i].MemValueIndex, SCADA_MEM_TYPE.BYTE, ref val); @@ -2468,7 +2468,7 @@ namespace Step.NC }); } - if (layer.Inputs.ElementAt(i) != null && layer.Inputs[i].Status.Action == "read") + if (layer.Inputs.ElementAtOrDefault(i) != null && layer.Inputs[i].Status.Action == "read") { // Read isVisible from PLC cmsError = numericalControl.PLC_RScadaValue(layer.Inputs[i].Status.MemEnabledIndex, SCADA_MEM_TYPE.BOOL, ref val);