From 424fc11fc137c01fc07d5e461d97f0aec07a3ccd Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 24 Jun 2022 11:55:12 +0200 Subject: [PATCH] Update SIM - generazione dati x stato - dati x contatori --- MP.MONO.ADAPTER.OPC/CONF/Tools.json | 32 +++--- MP.MONO.ADAPTER.OPC/CONF/Tools.multiax.json | 64 +++++------ MP.MONO.SIM/MP.MONO.SIM.csproj | 6 +- MP.MONO.SIM/Program.cs | 52 ++++----- MP.MONO.SIM/Simulator.cs | 114 +++++++++++++++++--- MP.MONO.SIM/conf/SimCountersRaw.json | 9 ++ MP.MONO.SIM/conf/SimMachStat.json | 16 +-- MP.MONO.SIM/conf/SimStatus.json | 14 --- 8 files changed, 188 insertions(+), 119 deletions(-) create mode 100644 MP.MONO.SIM/conf/SimCountersRaw.json delete mode 100644 MP.MONO.SIM/conf/SimStatus.json diff --git a/MP.MONO.ADAPTER.OPC/CONF/Tools.json b/MP.MONO.ADAPTER.OPC/CONF/Tools.json index d255f07..04e9d12 100644 --- a/MP.MONO.ADAPTER.OPC/CONF/Tools.json +++ b/MP.MONO.ADAPTER.OPC/CONF/Tools.json @@ -3,7 +3,7 @@ "Order": 0, "ExtCode": "ns=1;s=5_1_TOOL 1 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 01", + "Title": "SPINDLE 1 TOOL 01", "Value": "0", "ValueNum": 0, "MinVal": -9999, @@ -15,7 +15,7 @@ "Order": 1, "ExtCode": "ns=1;s=5_2_TOOL 2 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 02", + "Title": "SPINDLE 1 TOOL 02", "Value": "0", "ValueNum": 0, "MinVal": -9999, @@ -27,7 +27,7 @@ "Order": 2, "ExtCode": "ns=1;s=5_3_TOOL 3 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 03", + "Title": "SPINDLE 1 TOOL 03", "Value": "0", "ValueNum": 0, "MinVal": -9999, @@ -39,7 +39,7 @@ "Order": 3, "ExtCode": "ns=1;s=5_4_TOOL 4 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 04", + "Title": "SPINDLE 1 TOOL 04", "Value": "0", "ValueNum": 0, "MinVal": -9999, @@ -51,7 +51,7 @@ "Order": 4, "ExtCode": "ns=1;s=5_5_TOOL 11 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 05", + "Title": "SPINDLE 2 TOOL 01", "Value": "0", "ValueNum": 0, "MinVal": -9999, @@ -63,7 +63,7 @@ "Order": 5, "ExtCode": "ns=1;s=5_6_TOOL 12 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 06", + "Title": "SPINDLE 2 TOOL 02", "Value": "0", "ValueNum": 0, "MinVal": -9999, @@ -75,7 +75,7 @@ "Order": 6, "ExtCode": "ns=1;s=5_7_TOOL 13 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 07", + "Title": "SPINDLE 2 TOOL 03", "Value": "0", "ValueNum": 0, "MinVal": -9999, @@ -87,7 +87,7 @@ "Order": 7, "ExtCode": "ns=1;s=5_8_TOOL 14 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 08", + "Title": "SPINDLE 2 TOOL 04", "Value": "0", "ValueNum": 0, "MinVal": -9999, @@ -99,7 +99,7 @@ "Order": 8, "ExtCode": "ns=1;s=5_9_TOOL 21 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 09", + "Title": "SPINDLE 3 TOOL 01", "Value": "0", "ValueNum": 0, "MinVal": -9999, @@ -111,7 +111,7 @@ "Order": 9, "ExtCode": "ns=1;s=5_10_TOOL 22 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 10", + "Title": "SPINDLE 3 TOOL 2", "Value": "0", "ValueNum": 0, "MinVal": -9999, @@ -123,7 +123,7 @@ "Order": 10, "ExtCode": "ns=1;s=5_11_TOOL 23 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 11", + "Title": "SPINDLE 3 TOOL 3", "Value": "0", "ValueNum": 0, "MinVal": -9999, @@ -135,7 +135,7 @@ "Order": 11, "ExtCode": "ns=1;s=5_12_TOOL 24 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 12", + "Title": "SPINDLE 3 TOOL 4", "Value": "0", "ValueNum": 0, "MinVal": -9999, @@ -147,7 +147,7 @@ "Order": 12, "ExtCode": "ns=1;s=5_13_TOOL 31 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 13", + "Title": "SPINDLE 4 TOOL 1", "Value": "0", "ValueNum": 0, "MinVal": -9999, @@ -159,7 +159,7 @@ "Order": 13, "ExtCode": "ns=1;s=5_14_TOOL 32 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 14", + "Title": "SPINDLE 4 TOOL 2", "Value": "0", "ValueNum": 0, "MinVal": -9999, @@ -171,7 +171,7 @@ "Order": 14, "ExtCode": "ns=1;s=5_15_TOOL 33 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 15", + "Title": "SPINDLE 4 TOOL 3", "Value": "0", "ValueNum": 0, "MinVal": -9999, @@ -183,7 +183,7 @@ "Order": 15, "ExtCode": "ns=1;s=5_16_TOOL 34 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 16", + "Title": "SPINDLE 4 TOOL 4", "Value": "0", "ValueNum": 0, "MinVal": -9999, diff --git a/MP.MONO.ADAPTER.OPC/CONF/Tools.multiax.json b/MP.MONO.ADAPTER.OPC/CONF/Tools.multiax.json index c7b2b88..04e9d12 100644 --- a/MP.MONO.ADAPTER.OPC/CONF/Tools.multiax.json +++ b/MP.MONO.ADAPTER.OPC/CONF/Tools.multiax.json @@ -3,192 +3,192 @@ "Order": 0, "ExtCode": "ns=1;s=5_1_TOOL 1 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 01", + "Title": "SPINDLE 1 TOOL 01", "Value": "0", "ValueNum": 0, "MinVal": -9999, "MaxVal": 9999, - "DisplFormat": "N2", + "DisplFormat": "N1", "IsNumeric": true }, { "Order": 1, "ExtCode": "ns=1;s=5_2_TOOL 2 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 02", + "Title": "SPINDLE 1 TOOL 02", "Value": "0", "ValueNum": 0, "MinVal": -9999, "MaxVal": 9999, - "DisplFormat": "N2", + "DisplFormat": "N1", "IsNumeric": true }, { "Order": 2, "ExtCode": "ns=1;s=5_3_TOOL 3 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 03", + "Title": "SPINDLE 1 TOOL 03", "Value": "0", "ValueNum": 0, "MinVal": -9999, "MaxVal": 9999, - "DisplFormat": "N2", + "DisplFormat": "N1", "IsNumeric": true }, { "Order": 3, "ExtCode": "ns=1;s=5_4_TOOL 4 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 04", + "Title": "SPINDLE 1 TOOL 04", "Value": "0", "ValueNum": 0, "MinVal": -9999, "MaxVal": 9999, - "DisplFormat": "N2", + "DisplFormat": "N1", "IsNumeric": true }, { "Order": 4, "ExtCode": "ns=1;s=5_5_TOOL 11 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 05", + "Title": "SPINDLE 2 TOOL 01", "Value": "0", "ValueNum": 0, "MinVal": -9999, "MaxVal": 9999, - "DisplFormat": "N2", + "DisplFormat": "N1", "IsNumeric": true }, { "Order": 5, "ExtCode": "ns=1;s=5_6_TOOL 12 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 06", + "Title": "SPINDLE 2 TOOL 02", "Value": "0", "ValueNum": 0, "MinVal": -9999, "MaxVal": 9999, - "DisplFormat": "N2", + "DisplFormat": "N1", "IsNumeric": true }, { "Order": 6, "ExtCode": "ns=1;s=5_7_TOOL 13 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 07", + "Title": "SPINDLE 2 TOOL 03", "Value": "0", "ValueNum": 0, "MinVal": -9999, "MaxVal": 9999, - "DisplFormat": "N2", + "DisplFormat": "N1", "IsNumeric": true }, { "Order": 7, "ExtCode": "ns=1;s=5_8_TOOL 14 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 08", + "Title": "SPINDLE 2 TOOL 04", "Value": "0", "ValueNum": 0, "MinVal": -9999, "MaxVal": 9999, - "DisplFormat": "N2", + "DisplFormat": "N1", "IsNumeric": true }, { "Order": 8, "ExtCode": "ns=1;s=5_9_TOOL 21 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 09", + "Title": "SPINDLE 3 TOOL 01", "Value": "0", "ValueNum": 0, "MinVal": -9999, "MaxVal": 9999, - "DisplFormat": "N2", + "DisplFormat": "N1", "IsNumeric": true }, { "Order": 9, "ExtCode": "ns=1;s=5_10_TOOL 22 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 10", + "Title": "SPINDLE 3 TOOL 2", "Value": "0", "ValueNum": 0, "MinVal": -9999, "MaxVal": 9999, - "DisplFormat": "N2", + "DisplFormat": "N1", "IsNumeric": true }, { "Order": 10, "ExtCode": "ns=1;s=5_11_TOOL 23 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 11", + "Title": "SPINDLE 3 TOOL 3", "Value": "0", "ValueNum": 0, "MinVal": -9999, "MaxVal": 9999, - "DisplFormat": "N2", + "DisplFormat": "N1", "IsNumeric": true }, { "Order": 11, "ExtCode": "ns=1;s=5_12_TOOL 24 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 12", + "Title": "SPINDLE 3 TOOL 4", "Value": "0", "ValueNum": 0, "MinVal": -9999, "MaxVal": 9999, - "DisplFormat": "N2", + "DisplFormat": "N1", "IsNumeric": true }, { "Order": 12, "ExtCode": "ns=1;s=5_13_TOOL 31 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 13", + "Title": "SPINDLE 4 TOOL 1", "Value": "0", "ValueNum": 0, "MinVal": -9999, "MaxVal": 9999, - "DisplFormat": "N2", + "DisplFormat": "N1", "IsNumeric": true }, { "Order": 13, "ExtCode": "ns=1;s=5_14_TOOL 32 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 14", + "Title": "SPINDLE 4 TOOL 2", "Value": "0", "ValueNum": 0, "MinVal": -9999, "MaxVal": 9999, - "DisplFormat": "N2", + "DisplFormat": "N1", "IsNumeric": true }, { "Order": 14, "ExtCode": "ns=1;s=5_15_TOOL 33 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 15", + "Title": "SPINDLE 4 TOOL 3", "Value": "0", "ValueNum": 0, "MinVal": -9999, "MaxVal": 9999, - "DisplFormat": "N2", + "DisplFormat": "N1", "IsNumeric": true }, { "Order": 15, "ExtCode": "ns=1;s=5_16_TOOL 34 CURRENT LIFE PC", "Type": "TOOL", - "Title": "TOOL 16", + "Title": "SPINDLE 4 TOOL 4", "Value": "0", "ValueNum": 0, "MinVal": -9999, "MaxVal": 9999, - "DisplFormat": "N2", + "DisplFormat": "N1", "IsNumeric": true } ] \ No newline at end of file diff --git a/MP.MONO.SIM/MP.MONO.SIM.csproj b/MP.MONO.SIM/MP.MONO.SIM.csproj index d7df128..f69171a 100644 --- a/MP.MONO.SIM/MP.MONO.SIM.csproj +++ b/MP.MONO.SIM/MP.MONO.SIM.csproj @@ -63,15 +63,15 @@ Always + + Always + Always Always - - Always - Always diff --git a/MP.MONO.SIM/Program.cs b/MP.MONO.SIM/Program.cs index 468fe9f..5899a20 100644 --- a/MP.MONO.SIM/Program.cs +++ b/MP.MONO.SIM/Program.cs @@ -74,11 +74,11 @@ LogSimulator.Add(Constants.MAINT_STATS_M_QUEUE, 0); LogSimulator.Add(Constants.TOOLS_M_QUEUE, 0); // avvio tutti i thread... -Thread threadStatus = new Thread(simStatus); +Thread threadStatus = new Thread(simMPStatus); +Thread threadCount = new Thread(simCountersRaw); Thread threadAlarms = new Thread(simAlarms); Thread threadParams = new Thread(simParameters); Thread threadProd = new Thread(simProd); -Thread threadMachStat = new Thread(simMachStat); Thread threadMaint = new Thread(simMaint); Thread threadTools = new Thread(simTools); Thread threadEvHistory = new Thread(simEvents); @@ -88,7 +88,7 @@ threadStatus.Start(); threadAlarms.Start(); threadParams.Start(); threadProd.Start(); -threadMachStat.Start(); +threadCount.Start(); threadMaint.Start(); threadTools.Start(); threadEvHistory.Start(); @@ -346,13 +346,13 @@ void simParameters() } } -void simStatus() +void simMPStatus() { int minPeriod = 1000; int maxPeriod = 5000; // controllo se devo fare (se ho valori da simulare...) - if (currSimGen.currSimStatus.Count > 0) + if (currSimGen.currSimMachStat.Count > 0) { do { @@ -367,6 +367,27 @@ void simStatus() } } +void simCountersRaw() +{ + int minPeriod = 1000; + int maxPeriod = 5000; + + // controllo se devo fare (se ho valori da simulare...) + if (currSimGen.currSimMachStat.Count > 0) + { + do + { + // recupero uno stato simulato + var newStatus = currSimGen.getCountersRaw(); + string rawData = JsonConvert.SerializeObject(newStatus); + saveAndSendMessage(Constants.COUNT_CURR_KEY, Constants.COUNT_RAW_QUEUE, rawData); + + // attesa random + Thread.Sleep(rand.Next(minPeriod, maxPeriod)); + } while (true); + } +} + void simProd() { int minPeriod = 3000; @@ -388,27 +409,6 @@ void simProd() } } -void simMachStat() -{ - int minPeriod = 5000; - int maxPeriod = 15000; - - - // controllo se devo fare (se ho valori da simulare...) - if (currSimGen.currSimMachStat.Count > 0) - { - do - { - // recupero uno stato simulato - var newVal = currSimGen.getProdStats(); - string rawData = JsonConvert.SerializeObject(newVal); - saveAndSendMessage(Constants.MACH_STATS_CURR_KEY, Constants.MACH_STATS_M_QUEUE, rawData); - - // attesa random - Thread.Sleep(rand.Next(minPeriod, maxPeriod)); - } while (true); - } -} void simMaint() { diff --git a/MP.MONO.SIM/Simulator.cs b/MP.MONO.SIM/Simulator.cs index 9403a75..406a0bc 100644 --- a/MP.MONO.SIM/Simulator.cs +++ b/MP.MONO.SIM/Simulator.cs @@ -13,12 +13,12 @@ namespace MachineSim public List currSimActLog = new List(); public List currSimEvHist = new List(); - public List currSimMachStat = new List(); public List currSimMaint = new List(); public List currSimPar = new List(); public List currSimProd = new List(); - public List currSimStatus = new List(); public List currSimTools = new List(); + public List currCountersRaw = new List(); + public List currSimMachStat = new List(); #endregion Public Fields @@ -183,6 +183,7 @@ namespace MachineSim return currMachDto; } +#if false public List getProdStats() { List answ = new List(); @@ -207,7 +208,8 @@ namespace MachineSim } return answ; - } + } +#endif /// /// Restituisce elenco info stato Macchina simulato come lista da adapter @@ -216,9 +218,6 @@ namespace MachineSim public Dictionary getStatus() { Dictionary answ = new Dictionary(); - int maxRun = 7; - int maxExe = 7; - // simulo stato macchina ad 1 nel 99.5% (0 nel 0.5% dei casi if (rand.Next(0, 1000) < 995) { @@ -248,6 +247,72 @@ namespace MachineSim answ.Add("PROCESS STATUS", "3"); answ.Add("PROCESS MODE", "7"); } + // aggiunta part program che cambia ogni minuto... + answ.Add("RECIPE NAME", $"{DateTime.Now:yyMMdd-HHmm}.prg"); + return answ; + } + + + /// + /// Restituisce elenco info dati x contatori come lista da adapter + /// + /// + public Dictionary getCountersRaw() + { + Dictionary answ = new Dictionary(); + + // simulo stato macchina ad 1 nel 99.5% (0 nel 0.5% dei casi + if (rand.Next(0, 1000) < 995) + { + answ.Add("MACHINE STATUS", "1"); + } + else + { + answ.Add("MACHINE STATUS", "1"); + } + + // simulo stato processo in ciclo 90% dei casi, resto HOLD + if (rand.Next(0, 1000) < 900) + { + answ.Add("PROCESS STATUS", "2"); + // simulo modo auto 90% dei casi + if (rand.Next(0, 1000) < 900) + { + answ.Add("PROCESS MODE", "2"); + // aggiungo spindle load che sono attivi 50% del tempo ogni coppia, random + if (rand.Next(0, 1000) < 500) + { + answ.Add("SPINDLE 1 LOAD", $"{rand.Next(5, 80)}"); + answ.Add("SPINDLE 2 LOAD", $"{rand.Next(5, 80)}"); + answ.Add("SPINDLE 3 LOAD", $"{rand.Next(5, 80)}"); + answ.Add("SPINDLE 4 LOAD", $"{rand.Next(5, 80)}"); + } + else + { + answ.Add("SPINDLE 1 LOAD", "0"); + answ.Add("SPINDLE 2 LOAD", "0"); + answ.Add("SPINDLE 3 LOAD", "0"); + answ.Add("SPINDLE 4 LOAD", "0"); + } + } + else + { + answ.Add("PROCESS MODE", "1"); + answ.Add("SPINDLE 1 LOAD", "0"); + answ.Add("SPINDLE 2 LOAD", "0"); + answ.Add("SPINDLE 3 LOAD", "0"); + answ.Add("SPINDLE 4 LOAD", "0"); + } + } + else + { + answ.Add("PROCESS STATUS", "3"); + answ.Add("PROCESS MODE", "7"); + answ.Add("SPINDLE 1 LOAD", "0"); + answ.Add("SPINDLE 2 LOAD", "0"); + answ.Add("SPINDLE 3 LOAD", "0"); + answ.Add("SPINDLE 4 LOAD", "0"); + } return answ; } @@ -354,7 +419,7 @@ namespace MachineSim #region Private Methods - private void setupConf(string paramFileName, ref List localObj) + private void setupConfDTO(string paramFileName, ref List localObj) { string fullPath = Path.Combine(basePath, paramFileName); if (File.Exists(fullPath)) @@ -371,24 +436,41 @@ namespace MachineSim } } + private void setupConfList(string paramFileName, ref List localObj) + { + string fullPath = Path.Combine(basePath, paramFileName); + if (File.Exists(fullPath)) + { + var rawData = File.ReadAllText(fullPath); + if (!string.IsNullOrEmpty(rawData)) + { + var deserObj = JsonConvert.DeserializeObject>(rawData); + if (deserObj != null) + { + localObj = deserObj; + } + } + } + } + private void setupConfig() { // setup conf Parametri - setupConf("SimParams.json", ref currSimPar); - // setup conf MachStat - setupConf("SimMachStat.json", ref currSimMachStat); + setupConfDTO("SimParams.json", ref currSimPar); // setup conf Maintenance - setupConf("SimMaint.json", ref currSimMaint); + setupConfDTO("SimMaint.json", ref currSimMaint); // setup conf Tools - setupConf("SimTools.json", ref currSimTools); + setupConfDTO("SimTools.json", ref currSimTools); // setup conf Event History - setupConf("SimEvHist.json", ref currSimEvHist); + setupConfDTO("SimEvHist.json", ref currSimEvHist); // setup conf Activity Log - setupConf("SimActLog.json", ref currSimActLog); + setupConfDTO("SimActLog.json", ref currSimActLog); // setup conf Prod - setupConf("SimProd.json", ref currSimProd); + setupConfDTO("SimProd.json", ref currSimProd); + // setup conf MachStat + setupConfList("SimMachStat.json", ref currSimMachStat); // setup conf Prod - setupConf("SimStatus.json", ref currSimStatus); + setupConfList("SimStatus.json", ref currCountersRaw); } #endregion Private Methods diff --git a/MP.MONO.SIM/conf/SimCountersRaw.json b/MP.MONO.SIM/conf/SimCountersRaw.json new file mode 100644 index 0000000..001b0ef --- /dev/null +++ b/MP.MONO.SIM/conf/SimCountersRaw.json @@ -0,0 +1,9 @@ +[ + "MACHINE STATUS", + "PROCESS STATUS", + "PROCESS MODE", + "SPINDLE 1 LOAD", + "SPINDLE 2 LOAD", + "SPINDLE 3 LOAD", + "SPINDLE 4 LOAD" +] \ No newline at end of file diff --git a/MP.MONO.SIM/conf/SimMachStat.json b/MP.MONO.SIM/conf/SimMachStat.json index 702cc02..ca488bf 100644 --- a/MP.MONO.SIM/conf/SimMachStat.json +++ b/MP.MONO.SIM/conf/SimMachStat.json @@ -1,14 +1,6 @@ [ - { - "Order": 0, - "Type": "OEE-75-90", - "Title": "OEE", - "Value": "0.5", - "ValueNum": 0.5, - "MinVal": 0.4, - "MaxVal": 1, - "SimMean": 0.2, - "SimStd": 0.2, - "DisplFormat": "P1" - } + "MACHINE STATUS", + "PROCESS STATUS", + "PROCESS MODE", + "RECIPE NAME" ] \ No newline at end of file diff --git a/MP.MONO.SIM/conf/SimStatus.json b/MP.MONO.SIM/conf/SimStatus.json deleted file mode 100644 index 1a1efc0..0000000 --- a/MP.MONO.SIM/conf/SimStatus.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "Order": 0, - "Type": "POS", - "Title": "Z POS", - "Value": "-500", - "ValueNum": -500, - "MinVal": -3000, - "MaxVal": 0, - "SimMean": 50, - "SimStd": 5, - "DisplFormat": "N2" - } -] \ No newline at end of file