fix per uppercase vari e gestione nomi file generati

This commit is contained in:
zaccaria.majid
2023-07-24 15:52:23 +02:00
parent 8def552ab9
commit e58ee47832
4 changed files with 94 additions and 291 deletions
@@ -1,115 +0,0 @@
#
# Macchine MULTI (bench x SIMULA) - macchina PRINCIPALE
# - contapezzi SEMPRE attivo (anche in attrezzaggio)
# - gestione cicli riscaldo
# - COMMENTATO gestione check TCiclo rallentato
#
# partenza da 5 + 60
#
# 2020.10.01 S.E.L.
#
#
$DEFINITIONS
$NAME : REFERENCE_MULTI_MAIN
$IDX : 61
$N_STATES : 9
$N_BITS : 8
#definizione bit : obbligatorio iniziare da 0
$BIT : 0 : bPowerOn
$BIT : 1 : bRun
$BIT : 2 : bPzCount
$BIT : 3 : bAlarm
$BIT : 4 : bManual
$BIT : 5 : bslowTC
$BIT : 6 : bWUpCDown
$BIT : 7 : bEmergArm
#definizione stati : obbligatorio iniziare da 0
$STATE : 0 : ST_Init
$STATE : 1 : ST_Power_off
$STATE : 2 : ST_Machine_ready
$STATE : 3 : ST_Run
$STATE : 4 : ST_Cycle_end
$STATE : 5 : ST_Alarm
$STATE : 6 : ST_Manual
$STATE : 7 : ST_Slow
$STATE : 8 : ST_WUp_CDown
#definizione eventi : obbligatorio iniziare da 0
$EVENT : 00 : EV_00
$EVENT : 01 : EV_01
$EVENT : 02 : EV_02
$EVENT : 03 : EV_03
$EVENT : 04 : EV_04
$EVENT : 05 : EV_05
$EVENT : 06 : EV_06
$EVENT : 07 : EV_07
$EVENT : 08 : EV_08
$EVENT : 09 : EV_09
$EVENT : 10 : EV_10
$EVENT : 11 : EV_11
$EVENT : 12 : EV_12
$EVENT : 13 : HW_init
$EVENT : 14 : HW_power_off
$EVENT : 15 : HW_PowerOn
$EVENT : 16 : HW_machining
$EVENT : 17 : HW_end_machining
$EVENT : 18 : HW_error
$EVENT : 19 : Barcode_cambio operatore
$EVENT : 20 : Contapezzi
$EVENT : 21 : HW_start_pallet
$EVENT : 22 : HW_end_pallet
$EVENT : 23 : HW_rottura_nastro_abrasivo
$EVENT : 24 : HW_manuale
$EVENT : 25 : HW_nastro_scarico_pieno
$EVENT : 26 : Barcode_Manca_Riforn_MPD
$EVENT : 27 : Timer_timeout_tempo_ciclo
$EVENT : 28 : Timer_timeout_TURNO_by_tempo_ciclo
$EVENT : 29 : HW_magazzino_grezzi vuoto
$EVENT : 30 : HW_emergenza
$EVENT : 31 : Barcode_Modifica_Programmi
$EVENT : 32 : Barcode_Sostituzione_Utensile
$EVENT : 33 : HW_Allarme Macchina
$EVENT : 34 : HW_end_pallet_1
$EVENT : 35 : HW_end_pallet_2
$EVENT : 36 : HW_deposito_robot
$EVENT : 37 : Barcode_Riempimento_Vasca
$EVENT : 38 : Barcode_Riscaldamento
$EVENT : 39 : Barcode_Anomalia_Macchina
$EVENT : 40 : HW_WarmUp_CoolDown
$EVENT : 41 : HW_machining_SLOW
$EVENT : 42 : HW_Warn_Livello_Vasca
$EVENT : 43 : HW_Warn_Livello_Cell
$EVENT : 44 : HW_Warn_a_Vuoto
$EVENT : 45 : HW_Warn_Riserva
$EVENT : 46 : HW_Carico
$EVENT : 47 : HW_Mismatch
$EVENT : 48 : HW_preparing
#EVENT : 120 : IncrementoPezzi
#EVENT : 121 : RettificaPezzi
#$EVENT : 999 : Commento
$RULES
# state : input : next state : event
ALL_STATES : NOT bPowerOn : ST_Power_off : HW_power_off
ALL_STATES : NOT bEmergArm : ST_Init : HW_emergenza
ALL_STATES : bPzCount : ST_Cycle_end : HW_end_pallet
ALL_STATES : bWUpCDown : ST_WUp_CDown : HW_WarmUp_CoolDown
ALL_STATES : bManual : ST_Manual : HW_manuale
ALL_STATES : bAlarm : ST_Alarm : HW_error
#ALL_STATES : bslowTC : ST_Slow : HW_machining_SLOW
ALL_STATES : bRun : ST_Run : HW_machining
ALL_STATES : bPowerOn : ST_Machine_ready : HW_PowerOn
#--------------------------------------------------------------------------
$DO
@@ -1,114 +0,0 @@
#
# Macchine STD (bench x SIMULA)
# - contapezzi SEMPRE attivo (anche in attrezzaggio)
# - gestione cicli riscaldo
# - gestione check TCiclo rallentato
#
# partenza da IdxFam 42
#
# 2020.10.01 S.E.L.
#
$DEFINITIONS
$NAME : REFERENCE_STD
$IDX : 60
$N_STATES : 9
$N_BITS : 8
#definizione bit : obbligatorio iniziare da 0
$BIT : 0 : B_PowerOn
$BIT : 1 : B_Run
$BIT : 2 : B_PzCount
$BIT : 3 : B_Alarm
$BIT : 4 : B_Manual
$BIT : 5 : B_SlowTC
$BIT : 6 : B_WUpCDown
$BIT : 7 : B_EmergArm
#definizione stati : obbligatorio iniziare da 0
$STATE : 0 : ST_Init
$STATE : 1 : ST_Power_off
$STATE : 2 : ST_Machine_ready
$STATE : 3 : ST_Run
$STATE : 4 : ST_Cycle_end
$STATE : 5 : ST_Alarm
$STATE : 6 : ST_Manual
$STATE : 7 : ST_Slow
$STATE : 8 : ST_WUp_CDown
#definizione eventi : obbligatorio iniziare da 0
$EVENT : 00 : EV_00
$EVENT : 01 : EV_01
$EVENT : 02 : EV_02
$EVENT : 03 : EV_03
$EVENT : 04 : EV_04
$EVENT : 05 : EV_05
$EVENT : 06 : EV_06
$EVENT : 07 : EV_07
$EVENT : 08 : EV_08
$EVENT : 09 : EV_09
$EVENT : 10 : EV_10
$EVENT : 11 : EV_11
$EVENT : 12 : EV_12
$EVENT : 13 : HW_init
$EVENT : 14 : HW_power_off
$EVENT : 15 : HW_PowerOn
$EVENT : 16 : HW_machining
$EVENT : 17 : HW_end_machining
$EVENT : 18 : HW_error
$EVENT : 19 : Barcode_cambio operatore
$EVENT : 20 : Contapezzi
$EVENT : 21 : HW_start_pallet
$EVENT : 22 : HW_end_pallet
$EVENT : 23 : HW_rottura_nastro_abrasivo
$EVENT : 24 : HW_manuale
$EVENT : 25 : HW_nastro_scarico_pieno
$EVENT : 26 : Barcode_Manca_Riforn_MPD
$EVENT : 27 : Timer_timeout_tempo_ciclo
$EVENT : 28 : Timer_timeout_TURNO_by_tempo_ciclo
$EVENT : 29 : HW_magazzino_grezzi vuoto
$EVENT : 30 : HW_emergenza
$EVENT : 31 : Barcode_Modifica_Programmi
$EVENT : 32 : Barcode_Sostituzione_Utensile
$EVENT : 33 : HW_Allarme Macchina
$EVENT : 34 : HW_end_pallet_1
$EVENT : 35 : HW_end_pallet_2
$EVENT : 36 : HW_deposito_robot
$EVENT : 37 : Barcode_Riempimento_Vasca
$EVENT : 38 : Barcode_Riscaldamento
$EVENT : 39 : Barcode_Anomalia_Macchina
$EVENT : 40 : HW_WarmUp_CoolDown
$EVENT : 41 : HW_machining_SLOW
$EVENT : 42 : HW_Warn_Livello_Vasca
$EVENT : 43 : HW_Warn_Livello_Cell
$EVENT : 44 : HW_Warn_a_Vuoto
$EVENT : 45 : HW_Warn_Riserva
$EVENT : 46 : HW_Carico
$EVENT : 47 : HW_Mismatch
$EVENT : 48 : HW_preparing
#EVENT : 120 : IncrementoPezzi
#EVENT : 121 : RettificaPezzi
#$EVENT : 999 : Commento
$RULES
# state : input : next state : event
ALL_STATES : NOT B_PowerOn : ST_Power_off : HW_power_off
ALL_STATES : NOT B_EmergArm : ST_Init : HW_emergenza
ALL_STATES : B_PzCount : ST_Cycle_end : HW_end_pallet
ALL_STATES : B_WUpCDown : ST_WUp_CDown : HW_WarmUp_CoolDown
ALL_STATES : B_Manual : ST_Manual : HW_manuale
ALL_STATES : B_Alarm : ST_Alarm : HW_error
ALL_STATES : B_SlowTC : ST_Slow : HW_machining_SLOW
ALL_STATES : B_Run : ST_Run : HW_machining
ALL_STATES : B_PowerOn : ST_Machine_ready : HW_PowerOn
#--------------------------------------------------------------------------
$DO
+2 -2
View File
@@ -14,9 +14,9 @@
Vista in preview si può poi inserire in prod se confermato
</p>
<InputFile OnChange="@LoadFiles" />
<InputFile OnChange="@LoadFiles" multiple/>
<button @onclick="()=>Read_rule_file_transitions()"></button>
<button @onclick="()=>Read_rule_file_transitions()">Process</button>
<span class="fs-1">@sz_file2Read</span>
+92 -60
View File
@@ -44,13 +44,14 @@ namespace SMGen.Pages
protected List<string> Events_to_send { get; set; } = new List<string>();
protected List<RuleClass> Rules { get; set; } = new List<RuleClass>();
protected Dictionary<string, string> files2Read { get; set; } = new Dictionary<string, string>();
//// va dopo
//private StreamWriter objWriter { get; set; };
private async Task LoadFiles(InputFileChangeEventArgs e)
{
List<IBrowserFile> loadedFiles = new();
long maxFileSize = 1024 * 15;
int maxAllowedFiles = 3;
int maxAllowedFiles = 150;
bool isLoading;
isLoading = true;
loadedFiles.Clear();
@@ -78,13 +79,20 @@ namespace SMGen.Pages
{
Directory.CreateDirectory(pathDir);
}
else
{
//deleteOldFiles(pathDir);
}
//creo file
await using FileStream fs = new(pathFile, FileMode.Create);
//copio il contenuto del file
await file.OpenReadStream(maxFileSize).CopyToAsync(fs);
sz_file2Read = pathFile;
if (file.Name.Contains(".rul"))
{
files2Read.Add(file.Name, pathFile);
}
}
catch (Exception ex)
{
@@ -94,87 +102,111 @@ namespace SMGen.Pages
isLoading = false;
}
/// <summary>
/// Procedee a bonificare la cartella di upload dei files + vecchi di 3 mesi
/// </summary>
private void deleteOldFiles(string dirPath)
{
// elenco files nella directory
string[] files = Directory.GetFiles(dirPath);
// li guardo tutti e se vecchi li elimino...
foreach (string file in files)
{
FileInfo fi = new FileInfo(file);
if (fi.LastAccessTime < DateTime.Now.AddMinutes(-20))
{
fi.Delete();
}
}
}
protected async Task Read_rule_file_transitions()
{
using (StreamReader sr = new StreamReader(sz_file2Read))
foreach (var item in files2Read)
{
States.Clear();
Bits.Clear();
Events_to_send.Clear();
Rules.Clear();
string line = "";
while ((line = await sr.ReadLineAsync().ConfigureAwait(false)) != null)
sz_file2Read = item.Value;
using (StreamReader sr = new StreamReader(sz_file2Read))
{
if (!line.StartsWith("#") && !string.IsNullOrEmpty(line))
States.Clear();
Bits.Clear();
Events_to_send.Clear();
Rules.Clear();
string line = "";
while ((line = await sr.ReadLineAsync().ConfigureAwait(false)) != null)
{
var sz_tokens = line.Split(":");
var sz_temp = sz_tokens[0].Trim();
switch (sz_temp)
if (!line.StartsWith("#") && !string.IsNullOrEmpty(line))
{
case "$DEFINITIONS":
b_rules_definition = false;
break;
case "$NAME":
sz_state_machine_name = sz_tokens[1].Trim();
break;
var sz_tokens = line.Split(":");
case "$IDX":
n_state_machine_index = sz_tokens[1].Trim();
break;
var sz_temp = sz_tokens[0].Trim();
switch (sz_temp)
{
case "$DEFINITIONS":
b_rules_definition = false;
break;
case "$NAME":
sz_state_machine_name = sz_tokens[1].Trim();
break;
case "$N_STATES":
n_states = int.Parse(sz_tokens[1].Trim());
break;
case "$IDX":
n_state_machine_index = sz_tokens[1].Trim();
break;
case "$N_BITS":
n_bits = int.Parse(sz_tokens[1].Trim());
break;
case "$N_STATES":
n_states = int.Parse(sz_tokens[1].Trim());
break;
case "$BIT":
Bits.Add(sz_tokens[2].Trim().ToUpper());
break;
case "$N_BITS":
n_bits = int.Parse(sz_tokens[1].Trim());
break;
case "$STATE":
States.Add(sz_tokens[2].Trim().ToUpper());
break;
case "$BIT":
Bits.Add(sz_tokens[2].Trim().ToUpper());
break;
case "$EVENT":
Events_to_send.Add(sz_tokens[2].Trim().ToUpper());
break;
case "$STATE":
States.Add(sz_tokens[2].Trim().ToUpper());
break;
case "$RULES":
b_rules_definition = true;
break;
case "$EVENT":
Events_to_send.Add(sz_tokens[2].Trim().ToUpper());
break;
case "$DO":
b_rules_definition = false;
evaluate_transitions();
break;
case "$RULES":
b_rules_definition = true;
break;
default:
if (b_rules_definition)
{
var temp_rule = new RuleClass()
case "$DO":
b_rules_definition = false;
evaluate_transitions($"C:\\Temp\\Rules\\PROCESSED\\{item.Key.Split(".")[0]}.csv");
break;
default:
if (b_rules_definition)
{
state = sz_temp,
expression = sz_tokens[1].Trim().ToUpper(),
next_state = sz_tokens[2].Trim().ToUpper(),
event_to_send = sz_tokens[3].Trim().ToUpper()
};
var temp_rule = new RuleClass()
{
state = sz_temp.Trim().ToUpper(),
expression = sz_tokens[1].Trim().ToUpper(),
next_state = sz_tokens[2].Trim().ToUpper(),
event_to_send = sz_tokens[3].Trim().ToUpper()
};
Rules.Add(temp_rule);
}
break;
Rules.Add(temp_rule);
}
break;
}
//fileLines.Add(lineSplit[0]);
}
//fileLines.Add(lineSplit[0]);
}
}
}
}
protected void evaluate_transitions()
protected void evaluate_transitions(string sz_file2Write)
{
using (StreamWriter sw = new StreamWriter(sz_file2Write))
{