diff --git a/Libs/CMS_CORE_Library.dll b/Libs/CMS_CORE_Library.dll index 41286cb7..90f616fc 100644 Binary files a/Libs/CMS_CORE_Library.dll and b/Libs/CMS_CORE_Library.dll differ diff --git a/Step.Config/ServerConfig.cs b/Step.Config/ServerConfig.cs index 6154fe7e..cd084a08 100644 --- a/Step.Config/ServerConfig.cs +++ b/Step.Config/ServerConfig.cs @@ -1,6 +1,7 @@ using Step.Model.ConfigModels; using Step.Model.DatabaseModels; using Step.Model.DTOModels; +using Step.Model.DTOModels.Scada; using System.Collections.Generic; namespace Step.Config @@ -30,6 +31,10 @@ namespace Step.Config public static AreasConfigModel ScadaConfig; public static AreasConfigModel JobEditorConfig; + + public static List ProductionScada = new List(); + public static List Scadas = new List(); + public static List MacrosConfig; } } \ No newline at end of file diff --git a/Step.Config/ServerConfigController.cs b/Step.Config/ServerConfigController.cs index 386addf4..62553571 100644 --- a/Step.Config/ServerConfigController.cs +++ b/Step.Config/ServerConfigController.cs @@ -173,67 +173,40 @@ namespace Step.Config } } - #region Read config from file from configuration - private static void ReadScadaFile() { - List a = new List(); - DirectoryInfo d = new DirectoryInfo(SCADA_DIRECTORY); FileInfo[] files = d.GetFiles("*.xml"); + + int i = 1; + // Cycle inside xml files foreach (var file in files) { - XDocument scadaFile = XDocument.Load(SCADA_DIRECTORY + file.Name); + StreamReader sr = new StreamReader(SCADA_DIRECTORY + file.Name); + XmlSerializer xmlSerializer = new XmlSerializer(typeof(ScadaSchemaModel)); + ScadaSchemaModel schema = xmlSerializer.Deserialize(sr) as ScadaSchemaModel; + // Setup incremental ids + schema.Layers = schema.Layers.Select(x => new ScadaSchemaLayerModel() + { + Id = i++, + Buttons = x.Buttons.Select(y => { y.Id = i++; return y; }).ToArray(), + Images = x.Images.Select(y => { y.Id = i++; return y; }).ToArray(), + ProgressBars = x.ProgressBars.Select(y => { y.Id = i++; return y; }).ToArray(), + Inputs = x.Inputs.Select(y => { y.Id = i++; return y; }).ToArray() + }) + .ToArray(); - StreamReader sr = new StreamReader(SCADA_DIRECTORY + file.Name); - XmlSerializer xs = new XmlSerializer(typeof(ScadaSchemaModel)); - ScadaSchemaModel f = xs.Deserialize(sr) as ScadaSchemaModel; - - //ScadaSchemaModel schema = scadaFile - // .Elements() - // .Select(root => new ScadaSchemaModel() - // { - // Name = root.Element("name").Value, - // BackgroundImage = "fare il base 64 dell'immagine", - // IsInProductionPage = Convert.ToBoolean(root.Element("isInProductionPage").Value), - // Layers = root - // .Element("layers")? - // .Elements() - // .Select(layer => new ScadaSchemaLayerModel() - // { - // Id = Convert.ToInt32(layer.Element("id").Value), - // Buttons = layer.Element("buttons").Elements().Select(button => new ScadaSchemaButtonModel() - // { - // Id = Convert.ToInt32(button.Element("id").Value), - // Position = new ScadaSchemaPositionModel() - // { - // X = Convert.ToInt32(button.Element("position").Element("x").Value), - // Y = Convert.ToInt32(button.Element("position").Element("y").Value) - // }, - // Size = new ScadaSchemaSizeModel() - // { - // X = Convert.ToInt32(button.Element("position").Element("x").Value), - // Y = Convert.ToInt32(button.Element("position").Element("y").Value) - // }, - // Status = new ScadaSchemaStatusModel() - // { - // MemValueIndex = button.Element("status").Element("memClickIndex").Value, - // MemVisibleIndex = button.Element("status").Element("memEnabledIndex").Value - // }, - // Label = button.Elements("label").Select(label => new ScadaSchemaLabelDataModel() - // { - // BackgroundColod = label.Element("backgroundColor").Value, - // TextAlign = label.Element("textAlign").Value, - // TextColor = label.Element("textColor").Value, - // TextContent = label.Element("textContent").Value, - // TextSize = Convert.ToInt32(label.Element("textSize").Value) - // }).FirstOrDefault() - // }).ToList() - // }).ToList() - // }).First(); + if (schema.IsInProductionPage == true) + ProductionScada.Add(schema); + else + Scadas.Add(schema); } } + + #region Read config from file from configuration + + public static void ReadServerConfig() { // Get server file handler diff --git a/Step.Model/DTOModels/Scada/DTOScadaModel.cs b/Step.Model/DTOModels/Scada/DTOScadaModel.cs index acca91df..7fed2795 100644 --- a/Step.Model/DTOModels/Scada/DTOScadaModel.cs +++ b/Step.Model/DTOModels/Scada/DTOScadaModel.cs @@ -6,7 +6,19 @@ namespace Step.Model.DTOModels.Scada { public string Name { get; set; } public bool IsInProductionPage { get; set; } - public List Layers { get; set; } + public List Buttons { get; set; } + public List Images { get; set; } + public List ProgressBars { get; set; } + public List Inputs { get; set; } + + public DTOScadaModel() + { + Name = ""; + Buttons = new List(); + Images = new List(); + ProgressBars = new List(); + Inputs = new List(); + } } @@ -17,24 +29,32 @@ namespace Step.Model.DTOModels.Scada public List Images { get; set; } public List ProgressBars { get; set; } public List Inputs { get; set; } + + public DTOScadaLayerModel() + { + Buttons = new List(); + Images = new List(); + ProgressBars = new List(); + Inputs = new List(); + } } public class DTOScadaButtonModel { public int Id { get; set; } - public DTOScadaValueModel Value { get; set; } + public bool Enabled { get; set; } } public class DTOScadaImageModel { public int Id { get; set; } - public DTOScadaValueModel Value { get; set; } + public bool IsVisible { get; set; } } public class DTOScadaProgressBarModel { public int Id { get; set; } - public DTOScadaValueModel Value { get; set; } + public byte Value { get; set; } } public class DTOScadaInputModel @@ -45,9 +65,6 @@ namespace Step.Model.DTOModels.Scada public class DTOScadaValueModel { - public string MemVisibleIndex { get; set; } - public string MemValueIndex { get; set; } - public bool IsVisible { get; set; } public object Value { get; set; } } diff --git a/Step.Model/DTOModels/Scada/ScadaSchemaModel.cs b/Step.Model/DTOModels/Scada/ScadaSchemaModel.cs index 2963fb40..55ce39b8 100644 --- a/Step.Model/DTOModels/Scada/ScadaSchemaModel.cs +++ b/Step.Model/DTOModels/Scada/ScadaSchemaModel.cs @@ -19,7 +19,7 @@ namespace Step.Model.DTOModels.Scada public class ScadaSchemaLayerModel { - [XmlElement("id")] + //[XmlElement("id")] public int Id { get; set; } [XmlArray("buttons")] @@ -42,7 +42,7 @@ namespace Step.Model.DTOModels.Scada public class ScadaSchemaButtonModel { - [XmlElement("id")] + //[XmlElement("id")] public int Id { get; set; } [XmlElement("label")] @@ -55,12 +55,12 @@ namespace Step.Model.DTOModels.Scada public ScadaSchemaSizeModel Size { get; set; } [XmlElement("status")] - public ScadaSchemaStatusModel Status { get; set; } + public ScadaSchemaClickModel Status { get; set; } } public class ScadaSchemaImageModel { - [XmlElement("id")] + //[XmlElement("id")] public int Id { get; set; } [XmlElement("label")] @@ -73,12 +73,12 @@ namespace Step.Model.DTOModels.Scada public ScadaSchemaSizeModel Size { get; set; } [XmlElement("status")] - public ScadaSchemaStatusModel Status { get; set; } + public ScadaSchemaImgClickModel Status { get; set; } } public class ScadaSchemaLabelModel { - [XmlElement("id")] + //[XmlElement("id")] public int Id { get; set; } [XmlElement("label")] @@ -93,7 +93,7 @@ namespace Step.Model.DTOModels.Scada public class ScadaSchemaProgressBarModel { - [XmlElement("id")] + //[XmlElement("id")] public int Id { get; set; } [XmlElement("label")] @@ -111,7 +111,7 @@ namespace Step.Model.DTOModels.Scada public class ScadaSchemaInputModel { - [XmlElement("id")] + //[XmlElement("id")] public int Id { get; set; } [XmlElement("label")] @@ -122,6 +122,10 @@ namespace Step.Model.DTOModels.Scada [XmlElement("size")] public ScadaSchemaSizeModel Size { get; set; } + + [XmlElement("status")] + public ScadaSchemaInputDataModel Status { get; set; } + } /// @@ -163,10 +167,44 @@ namespace Step.Model.DTOModels.Scada public class ScadaSchemaStatusModel { + [XmlElement("memVisibleIndex")] + public string MemVisibleIndex { get; set; } + [XmlElement("memValueIndex")] public string MemValueIndex { get; set; } + } + + public class ScadaSchemaClickModel + { + [XmlElement("memEnabledIndex")] + public string MemEnabledIndex { get; set; } + + [XmlElement("memClickIndex")] + public string MemClickIndex { get; set; } + } + + public class ScadaSchemaImgClickModel + { [XmlElement("memVisibleIndex")] public string MemVisibleIndex { get; set; } + + [XmlElement("memClickIndex")] + public string MemClickIndex { get; set; } + } + + public class ScadaSchemaInputDataModel + { + [XmlElement("memVisibleIndex")] + public string MemVisibleIndex { get; set; } + + [XmlElement("memValueIndex")] + public string MemValueIndex { get; set; } + + [XmlElement("type")] + public string Type { get; set; } + + [XmlElement("action")] + public string Action { get; set; } } } \ No newline at end of file diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index 443d6c61..414e3b53 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -10,6 +10,7 @@ using Step.Model.DTOModels; using Step.Model.DTOModels.AlarmModels; using Step.Model.DTOModels.JobModels; using Step.Model.DTOModels.MaintenanceModels; +using Step.Model.DTOModels.Scada; using Step.Model.DTOModels.ToolModels; using Step.Utils; using System; @@ -2376,5 +2377,126 @@ namespace Step.NC } #endregion Osai/Fanuc Tools + + public CmsError ReadScadaData() + { + CmsError cmsError = NO_ERROR; + List scadas = new List(); + + DTOScadaModel scada = new DTOScadaModel(); + foreach (var prodScada in ProductionScada) + { + scada = new DTOScadaModel() + { + Name = prodScada.Name, + IsInProductionPage = prodScada.IsInProductionPage, + Buttons = new List() + }; + + // Cycle inside layers + foreach (var layer in prodScada.Layers) + { + object val = null; + object val2 = null; + // Cycle + for (int i = 0; i < layer.Buttons.Count(); i++) + { + if(layer.Buttons.ElementAt(i) != null) + { + // Read enabled from PLC + cmsError = numericalControl.PLC_RScadaValue(layer.Buttons[i].Status.MemEnabledIndex, ref val); + if (cmsError.IsError()) + return cmsError; + // Populate & add new object into scada model + scada.Buttons.Add(new DTOScadaButtonModel() + { + Id = layer.Buttons[i].Id, + Enabled = Convert.ToBoolean(val) + }); + } + + + if (layer.Images.ElementAt(i) != null) + { + // Read isVisible from PLC + cmsError = numericalControl.PLC_RScadaValue(layer.Images[i].Status.MemVisibleIndex, ref val); + if (cmsError.IsError()) + return cmsError; + // Populate & add new object into scada model + scada.Images.Add(new DTOScadaImageModel() + { + Id = layer.Images[i].Id, + IsVisible = Convert.ToBoolean(val) + }); + } + + + if(layer.ProgressBars.ElementAt(i) != null) + { + // Read value from PLC + cmsError = numericalControl.PLC_RScadaValue(layer.ProgressBars[i].MemValueIndex, ref val); + if (cmsError.IsError()) + return cmsError; + // Populate & add new object into scada model + scada.ProgressBars.Add(new DTOScadaProgressBarModel() + { + Id = layer.ProgressBars[i].Id, + Value = Convert.ToByte(val) + }); + } + + if (layer.Inputs.ElementAt(i) != null) + { + // Read isVisible from PLC + cmsError = numericalControl.PLC_RScadaValue(layer.Inputs[i].Status.MemVisibleIndex, ref val); + if (cmsError.IsError()) + return cmsError; + + // Read value from PLC + cmsError = numericalControl.PLC_RScadaValue(layer.Inputs[i].Status.MemValueIndex, ref val2); + if (cmsError.IsError()) + return cmsError; + + // Populate & add new object into scada model + scada.Inputs.Add(new DTOScadaInputModel() + { + Id = layer.Inputs[i].Id, + Value = new DTOScadaValueModel() + { + IsVisible = Convert.ToBoolean(val), + Value = Convert.ToBoolean(val) + } + }); + } + } + } + } + + return cmsError; + } + + //DTOScadaModel scada = new DTOScadaModel + //{ + // Layers = prodScada.Layers.Select(x => new DTOScadaLayerModel() + // { + // Id = x.Id, + // Buttons = x.Buttons.Select(y => new DTOScadaButtonModel() + // { + // Id = y.Id + // }).ToList(), + // Images = x.Images.Select(y => new DTOScadaImageModel() + // { + // Id = y.Id + // }).ToList(), + // ProgressBars = x.ProgressBars.Select(y => new DTOScadaProgressBarModel() + // { + // Id = y.Id + // }).ToList(), + // Inputs = x.Inputs.Select(y => new DTOScadaInputModel() + // { + // Id = y.Id + // }).ToList() + // }).ToList() + //}; } } \ No newline at end of file