Improved siemens scada performance

This commit is contained in:
Lucio Maranta
2020-02-25 15:12:30 +01:00
parent e1d6bd1f91
commit c6773bb942
2 changed files with 222 additions and 6 deletions
Binary file not shown.
+222 -6
View File
@@ -985,13 +985,14 @@ namespace Step.NC
List<int> alreadyReadScada = new List<int>();
foreach (var schema in schemasToRead)
{
{
DTOScadaModel scadaValue = new DTOScadaModel();
// Avoid duplicated reads
if (!alreadyReadScada.Contains(schema.Id))
{
// Read one schema
cmsError = ReadScadaData(schema, out DTOScadaModel scadaValue);
if (cmsError.IsError())
{
// Read one schema
cmsError = ReadScadaData(schema, out scadaValue);
if (cmsError.IsError())
return cmsError;
// Add value to return list
@@ -1004,7 +1005,27 @@ namespace Step.NC
return cmsError;
}
public CmsError ReadScadaData(ScadaSchemaModel scadaSchema, out DTOScadaModel scadaValue)
public CmsError ReadScadaData(ScadaSchemaModel schema, out DTOScadaModel scadaValue)
{
if (NcConfig.NcVendor != NC_VENDOR.SIEMENS)
{
// Read OSAI FANUC schema
CmsError cmsError = ReadNcScada(schema, out scadaValue);
if (cmsError.IsError())
return cmsError;
}
else
{
// Read SIEMENS schema
CmsError cmsError = ReadSiemensScadaSiemens(schema, out scadaValue);
if (cmsError.IsError())
return cmsError;
}
return NO_ERROR;
}
public CmsError ReadNcScada(ScadaSchemaModel scadaSchema, out DTOScadaModel scadaValue)
{
//ReadScadaDataSiemens(scadaSchema, out scadaValue);
@@ -1155,6 +1176,201 @@ namespace Step.NC
return cmsError;
}
public CmsError ReadSiemensScadaSiemens(ScadaSchemaModel scadaSchema, out DTOScadaModel scadaValue)
{
List<ScadaObjectModel> inputData = new List<ScadaObjectModel>();
List<ScadaObjectModel> booleanValue = new List<ScadaObjectModel>();
CmsError cmsError = NO_ERROR;
scadaValue = new DTOScadaModel()
{
Id = scadaSchema.Id,
Name = scadaSchema.Name,
IsInProductionPage = scadaSchema.IsInProductionPage,
Buttons = new List<DTOScadaButtonModel>()
};
// Cycle inside layers
foreach (var layer in scadaSchema.Layers)
{
object val = null;
// 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.Labels.ElementAtOrDefault(i) != null)
{
if (layer.Labels[i].MemEnabledIndex != null)
{
var label = layer.Labels[i];
// Add labelVisible to the list of bolean values to be readed
booleanValue.Add(new ScadaObjectModel()
{
Id = label.Id,
Address = label.MemEnabledIndex,
MemType = SCADA_MEM_TYPE.BOOL,
Round = 0,
Action = SCADA_ACTION.READ,
ObjectType = (int)SCADA_ELEMENT_TYPE.LABEL
});
}
else
{
// if memory index is not declared, automatically the label is visible
scadaValue.Labels.Add(new DTOScadaLabelModel()
{
Id = layer.Labels[i].Id,
IsVisible = true
});
}
}
if (layer.Buttons.ElementAtOrDefault(i) != null)
{
var button = layer.Buttons[i];
// Add buttonEnabled to the list of bolean values to be readed
booleanValue.Add(new ScadaObjectModel()
{
Id = button.Id,
Address = button.Status.MemEnabledIndex,
MemType = SCADA_MEM_TYPE.BOOL,
Round = 0,
Action = SCADA_ACTION.READ,
ObjectType = (int)SCADA_ELEMENT_TYPE.BUTTON
});
}
if (layer.Images.ElementAtOrDefault(i) != null)
{
var negate = layer.Images[i].Status.Negate;
var image = layer.Images[i];
// Add imageVisible to the list of bolean values to be readed
booleanValue.Add(new ScadaObjectModel()
{
Id = image.Id,
Address = image.Status.MemVisibleIndex,
MemType = SCADA_MEM_TYPE.BOOL,
Round = 0,
Action = SCADA_ACTION.READ,
ObjectType = negate ? (int)SCADA_ELEMENT_TYPE.NEGATE_IMAGE : (int)SCADA_ELEMENT_TYPE.IMAGE
});
}
if (layer.ProgressBars.ElementAtOrDefault(i) != null)
{
// Read value from PLC
cmsError = numericalControl.PLC_RScadaValue(layer.ProgressBars[i].MemValueIndex, SCADA_MEM_TYPE.BYTE, ref val);
if (cmsError.IsError())
return cmsError;
// Populate & add new object into scada model
scadaValue.ProgressBars.Add(new DTOScadaProgressBarModel()
{
Id = layer.ProgressBars[i].Id,
Value = Convert.ToByte(val)
});
}
if (layer.Inputs.ElementAtOrDefault(i) != null)
{
var input = layer.Inputs[i];
SCADA_MEM_TYPE type = SupportFunctions.GetMemTypeFromString(input.Status.Type);
// InputData list is made up of the values of inputs and the next element of each value is the isVisible field of the same input
// Add Value information
inputData.Add(new ScadaObjectModel()
{
Id = input.Id,
Address = input.Status.MemValueIndex,
MemType = type,
Round = input.Status.Round,
Action = input.Status.Action,
});
// Add is visible to the item to be readed
inputData.Add(new ScadaObjectModel()
{
Id = input.Id,
Address = input.Status.MemEnabledIndex,
MemType = SCADA_MEM_TYPE.BOOL,
Round = input.Status.Round,
Action = input.Status.Action,
});
}
}
}
//Stopwatch st = new Stopwatch();
//st.Start();
// Read input data ( value, isEnabled, value2, isEnabled2 ...)
cmsError = numericalControl.PLC_RScadaSiemens(ref inputData);
if (cmsError.IsError())
return cmsError;
// Read bolean values (isVisible, isEnabled, isEnabled ...)
cmsError = numericalControl.PLC_RScadaSiemens(ref booleanValue);
if (cmsError.IsError())
return cmsError;
for (int i = 0; i < booleanValue.Count() - 1; i++)
{
var enabled = booleanValue[i];
switch (enabled.ObjectType)
{
case (int)SCADA_ELEMENT_TYPE.BUTTON:
{
// Populate & add new object into scada model
scadaValue.Buttons.Add(new DTOScadaButtonModel()
{
Id = enabled.Id,
IsEnabled = Convert.ToBoolean(enabled.Value)
});
} break;
case (int)SCADA_ELEMENT_TYPE.IMAGE:
case (int)SCADA_ELEMENT_TYPE.NEGATE_IMAGE:
{
// Populate & add new object into scada model
scadaValue.Images.Add(new DTOScadaImageModel()
{
Id = enabled.Id,
IsVisible = enabled.ObjectType == (int)SCADA_ELEMENT_TYPE.NEGATE_IMAGE? !Convert.ToBoolean(enabled.Value) : Convert.ToBoolean(enabled.Value)
});
} break;
case (int)SCADA_ELEMENT_TYPE.LABEL:
{
// Populate & add new object into scada model
scadaValue.Labels.Add(new DTOScadaLabelModel()
{
Id = enabled.Id,
IsVisible = Convert.ToBoolean(enabled.Value)
});
} break;
}
}
for (int i = 0; i < inputData.Count() - 1; i += 2)
{
var obj = inputData[i];
var enabled = inputData[i + 1];
// Populate & add new object into scada model
scadaValue.Inputs.Add(new DTOScadaInputModel()
{
Id = obj.Id,
Value = new DTOScadaValueModel()
{
IsEnabled = obj.Action.ToLower() == SCADA_ACTION.READ ? true : Convert.ToBoolean(enabled.Value),
Value = obj.Value
}
});
}
//st.Stop();
//Console.WriteLine(st.ElapsedMilliseconds);
return cmsError;
}
#endregion Read Data
#region Write data