From f316e26c239a0130ab5b09354deab4b3f974c943 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Tue, 13 Dec 2022 14:56:24 +0100 Subject: [PATCH 1/2] Test (NON provato) x import excel, non possibile fix compression e catena relativa in portatile --- IOB-WIN-NEXT/DATA/CONF/GIACO_SAIM_003.json | 12 +++ IOB-WIN-NEXT/DATA/CONF/MAIN.ini | 2 +- IOB-WIN-NEXT/DATA/CONF/SIMUL_01.json | 20 ++--- IOB-WIN-NEXT/DATA/CONF/SIMUL_02.json | 12 +++ IOB-WIN-NEXT/IobModbusTCPSaim.cs | 97 +++++++++++++--------- IOB-WIN-NEXT/IobSimula.cs | 97 +++++++++++++--------- 6 files changed, 147 insertions(+), 93 deletions(-) diff --git a/IOB-WIN-NEXT/DATA/CONF/GIACO_SAIM_003.json b/IOB-WIN-NEXT/DATA/CONF/GIACO_SAIM_003.json index 9377a7d2..5731457b 100644 --- a/IOB-WIN-NEXT/DATA/CONF/GIACO_SAIM_003.json +++ b/IOB-WIN-NEXT/DATA/CONF/GIACO_SAIM_003.json @@ -450,5 +450,17 @@ "maxVal": 999999999, "unit": "#" } + }, + "fileDecod": { + "Product": 3, + "Variety": 9, + "Supplier": 8, + "ExtDoc": 2, + "DateRif": 14, + "QtyTot": 22, + "NumPack": 21, + "NumPed": 17, + "PackPed": 18, + "PesoPack": 20 } } \ No newline at end of file diff --git a/IOB-WIN-NEXT/DATA/CONF/MAIN.ini b/IOB-WIN-NEXT/DATA/CONF/MAIN.ini index 794a370b..d750ed94 100644 --- a/IOB-WIN-NEXT/DATA/CONF/MAIN.ini +++ b/IOB-WIN-NEXT/DATA/CONF/MAIN.ini @@ -45,6 +45,6 @@ CLI_INST=SteamWareSim ;STARTLIST=BAGLIETTO_CIMOLAI_01 ;STARTLIST=SIMUL_01 ;STARTLIST=GIACO_SAIM_003 -STARTLIST=GIACO_SAIM_003 +STARTLIST=SIMUL_01 MAXCNC=10 \ No newline at end of file diff --git a/IOB-WIN-NEXT/DATA/CONF/SIMUL_01.json b/IOB-WIN-NEXT/DATA/CONF/SIMUL_01.json index 482f00ef..06269024 100644 --- a/IOB-WIN-NEXT/DATA/CONF/SIMUL_01.json +++ b/IOB-WIN-NEXT/DATA/CONF/SIMUL_01.json @@ -85,15 +85,15 @@ } }, "fileDecod": { - "Product": 2, - "Variety": 3, - "Supplier": 4, - "ExtDoc": 0, - "DateRif": 1, - "QtyTot": 15, - "NumPack": 14, - "NumPed": 11, - "PackPed": 12, - "PesoPack": 13 + "Product": 3, + "Variety": 9, + "Supplier": 8, + "ExtDoc": 2, + "DateRif": 14, + "QtyTot": 22, + "NumPack": 21, + "NumPed": 17, + "PackPed": 18, + "PesoPack": 20 } } \ No newline at end of file diff --git a/IOB-WIN-NEXT/DATA/CONF/SIMUL_02.json b/IOB-WIN-NEXT/DATA/CONF/SIMUL_02.json index dbb74d4d..482f00ef 100644 --- a/IOB-WIN-NEXT/DATA/CONF/SIMUL_02.json +++ b/IOB-WIN-NEXT/DATA/CONF/SIMUL_02.json @@ -83,5 +83,17 @@ "minVal": 0, "maxVal": 1500 } + }, + "fileDecod": { + "Product": 2, + "Variety": 3, + "Supplier": 4, + "ExtDoc": 0, + "DateRif": 1, + "QtyTot": 15, + "NumPack": 14, + "NumPed": 11, + "PackPed": 12, + "PesoPack": 13 } } \ No newline at end of file diff --git a/IOB-WIN-NEXT/IobModbusTCPSaim.cs b/IOB-WIN-NEXT/IobModbusTCPSaim.cs index 02d238a3..cd3eceb9 100644 --- a/IOB-WIN-NEXT/IobModbusTCPSaim.cs +++ b/IOB-WIN-NEXT/IobModbusTCPSaim.cs @@ -223,53 +223,68 @@ namespace IOB_WIN_NEXT double qtyTot = 0; int numPack = 0; string ddt = tabella.Rows[i].ItemArray[FileDecod["ExtDoc"]].ToString().Trim(); - string prod = tabella.Rows[i].ItemArray[FileDecod["Product"]].ToString().Trim(); - string variety = tabella.Rows[i].ItemArray[FileDecod["Variety"]].ToString().Trim(); - string suppl = tabella.Rows[i].ItemArray[FileDecod["Supplier"]].ToString().Trim(); string sDate = tabella.Rows[i].ItemArray[FileDecod["DateRif"]].ToString().Trim(); - string sQty = tabella.Rows[i].ItemArray[FileDecod["QtyTot"]].ToString().Trim(); - string sNum = tabella.Rows[i].ItemArray[FileDecod["NumPack"]].ToString().Trim(); - string numPed = tabella.Rows[i].ItemArray[FileDecod["NumPed"]].ToString().Trim(); - string packPed = tabella.Rows[i].ItemArray[FileDecod["PackPed"]].ToString().Trim(); - string pesoPack = tabella.Rows[i].ItemArray[FileDecod["PesoPack"]].ToString().Trim(); - DateTime.TryParse(sDate, out dtRif); - int.TryParse(sNum, out numPack); - double.TryParse(sQty, out qtyTot); - string identRG = ddt.Length > 2 ? $"{strFixId(ddt)}.{strFixId(prod)}.{strFixId(variety)}.{strFixId(suppl)}" : $"{dtRif:yyyyMMdd}.{strFixId(prod)}.{strFixId(variety)}.{strFixId(suppl)}"; - string notes = $"{numPed}x{packPed}x{pesoPack}"; - // verifico di avere dati per proseguire... - bool checkIdent = !string.IsNullOrEmpty($"{prod}{variety}{suppl}"); + string prod = tabella.Rows[i].ItemArray[FileDecod["Product"]].ToString().Trim(); + // verifiche x import: header, data e DDT (vuoti o "-") --> SKIP! bool checkHeaderKo = (ddt == "DDT" || prod == "PRODOTTO"); - if (checkIdent && !checkHeaderKo) + bool checkEmptyDdt = (string.IsNullOrEmpty(ddt) || ddt == "-"); + bool checkEmptyDate = (string.IsNullOrEmpty(sDate) || sDate == "-"); + if (checkHeaderKo) { - BatchRec newRow = new BatchRec() - { - IdxODL = idxODL, - IdentRG = identRG, - DateRif = dtRif, - ExtDoc = ddt, - Product = prod, - Variety = variety, - Supplier = suppl, - NumPack = numPack, - QtyTot = qtyTot, - Notes = notes - }; - // verifico: se manca aggiungo - if (!listaGiac.ContainsKey(identRG)) - { - listaGiac.Add(identRG, newRow); - } - else - { - // altrimenti aggiorno giacenza con valori numerici - listaGiac[identRG].NumPack += newRow.NumPack; - listaGiac[identRG].QtyTot += newRow.QtyTot; - } + lgTrace($"SKIP header"); + } + else if (checkEmptyDdt || checkEmptyDate) + { + lgTrace($"SKIP linea vuota | i: {i} | ddt: {ddt} | date: {sDate} | prod: {prod}"); } else { - numErr++; + string variety = tabella.Rows[i].ItemArray[FileDecod["Variety"]].ToString().Trim(); + string suppl = tabella.Rows[i].ItemArray[FileDecod["Supplier"]].ToString().Trim(); + string sQty = tabella.Rows[i].ItemArray[FileDecod["QtyTot"]].ToString().Trim(); + string sNum = tabella.Rows[i].ItemArray[FileDecod["NumPack"]].ToString().Trim(); + string numPed = tabella.Rows[i].ItemArray[FileDecod["NumPed"]].ToString().Trim(); + string packPed = tabella.Rows[i].ItemArray[FileDecod["PackPed"]].ToString().Trim(); + string pesoPack = tabella.Rows[i].ItemArray[FileDecod["PesoPack"]].ToString().Trim(); + DateTime.TryParse(sDate, out dtRif); + int.TryParse(sNum, out numPack); + double.TryParse(sQty, out qtyTot); + string identRG = ddt.Length > 2 ? $"{strFixId(ddt)}.{strFixId(prod)}.{strFixId(variety)}.{strFixId(suppl)}" : $"{dtRif:yyyyMMdd}.{strFixId(prod)}.{strFixId(variety)}.{strFixId(suppl)}"; + string notes = $"{numPed}x{packPed}x{pesoPack}"; + // verifico di avere dati per proseguire... + bool checkIdent = !string.IsNullOrEmpty($"{prod}{variety}{suppl}"); + if (checkIdent) + { + BatchRec newRow = new BatchRec() + { + IdxODL = idxODL, + IdentRG = identRG, + DateRif = dtRif, + ExtDoc = ddt, + Product = prod, + Variety = variety, + Supplier = suppl, + NumPack = numPack, + QtyTot = qtyTot, + Notes = notes + }; + // verifico: se manca aggiungo + if (!listaGiac.ContainsKey(identRG)) + { + listaGiac.Add(identRG, newRow); + } + else + { + // altrimenti aggiorno giacenza con valori numerici + listaGiac[identRG].NumPack += newRow.NumPack; + listaGiac[identRG].QtyTot += newRow.QtyTot; + } + } + else + { + lgError($"Errore verifica identità riga | prod: {prod} | variety: {variety} | suppl: {suppl}"); + numErr++; + } } } catch (Exception exc) diff --git a/IOB-WIN-NEXT/IobSimula.cs b/IOB-WIN-NEXT/IobSimula.cs index 8bf38c4f..31575816 100644 --- a/IOB-WIN-NEXT/IobSimula.cs +++ b/IOB-WIN-NEXT/IobSimula.cs @@ -575,53 +575,68 @@ namespace IOB_WIN_NEXT double qtyTot = 0; int numPack = 0; string ddt = tabella.Rows[i].ItemArray[FileDecod["ExtDoc"]].ToString().Trim(); - string prod = tabella.Rows[i].ItemArray[FileDecod["Product"]].ToString().Trim(); - string variety = tabella.Rows[i].ItemArray[FileDecod["Variety"]].ToString().Trim(); - string suppl = tabella.Rows[i].ItemArray[FileDecod["Supplier"]].ToString().Trim(); string sDate = tabella.Rows[i].ItemArray[FileDecod["DateRif"]].ToString().Trim(); - string sQty = tabella.Rows[i].ItemArray[FileDecod["QtyTot"]].ToString().Trim(); - string sNum = tabella.Rows[i].ItemArray[FileDecod["NumPack"]].ToString().Trim(); - string numPed = tabella.Rows[i].ItemArray[FileDecod["NumPed"]].ToString().Trim(); - string packPed = tabella.Rows[i].ItemArray[FileDecod["PackPed"]].ToString().Trim(); - string pesoPack = tabella.Rows[i].ItemArray[FileDecod["PesoPack"]].ToString().Trim(); - DateTime.TryParse(sDate, out dtRif); - int.TryParse(sNum, out numPack); - double.TryParse(sQty, out qtyTot); - string identRG = ddt.Length > 2 ? $"{strFixId(ddt)}.{strFixId(prod)}.{strFixId(variety)}.{strFixId(suppl)}" : $"{dtRif:yyyyMMdd}.{strFixId(prod)}.{strFixId(variety)}.{strFixId(suppl)}"; - string notes = $"{numPed}x{packPed}x{pesoPack}"; - // verifico di avere dati per proseguire... - bool checkIdent = !string.IsNullOrEmpty($"{prod}{variety}{suppl}"); + string prod = tabella.Rows[i].ItemArray[FileDecod["Product"]].ToString().Trim(); + // verifiche x import: header, data e DDT (vuoti o "-") --> SKIP! bool checkHeaderKo = (ddt == "DDT" || prod == "PRODOTTO"); - if (checkIdent && !checkHeaderKo) + bool checkEmptyDdt = (string.IsNullOrEmpty(ddt) || ddt == "-"); + bool checkEmptyDate = (string.IsNullOrEmpty(sDate) || sDate == "-"); + if (checkHeaderKo) { - BatchRec newRow = new BatchRec() - { - IdxODL = idxODL, - IdentRG = identRG, - DateRif = dtRif, - ExtDoc = ddt, - Product = prod, - Variety = variety, - Supplier = suppl, - NumPack = numPack, - QtyTot = qtyTot, - Notes = notes - }; - // verifico: se manca aggiungo - if (!listaGiac.ContainsKey(identRG)) - { - listaGiac.Add(identRG, newRow); - } - else - { - // altrimenti aggiorno giacenza con valori numerici - listaGiac[identRG].NumPack += newRow.NumPack; - listaGiac[identRG].QtyTot += newRow.QtyTot; - } + lgTrace($"SKIP header"); + } + else if (checkEmptyDdt || checkEmptyDate) + { + lgTrace($"SKIP linea vuota | i: {i} | ddt: {ddt} | date: {sDate} | prod: {prod}"); } else { - numErr++; + string variety = tabella.Rows[i].ItemArray[FileDecod["Variety"]].ToString().Trim(); + string suppl = tabella.Rows[i].ItemArray[FileDecod["Supplier"]].ToString().Trim(); + string sQty = tabella.Rows[i].ItemArray[FileDecod["QtyTot"]].ToString().Trim(); + string sNum = tabella.Rows[i].ItemArray[FileDecod["NumPack"]].ToString().Trim(); + string numPed = tabella.Rows[i].ItemArray[FileDecod["NumPed"]].ToString().Trim(); + string packPed = tabella.Rows[i].ItemArray[FileDecod["PackPed"]].ToString().Trim(); + string pesoPack = tabella.Rows[i].ItemArray[FileDecod["PesoPack"]].ToString().Trim(); + DateTime.TryParse(sDate, out dtRif); + int.TryParse(sNum, out numPack); + double.TryParse(sQty, out qtyTot); + string identRG = ddt.Length > 2 ? $"{strFixId(ddt)}.{strFixId(prod)}.{strFixId(variety)}.{strFixId(suppl)}" : $"{dtRif:yyyyMMdd}.{strFixId(prod)}.{strFixId(variety)}.{strFixId(suppl)}"; + string notes = $"{numPed}x{packPed}x{pesoPack}"; + // verifico di avere dati per proseguire... + bool checkIdent = !string.IsNullOrEmpty($"{prod}{variety}{suppl}"); + if (checkIdent) + { + BatchRec newRow = new BatchRec() + { + IdxODL = idxODL, + IdentRG = identRG, + DateRif = dtRif, + ExtDoc = ddt, + Product = prod, + Variety = variety, + Supplier = suppl, + NumPack = numPack, + QtyTot = qtyTot, + Notes = notes + }; + // verifico: se manca aggiungo + if (!listaGiac.ContainsKey(identRG)) + { + listaGiac.Add(identRG, newRow); + } + else + { + // altrimenti aggiorno giacenza con valori numerici + listaGiac[identRG].NumPack += newRow.NumPack; + listaGiac[identRG].QtyTot += newRow.QtyTot; + } + } + else + { + lgError($"Errore verifica identità riga | prod: {prod} | variety: {variety} | suppl: {suppl}"); + numErr++; + } } } catch (Exception exc) From 640c8275ed89d541e9d9f788245b63cbf0ab31d4 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Wed, 14 Dec 2022 10:12:34 +0100 Subject: [PATCH 2/2] Fix ModBusTcp x lettura valori inputRegisters --- IOB-WIN-NEXT/IobModbusTCP.cs | 60 +++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/IOB-WIN-NEXT/IobModbusTCP.cs b/IOB-WIN-NEXT/IobModbusTCP.cs index 7bfd8d04..9817951e 100644 --- a/IOB-WIN-NEXT/IobModbusTCP.cs +++ b/IOB-WIN-NEXT/IobModbusTCP.cs @@ -1508,16 +1508,63 @@ namespace IOB_WIN_NEXT break; case modBusAddrType.InputRegister: - listInt = readInputReg(item.Value.index, item.Value.size); - if (item.Value.tipoMem == plcDataType.String) + if (useLUT) { - // valore string... - valString = ModbusClient.ConvertRegistersToString(listInt, 0, item.Value.size); + int lutAddress = 30000 + item.Value.index + deltaBase + indexLutCorr; + // se size = 1 --> devo cambiare modo recupero + if (item.Value.size == 1) + { + //if (item.Value.index % 2 == 0) + if (lutAddress % 2 == 0) + { + //Array.Copy(HoldingRegisterLUT[lutAddress], listInt, 1); + Array.Copy(InputRegisterLUT[lutAddress], 0, listInt, 0, 1); + } + else + { + lutAddress--; + Array.Copy(InputRegisterLUT[lutAddress], 1, listInt, 0, 1); + } + } + else + { + if (InputRegisterLUT.ContainsKey(lutAddress)) + { + try + { + if (listInt.Length == 2) + { + listInt = InputRegisterLUT[lutAddress]; + } + else + { + // faccio ciclo x copiare 2 alla volta... + for (int i = 0; i < listInt.Length; i += 2) + { + Array.Copy(InputRegisterLUT[lutAddress + i], 0, listInt, i, 2); + } + } + } + catch (Exception exc) + { + lgError($"Errore in lettura da InputRegisterLUT per indirizzo {lutAddress} | item {item.Key}{Environment.NewLine}{exc}"); + } + } + } } else { - // valori numerici... - valore = convertFromReg(listInt, item.Value.size, item.Value.tipoMem); + listInt = readInputReg(item.Value.index, item.Value.size); + if (item.Value.tipoMem == plcDataType.String) + { + // valore string... + valString = ModbusClient.ConvertRegistersToString(listInt, 0, item.Value.size); + } + else + { + // valori numerici... + valore = convertFromReg(listInt, item.Value.size, item.Value.tipoMem); + } } break; @@ -1565,7 +1612,6 @@ namespace IOB_WIN_NEXT lgError($"Errore in lettura da HoldingRegisterLUT per indirizzo {lutAddress} | item {item.Key}{Environment.NewLine}{exc}"); } } - // altrimenti cerco swappando a -1... } } else