diff --git a/MTC_Adapter/MTC_Adapter/AdapterESA.cs b/MTC_Adapter/MTC_Adapter/AdapterESA.cs
index 1ae26c5..002c469 100644
--- a/MTC_Adapter/MTC_Adapter/AdapterESA.cs
+++ b/MTC_Adapter/MTC_Adapter/AdapterESA.cs
@@ -160,7 +160,7 @@ namespace MTC_Adapter
// creo un vettore della dimensione corretta... conta anche commenti tanto poi riduco...
vettoreConf = new otherData[File.ReadLines(nomeFile).Count()];
// carica da file...
- System.IO.StreamReader file = new System.IO.StreamReader(nomeFile);
+ StreamReader file = new StreamReader(nomeFile);
// leggo 1 linea alla volta...
int numRiga = 0;
int bitNum = 0;
@@ -192,7 +192,7 @@ namespace MTC_Adapter
byteNum = 0;
bitNum = 0;
}
- lastData = decodeBitData(linea, utils.CRC("testCharSep"), "", byteNum, 1, bitNum);
+ lastData = decodeBitData(linea, utils.CRC("testCharSep"), byteNum, 1, bitNum);
vettoreConf[numRiga] = lastData;
}
else
diff --git a/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs b/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs
index 0578886..3067c78 100644
--- a/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs
+++ b/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs
@@ -1084,14 +1084,20 @@ namespace MTC_Adapter
{
// recupero i dati di manutenzione dall'area di memoria IN BLOCCO
int memIndex = 14512;
- int bitNum = 0;
- int byteNum = 0;
- byte byteVal;
int numByte = 1 + (statusData.Length / 8);
byte[] tabDatiStatus = new byte[numByte];
inizio = DateTime.Now;
FanucMemRW(R, FANUC.MemType.R, memIndex, ref tabDatiStatus);
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-DatiStatus", tabDatiStatus.Length), DateTime.Now.Subtract(inizio).Ticks);
+
+ // decodifico aree memoria secondo tab configurazione
+ processStatusData(tabDatiStatus, statusData);
+
+ // vecchia gestione, ora gestito come OSAI con metodo da AdapterGeneric...
+#if false
+ int bitNum = 0;
+ int byteNum = 0;
+ byte byteVal;
// uno ad uno vado a inserirli nella mappa dei dati dell'adapter...
int numero = 0;
string status = "";
@@ -1168,7 +1174,8 @@ namespace MTC_Adapter
}
}
}
- }
+ }
+#endif
}
///
/// Leggo dati globali comuni (x path, assi...)
@@ -1284,7 +1291,7 @@ namespace MTC_Adapter
// creo un vettore della dimensione corretta... conta anche commenti tanto poi riduco...
statusData = new otherData[File.ReadLines(fileName).Count()];
// carica da file...
- System.IO.StreamReader file = new System.IO.StreamReader(fileName);
+ StreamReader file = new StreamReader(fileName);
// leggo 1 linea alla volta...
int numRiga = 0;
while ((linea = file.ReadLine()) != null)
diff --git a/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs b/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs
index 540c724..81a211c 100644
--- a/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs
+++ b/MTC_Adapter/MTC_Adapter/AdapterGeneric.cs
@@ -1417,16 +1417,15 @@ namespace MTC_Adapter
return new otherData(valori[0], memAddr, valori[1].Trim(), valori[2].Trim());
}
///
- /// Decodifica file MAP
+ /// Decodifica file MAP (caso ESA/IOT)
///
///
///
- /// tipo memoria (R/D/...)
- /// indirizzo di partenza memoria
+ /// indirizzo Byte: indirizzo di partenza memoria
/// dimensione singolo slot in byte
- /// numero riga x calcolo indice bit
+ /// indirizzo bit: numero riga x calcolo indice bit
///
- protected otherData decodeBitData(string linea, char separator, string memPre, int baseAddr, int memSize, int numRiga)
+ protected otherData decodeBitData(string linea, char separator, int ByteNum, int memSize, int BitNum)
{
string[] valori = linea.Split(separator);
int shift = 0;
@@ -1437,8 +1436,33 @@ namespace MTC_Adapter
catch
{ }
int resto = 0;
- Math.DivRem(numRiga, 8, out resto);
- string memAddr = string.Format("{0}{1}.{2}", memPre, baseAddr + shift * memSize, resto);
+ Math.DivRem(BitNum, 8, out resto);
+ string memAddr = string.Format("{0}.{1}", ByteNum + shift * memSize, resto);
+ return new otherData(valori[0], memAddr, valori[1].Trim(), valori[2].Trim());
+ }
+ ///
+ /// Decodifica file MAP (caso FANUC/OSAI/...)
+ ///
+ ///
+ ///
+ /// tipo memoria (R/D/...)
+ /// indirizzo Byte: indirizzo di partenza memoria
+ /// dimensione singolo slot in byte
+ /// indirizzo bit: numero riga x calcolo indice bit
+ ///
+ protected otherData decodeBitData(string linea, char separator, string memPre, int baseAddr, int memSize, int numRiga)
+ {
+ string[] valori = linea.Split(separator);
+ int shift = 0;
+ try
+ {
+ shift = (Convert.ToInt32(valori[0]) - 1) / (8 * memSize);
+ }
+ catch
+ { }
+ int resto = 0;
+ Math.DivRem(numRiga, 8 * memSize, out resto);
+ string memAddr = string.Format("{0}{1}.{2}", memPre, baseAddr + shift, resto);
return new otherData(valori[0], memAddr, valori[1].Trim(), valori[2].Trim());
}
@@ -1634,7 +1658,7 @@ namespace MTC_Adapter
// leggo tutti i dati...
List> listaDR = currAdpConf.ProtMag[i].dataRefList;
// punto all'item
- DataRefItem riProtMag= listaDR.Find(x => x.Key == string.Format("ProtMagazzino_{0:00}_Count", i + 1));
+ DataRefItem riProtMag = listaDR.Find(x => x.Key == string.Format("ProtMagazzino_{0:00}_Count", i + 1));
// recupero valori...
currProtMag[i] = Convert.ToUInt32(riProtMag.Value);
}
@@ -2077,6 +2101,7 @@ namespace MTC_Adapter
/// Processa la tabella di memoria dei dati di manutenzione
///
///
+ ///
public void processMaintData(uint[] tabDatiMtz, otherData[] maintData)
{
// uno ad uno vado a inserirli nella mappa dei dati dell'adapter...
@@ -2319,6 +2344,94 @@ namespace MTC_Adapter
// -------------------------------------------
}
}
+ ///
+ /// Processa la tabella di memoria degli status di manutenzione
+ ///
+ ///
+ ///
+ public void processStatusData(byte[] tabDatiStatus, otherData[] statusData)
+ {
+ int bitNum = 0;
+ int byteNum = 0;
+ byte byteVal;
+ // uno ad uno vado a inserirli nella mappa dei dati dell'adapter...
+ int numero = 0;
+ string status = "";
+ for (int i = 0; i < statusData.Length; i++)
+ {
+ numero = 0;
+ status = "";
+
+ // calcolo quale byte e quale bit devo leggere..
+ byteNum = i / 8;
+ bitNum = i - (8 * byteNum); // indice zero dei bit nel byte ( da cui -1 )
+ // faccio vera lettura
+ byteVal = tabDatiStatus[byteNum];
+ // leggo bit come ACTIVE/INACTIVE
+ if (((StFlag8)byteVal).HasFlag((StFlag8)Math.Pow(2, bitNum)))
+ {
+ status = "ACTIVE";
+ }
+ else
+ {
+ status = "INACTIVE";
+ }
+
+ if (statusData[i].varName == "PROTECTION_STATUS")
+ {
+ mProtectionStatus.Value = status;
+ }
+ else if (statusData[i].varName.StartsWith("VacPump_"))
+ {
+ if (statusData[i].varName.EndsWith("_Status"))
+ {
+ try
+ {
+ numero = Convert.ToInt32(statusData[i].varName.Replace("VacPump_", "").Replace("_Status", ""));
+ }
+ catch
+ {
+ }
+ if (numero > 0)
+ {
+ vettVacPump[numero - 1].mVacPumpStatus.Value = status;
+ }
+ }
+ }
+ else if (statusData[i].varName.StartsWith("Cooler_"))
+ {
+ if (statusData[i].varName.EndsWith("_Status"))
+ {
+ try
+ {
+ numero = Convert.ToInt32(statusData[i].varName.Replace("Cooler_", "").Replace("_Status", ""));
+ }
+ catch
+ { }
+ if (numero > 0)
+ {
+ vettCooler[numero - 1].mCoolStatus.Value = status;
+ }
+ }
+ }
+ else if (statusData[i].varName.StartsWith("UnOp_"))
+ {
+ if (statusData[i].varName.EndsWith("_Status"))
+ {
+ try
+ {
+ numero = Convert.ToInt32(statusData[i].varName.Replace("UnOp_", "").Replace("_Status", ""));
+ }
+ catch
+ { }
+ if (numero > 0)
+ {
+ vettUnOp[numero - 1].mUnOpStatus.Value = status;
+ }
+ }
+ }
+ }
+ }
#endregion
diff --git a/MTC_Adapter/MTC_Adapter/AdapterOsai.cs b/MTC_Adapter/MTC_Adapter/AdapterOsai.cs
index e44c936..54b3255 100644
--- a/MTC_Adapter/MTC_Adapter/AdapterOsai.cs
+++ b/MTC_Adapter/MTC_Adapter/AdapterOsai.cs
@@ -1126,94 +1126,15 @@ namespace MTC_Adapter
private void getStatusDataFromPlc()
{
// recupero i dati di manutenzione dall'area di memoria IN BLOCCO
-#if false
- int memIndex = 14512;
- int bitNum = 0;
- int byteNum = 0;
- byte byteVal;
+ int memIndex = 19426;
int numByte = 1 + (statusData.Length / 8);
byte[] tabDatiStatus = new byte[numByte];
inizio = DateTime.Now;
- OsaiMemRW(R, FANUC.MemType.R, memIndex, ref tabDatiStatus);
+ OsaiMemRW_Byte(R, OSAI.MemTypeWord.MW_CODE, memIndex, 0, ref tabDatiStatus);
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-DatiStatus", tabDatiStatus.Length), DateTime.Now.Subtract(inizio).Ticks);
- // uno ad uno vado a inserirli nella mappa dei dati dell'adapter...
- int numero = 0;
- string status = "";
- for (int i = 0; i < statusData.Length; i++)
- {
- numero = 0;
- status = "";
- // calcolo quale byte e quale bit devo leggere..
- byteNum = i / 8;
- bitNum = i - (8 * byteNum); // indice zero dei bit nel byte ( da cui -1 )
- // faccio vera lettura
- byteVal = tabDatiStatus[byteNum];
- // leggo bit come ACTIVE/INACTIVE
- if (((StFlag8)byteVal).HasFlag((StFlag8)Math.Pow(2, bitNum)))
- {
- status = "ACTIVE";
- }
- else
- {
- status = "INACTIVE";
- }
-
- if (statusData[i].varName == "PROTECTION_STATUS")
- {
- mProtectionStatus.Value = status;
- }
- else if (statusData[i].varName.StartsWith("VacPump_"))
- {
- if (statusData[i].varName.EndsWith("_Status"))
- {
- try
- {
- numero = Convert.ToInt32(statusData[i].varName.Replace("VacPump_", "").Replace("_Status", ""));
- }
- catch
- {
- }
- if (numero > 0)
- {
- vettVacPump[numero - 1].mVacPumpStatus.Value = status;
- }
- }
- }
- else if (statusData[i].varName.StartsWith("Cooler_"))
- {
- if (statusData[i].varName.EndsWith("_Status"))
- {
- try
- {
- numero = Convert.ToInt32(statusData[i].varName.Replace("Cooler_", "").Replace("_Status", ""));
- }
- catch
- { }
- if (numero > 0)
- {
- vettCooler[numero - 1].mCoolStatus.Value = status;
- }
- }
- }
- else if (statusData[i].varName.StartsWith("UnOp_"))
- {
- if (statusData[i].varName.EndsWith("_Status"))
- {
- try
- {
- numero = Convert.ToInt32(statusData[i].varName.Replace("UnOp_", "").Replace("_Status", ""));
- }
- catch
- { }
- if (numero > 0)
- {
- vettUnOp[numero - 1].mUnOpStatus.Value = status;
- }
- }
- }
- }
-#endif
+ // decodifico aree memoria secondo tab configurazione
+ processStatusData(tabDatiStatus, statusData);
}
///
/// Leggo dati globali comuni (x path, assi...)
@@ -1361,8 +1282,6 @@ namespace MTC_Adapter
///
private void loadStatusData()
{
- // problema blocco file dati persistenti che diventa binario/illeggibile: cambiare metodo accesso file? using{}?!?
-#if false
// carico dati x Maintenance
if (utils.CRB("verbose")) lg.Info("Inizio caricamento vettore variabili status gestite");
int totRighe = 0;
@@ -1372,7 +1291,7 @@ namespace MTC_Adapter
// creo un vettore della dimensione corretta... conta anche commenti tanto poi riduco...
statusData = new otherData[File.ReadLines(fileName).Count()];
// carica da file...
- System.IO.StreamReader file = new System.IO.StreamReader(fileName);
+ StreamReader file = new StreamReader(fileName);
// leggo 1 linea alla volta...
int numRiga = 0;
while ((linea = file.ReadLine()) != null)
@@ -1380,8 +1299,7 @@ namespace MTC_Adapter
// SE non รจ un commento...
if (linea.Substring(0, 1) != "#")
{
- //elencoAllarmi[rumRiga] = decodeAlarmLine(linea, ':');
- statusData[numRiga] = decodeBitData(linea, utils.CRC("testCharSep"), "R", 14512, 1, numRiga);
+ statusData[numRiga] = decodeBitData(linea, utils.CRC("testCharSep"), "ML", 19426, 2, numRiga);
numRiga++;
}
}
@@ -1390,8 +1308,7 @@ namespace MTC_Adapter
// ora trimmo vettore al solo numero VERO dei valori caricati...
Array.Resize(ref statusData, numRiga);
- if (utils.CRB("verbose")) lg.Info(string.Format("Fine caricamento vettore di {0} variabili status gestite", numRiga));
-#endif
+ if (utils.CRB("verbose")) lg.Info(string.Format("Fine caricamento vettore di {0} variabili status gestite", numRiga));
}
public override void processAlarm()