diff --git a/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs b/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs
index 0ec75d2..fad7405 100644
--- a/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs
+++ b/MTC_Adapter/MTC_Adapter/AdapterFanuc.cs
@@ -10,7 +10,9 @@ namespace MTC_Adapter
{
public class AdapterFanuc : AdapterGeneric
{
- // vettore valori in file interscambio
+ ///
+ /// vettore valori in file interscambio
+ ///
public Dictionary generalStatus;
///
/// Contenuto valori maintenance data da PLC
@@ -27,7 +29,7 @@ namespace MTC_Adapter
protected FANUC FANUC_ref;
///
- /// wrapper chiamata lettura/scrittura fanuc...
+ /// wrapper chiamata lettura/scrittura SINGOLO BYTE...
///
///
///
@@ -49,7 +51,7 @@ namespace MTC_Adapter
return answ;
}
///
- /// wrapper chiamata lettura/scrittura fanuc...
+ /// wrapper chiamata lettura/scrittura MULTI BYTE...
///
///
///
@@ -106,7 +108,9 @@ namespace MTC_Adapter
tryConnect();
lg.Info("End init Adapter FANUC");
}
-
+ ///
+ /// Override disconnessione
+ ///
public override void tryDisconnect()
{
if (connectionOk)
@@ -129,7 +133,9 @@ namespace MTC_Adapter
lg.Error("IMPOSSIBILE effettuare disconnessione: Connessione non disponibile...");
}
}
-
+ ///
+ /// Override connessione
+ ///
public override void tryConnect()
{
if (!connectionOk)
@@ -138,17 +144,22 @@ namespace MTC_Adapter
try
{
FANUC_ref.Connect(ref szStatusConnection);
- lg.Info(szStatusConnection);
+ lg.Info("szStatusConnection: " + szStatusConnection);
connectionOk = true;
// refresh stato allarmi!!!
if (connectionOk)
{
- // carico status allarmi (completo)
- lg.Info("Inizio refresh completo stato allarmi...");
-
- forceAlarmCheck();
-
- lg.Info("Completato refresh completo stato allarmi!");
+ if (adpRunning)
+ {
+ // carico status allarmi (completo)
+ lg.Info("Inizio refresh completo stato allarmi...");
+ forceAlarmCheck();
+ lg.Info("Completato refresh completo stato allarmi!");
+ }
+ else
+ {
+ lg.Info("Connessione OK");
+ }
}
else
{
@@ -165,7 +176,7 @@ namespace MTC_Adapter
}
///
- /// Verifico connessione fanuc...
+ /// Verifico connessione FANUC...
///
///
public override bool connectionOk
@@ -200,7 +211,6 @@ namespace MTC_Adapter
lg.Error("Errore connessione mancante in getStrobeAndAckStatus");
}
}
-
///
/// processing strobe!
///
@@ -208,6 +218,10 @@ namespace MTC_Adapter
{
base.processStrobe();
+ // inizializzo userAction
+ string UserAction = "";
+ string TestingData = "";
+ string UnkStrobe = "";
// !!!FARE!!! multipath...
// verifico i vari strobe x recuperare i dati... PER ORA SOLO DW1 per path1 (indice 0)...
int idxPath = 0;
@@ -216,10 +230,6 @@ namespace MTC_Adapter
inizio = DateTime.Now;
// byte di acknowledge...
byte[] retACK_DW1 = new byte[4];
- // inizializzo userAction
- string UserAction = "";
- string TestingData = "";
- string UnkStrobe = "";
try
{
// controllo TUTTI i flag: se ce ne sono di alzati DEVO processare...
@@ -370,7 +380,7 @@ namespace MTC_Adapter
memIndex = 10508;
inizio = DateTime.Now;
FanucMemRW(W, FANUC.MemType.R, memIndex, ref retACK_DW);
- if (utils.CRB("recTime")) TimingData.addResult(string.Format("W{0}-DW2", retACK_DW.Length), DateTime.Now.Subtract(inizio).Ticks);
+ if (utils.CRB("recTime")) TimingData.addResult(string.Format("W{0}-WatchDog", retACK_DW.Length), DateTime.Now.Subtract(inizio).Ticks);
}
}
}
@@ -611,7 +621,7 @@ namespace MTC_Adapter
{
try
{
- // aggiorno vettore allarmi x intero!
+ // aggiorno vettore allarmi x intero! size del vettore di destinazione (in byte!!!!)
Buffer.BlockCopy(MemBlock, 0, AlarmFlags, 0, MemBlock.Length);
}
catch (Exception exc)
@@ -684,7 +694,6 @@ namespace MTC_Adapter
}
}
}
-
///
/// processing!
///
@@ -848,7 +857,9 @@ namespace MTC_Adapter
{
base.getConfigParam();
}
-
+ ///
+ /// Recupera dati a lenta variazione
+ ///
public override void getSlowChangingData()
{
base.getSlowChangingData();
@@ -858,14 +869,12 @@ namespace MTC_Adapter
// area gestione dati utensili... in base al num max di UnOp recupero i dati utensile... PROCEDURA AD HOC!!!
getDatiUt(currAdpConf.nUnOp);
-
}
///
/// Gestione lettura dati manutenzione
///
private void getMtzDataFromPlc()
{
- bool needSave = false;
// recupero i dati di manutenzione dall'area di memoria IN BLOCCO
int memIndex = 14000;
byte[] tabDatiMtzByte = new byte[4 * maintData.Length];
@@ -879,208 +888,6 @@ namespace MTC_Adapter
processMaintData(tabDatiMtz, maintData);
// verifica se debba salvare e mostrare dati
checkSavePersDataLayer();
-
- // vecchia gestione con shift & co, ora gestito come OSAI con metodo da AdapterGeneric...
-#if false
- // uno ad uno vado a inserirli nella mappa dei dati dell'adapter...
- int shift = 4; // 32bit
- int numero = 0;
- uint valRead = 0;
- for (int i = 0; i < maintData.Length; i++)
- {
- numero = 0;
- valRead = 0;
- // 2016.07.06 uso indice i * 4 x selezionare area memoria...
- //shift = Convert.ToInt32(maintData[i].codNum) - 1;
-
- if (maintData[i].varName == "ACC_TIME")
- {
- istOreMaccOn = BitConverter.ToUInt32(tabDatiMtzByte, shift * i);
- }
- else if (maintData[i].varName == "ACC_TIME_WORK")
- {
- istOreMaccLav = BitConverter.ToUInt32(tabDatiMtzByte, shift * i);
- }
- else if (maintData[i].varName.StartsWith("Path_"))
- {
- if (maintData[i].varName.EndsWith("_PZ_TOT"))
- {
- try
- {
- numero = Convert.ToInt32(maintData[i].varName.Replace("Path_", "").Replace("_PZ_TOT", ""));
- }
- catch
- {
- }
- if (numero > 0)
- {
- vettPath[numero - 1].mPathPartCount.Value = BitConverter.ToUInt32(tabDatiMtzByte, shift * i);
- }
- }
- }
- else if (maintData[i].varName.StartsWith("Axis_"))
- {
- if (maintData[i].varName.EndsWith("_DistDone"))
- {
- try
- {
- numero = Convert.ToInt32(maintData[i].varName.Replace("Axis_", "").Replace("_DistDone", ""));
- }
- catch
- { }
- if (numero > 0)
- {
- istDistMovAssi[numero - 1] = BitConverter.ToUInt32(tabDatiMtzByte, shift * i);
- }
- }
- else if (maintData[i].varName.EndsWith("_Invers"))
- {
- try
- {
- numero = Convert.ToInt32(maintData[i].varName.Replace("Axis_", "").Replace("_Invers", ""));
- }
- catch
- { }
- if (numero > 0)
- {
- // 2016.07.06 debug di valori che potrebbero essere nulli...
- try
- {
- valRead = BitConverter.ToUInt32(tabDatiMtzByte, shift * i);
- }
- catch (Exception exc)
- {
- valRead = 0;
- lg.Error(string.Format("Errore in recupero num inversioni:{0}parametro: {1}{0}shift: {2}{0}i: {3}{0}Exc: {4}", Environment.NewLine, maintData[i].varName, shift, i, exc));
- }
- istNumInvAssi[numero - 1] = valRead;
- }
- }
- else if (maintData[i].varName.EndsWith("_AccTime"))
- {
- try
- {
- numero = Convert.ToInt32(maintData[i].varName.Replace("Axis_", "").Replace("_AccTime", ""));
- }
- catch
- { }
- if (numero > 0)
- {
- // 2016.07.06 debug di valori che potrebbero essere nulli...
- try
- {
- valRead = BitConverter.ToUInt32(tabDatiMtzByte, shift * i);
- }
- catch (Exception exc)
- {
- valRead = 0;
- lg.Error(string.Format("Errore in recupero num inversioni:{0}parametro: {1}{0}shift: {2}{0}i: {3}{0}Exc: {4}", Environment.NewLine, maintData[i].varName, shift, i, exc));
- }
- istAccTimeAssi[numero - 1] = valRead;
- }
- }
- }
- else if (maintData[i].varName.StartsWith("UnOp_"))
- {
- if (maintData[i].varName.EndsWith("_AccTime"))
- {
- try
- {
- numero = Convert.ToInt32(maintData[i].varName.Replace("UnOp_", "").Replace("_AccTime", ""));
- }
- catch
- { }
- if (numero > 0)
- {
- istGiriElettrom[numero - 1] = BitConverter.ToUInt32(tabDatiMtzByte, shift * i);
- }
- }
- else if (maintData[i].varName.EndsWith("_NumCambiUT"))
- {
- try
- {
- numero = Convert.ToInt32(maintData[i].varName.Replace("UnOp_", "").Replace("_NumCambiUT", ""));
- }
- catch
- { }
- if (numero > 0)
- {
- istNumCambiUt[numero - 1] = BitConverter.ToUInt32(tabDatiMtzByte, shift * i);
- }
- }
- }
- else if (maintData[i].varName.StartsWith("VacPump_"))
- {
- if (maintData[i].varName.EndsWith("_WrkTime"))
- {
- try
- {
- numero = Convert.ToInt32(maintData[i].varName.Replace("VacPump_", "").Replace("_WrkTime", ""));
- }
- catch
- { }
- if (numero > 0)
- {
- istVacPumpWrkTime[numero - 1] = BitConverter.ToUInt32(tabDatiMtzByte, shift * i);
- }
- }
- }
- else if (maintData[i].varName.StartsWith("VacAct_"))
- {
- if (maintData[i].varName.EndsWith("_Count"))
- {
- try
- {
- numero = Convert.ToInt32(maintData[i].varName.Replace("VacAct_", "").Replace("_Count", ""));
- }
- catch
- { }
- if (numero > 0)
- {
- istVacActCount[numero - 1] = BitConverter.ToUInt32(tabDatiMtzByte, shift * i);
- }
- }
- }
- else if (maintData[i].varName.StartsWith("Lubro_"))
- {
- if (maintData[i].varName.EndsWith("_Num"))
- {
- try
- {
- numero = Convert.ToInt32(maintData[i].varName.Replace("Lubro_", "").Replace("_Num", ""));
- }
- catch
- { }
- if (numero > 0)
- {
- istLubroCount[numero - 1] = BitConverter.ToUInt32(tabDatiMtzByte, shift * i);
- }
- }
- }
- }
-
- if (persistenceLayer != null)
- {
- // verifica se si debba aggiornare XML (e salva in adapter dati vari)
- needSave = procOreMaccOn(needSave);
- needSave = procOreMaccLav(needSave);
- needSave = procProgrName(needSave);
- needSave = procPartId(needSave);
- needSave = procPzProd(needSave);
- needSave = procGiriTotUnOp(needSave);
- needSave = procNumCU(needSave);
- needSave = procMovTotAssi(needSave);
- needSave = procAccTimeAssi(needSave);
- needSave = procNumInvAssi(needSave);
- needSave = procVacPump(needSave);
- needSave = procVacAct(needSave);
- needSave = procLubro(needSave);
-
- // salvo se necessario!
- if (needSave) parentForm.persistData();
- // -------------------------------------------
- }
-#endif
}
///
@@ -1098,90 +905,6 @@ namespace MTC_Adapter
// 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 = "";
- 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
}
///
/// Leggo dati globali comuni (x path, assi...)
@@ -1189,9 +912,17 @@ namespace MTC_Adapter
public override void getGlobalData()
{
base.getGlobalData();
+ // svuoto...
+ parentForm.dataMonitor_1 = "";
+ parentForm.dataMonitor_2 = "";
+ parentForm.dataMonitor_3 = "";
// accodo dati path in DataMonitor......
- StringBuilder sb = new StringBuilder();
+ StringBuilder sb1 = new StringBuilder();
+ StringBuilder sb2 = new StringBuilder();
+
+ // dati base...
+ sb1.AppendLine(string.Format("POWER {0}: | EmStop:{1:N3} | ProcSel: {2}", mPower.Value, mEStop.Value, mProcSel.Value));
// leggo dati globali...
inizio = DateTime.Now;
@@ -1212,15 +943,15 @@ namespace MTC_Adapter
RapidOver = PathData_mem[2];
SpeedRateOver = PathData_mem[3];
- sb.AppendLine(string.Format("FeedRate: {0} mm/min", FeedRate));
- sb.AppendLine(string.Format("FeedRateOver: {0} %", FeedRateOver));
- sb.AppendLine(string.Format("RapidOver: {0} %", RapidOver));
- sb.AppendLine(string.Format("SpeedRateOver: {0} %", SpeedRateOver));
+ sb1.AppendLine(string.Format("FeedRate: {0} mm/min", FeedRate));
+ sb1.AppendLine(string.Format("FeedRateOver: {0} %", FeedRateOver));
+ sb1.AppendLine(string.Format("RapidOver: {0} %", RapidOver));
+ sb1.AppendLine(string.Format("SpeedRateOver: {0} %", SpeedRateOver));
// se ho allarmi li accodo...
if (allDynData.alarm != 0)
{
- sb.AppendLine(string.Format("Allarmi CNC: {0}", allDynData.alarm));
+ sb1.AppendLine(string.Format("Allarmi CNC: {0}", allDynData.alarm));
inizio = DateTime.Now;
allarmiCNC = FANUC_ref.getCncAlarm();
@@ -1232,7 +963,14 @@ namespace MTC_Adapter
allarmiCNC = new CMSCncLib.Focas1.ODBALMMSG2();
}
- parentForm.dataMonitor_1 = sb.ToString();
+ // accodo dati base!
+ parentForm.dataMonitor_1 = sb1.ToString();
+ // accodo dati UT...
+ for (int i = 0; i < currAdpConf.nUnOp; i++)
+ {
+ sb2.AppendLine(string.Format("UT: ToolId {0} | VitaRes {1} | TipoVita {2} ", vettUnOp[i].mUnOpToolId.Value, vettUnOp[i].mUnOpVitaRes.Value, vettUnOp[i].mUnOpVitaResType.Value));
+ }
+ parentForm.dataMonitor_2 = sb2.ToString();
// gestisco lettura dati manutenzione da PLC...
getMtzDataFromPlc();
@@ -1305,7 +1043,6 @@ 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);
numRiga++;
}
@@ -1317,15 +1054,16 @@ namespace MTC_Adapter
if (utils.CRB("verbose")) lg.Info(string.Format("Fine caricamento vettore di {0} variabili status gestite", numRiga));
}
-
+ ///
+ /// Processing allarmi CNC
+ ///
public override void processAlarm()
{
base.processAlarm();
- // ggiungo gestione allarmi CNC
+ // aggiungo gestione allarmi CNC
checkCNCAlarms();
}
-
///
/// Verifica i 10 allarmi CNC SE presenti
///
@@ -1353,23 +1091,36 @@ namespace MTC_Adapter
// controllo valore...
if (allarme.alm_no > 0)
{
- if (utils.CRI("loglevel") > 5)
+ try
{
- lg.Info(string.Format("Allarmi CNC: NUM {0} | MESS: {1} | ASSE: {2} | TYPE: {3}", allarme.alm_no, allarme.alm_msg, allarme.axis, allarme.type));
+ StringBuilder sb = new StringBuilder();
+ if (utils.CRI("loglevel") > 5)
+ {
+ lg.Info(string.Format("Allarmi CNC: NUM {0} | MESS: {1} | ASSE: {2} | TYPE: {3}", allarme.alm_no, allarme.alm_msg, allarme.axis, allarme.type));
+ }
+ // se ho asse accodo ad asse altrimenti no...
+ string codAllarme = string.Format("T{0}-N{1}", allarme.type, allarme.alm_no);
+ if (allarme.axis == 0)
+ {
+ mAlarmCNC.Add(MTConnect.Condition.Level.FAULT, allarme.alm_msg, codAllarme, "", "");
+ }
+ else
+ {
+ vettAxis[allarme.axis - 1].mAxAlarmCNC.Add(MTConnect.Condition.Level.FAULT, allarme.alm_msg, codAllarme, "", "");
+ }
+ // mostro in form!
+ sb.AppendLine(codAllarme);
+ parentForm.dataMonitor_1 += sb.ToString();
}
- // se ho asse accodo ad asse altrimenti no...
- string codAllarme = string.Format("T{0}-N{1}", allarme.type, allarme.alm_no);
- if (allarme.axis == 0)
+ catch (Exception exc)
{
- mAlarmCNC.Add(MTConnect.Condition.Level.FAULT, allarme.alm_msg, codAllarme, "", "");
- }
- else
- {
- vettAxis[allarme.axis - 1].mAxAlarmCNC.Add(MTConnect.Condition.Level.FAULT, allarme.alm_msg, codAllarme, "", "");
+ lg.Error(string.Format("{0}", exc));
}
}
}
-
+ ///
+ /// Recupero dati x UnOp
+ ///
public override void getUnOp()
{
base.getUnOp();
@@ -1546,11 +1297,14 @@ namespace MTC_Adapter
CMSCncLib.Focas1.ODB5AXMAN vettTTCoord = FANUC_ref.getPathTTCoord();
if (utils.CRB("recTime")) TimingData.addResult("R-TTCoord", DateTime.Now.Subtract(inizio).Ticks);
- // cicl su path
+ // ciclo su path
+ StringBuilder sb_2;
+ StringBuilder sb_3;
for (int i = 0; i < currAdpConf.nPath; i++)
{
- // accodo dati path in DataMonitor......
- StringBuilder sb = new StringBuilder();
+ // accodo dati path in DataMonitor...
+ sb_2 = new StringBuilder();
+ sb_3 = new StringBuilder();
vettPath[i].mPathCodG_Act.Value = GCodAttivi;
@@ -1565,7 +1319,8 @@ namespace MTC_Adapter
vettPath[i].mPathCurrProgRowNum.Value = "";
vettPath[i].mPathActiveAxes.Value = "";
- sb.AppendLine(string.Format("Path {0}, PROG: {1}", i + 1, vettPath[i].mPathCurrProg.Value));
+ sb_2.AppendLine(string.Format("Path {0}, PROG: {1}", i + 1, vettPath[i].mPathCurrProg.Value));
+ sb_3.AppendLine(string.Format("Path {0}, GCodes: {1}", i + 1, GCodAttivi));
sb.AppendLine(string.Format("Path {0}, Asse 1: {1:N3}", i + 1, ((decimal)vettTTCoord.data1) / utils.CRI("fattdecimale")));
sb.AppendLine(string.Format("Path {0}, Asse 2: {1:N3}", i + 1, ((decimal)vettTTCoord.data2) / utils.CRI("fattdecimale")));
@@ -1573,7 +1328,8 @@ namespace MTC_Adapter
sb.AppendLine(string.Format("Path {0}, Cent 1: {1:N3}", i + 1, ((decimal)vettTTCoord.c1) / utils.CRI("fattdecimale")));
sb.AppendLine(string.Format("Path {0}, Cent 2: {1:N3}", i + 1, ((decimal)vettTTCoord.c2) / utils.CRI("fattdecimale")));
- parentForm.dataMonitor_1 += sb.ToString();
+ parentForm.dataMonitor_2 += sb_2.ToString();
+ parentForm.dataMonitor_3 += sb_3.ToString();
}
}
@@ -1782,7 +1538,6 @@ namespace MTC_Adapter
if (utils.CRB("verbose"))
{
-
sb.AppendLine(string.Format("Asse {0}: PosAct:{1:N3}, ToGo:{2:N3}{3} | {4}", valPos.abs.name, (double)(valPos.abs.data) / Math.Pow(10, valPos.abs.dec), valPos.dist.name, (double)(valPos.dist.data) / Math.Pow(10, valPos.dist.dec), direzione));
}
@@ -1803,7 +1558,7 @@ namespace MTC_Adapter
}
}
- parentForm.dataMonitor_1 += sb.ToString();
+ parentForm.dataMonitor_3 += sb.ToString();
}
}
}