diff --git a/MTC_Adapter/MTC_Adapter/AdapterSiemens.cs b/MTC_Adapter/MTC_Adapter/AdapterSiemens.cs
index d2e0bf5..679e3ec 100644
--- a/MTC_Adapter/MTC_Adapter/AdapterSiemens.cs
+++ b/MTC_Adapter/MTC_Adapter/AdapterSiemens.cs
@@ -16,7 +16,7 @@ namespace MTC_Adapter
protected FANUC FANUC_ref;
///
- /// wrapper chiamata lettura/scrittura fanuc...
+ /// wrapper chiamata lettura/scrittura SINGOLO BYTE...
///
///
///
@@ -38,7 +38,7 @@ namespace MTC_Adapter
return answ;
}
///
- /// wrapper chiamata lettura/scrittura fanuc...
+ /// wrapper chiamata lettura/scrittura MULTI BYTE...
///
///
///
@@ -77,7 +77,7 @@ namespace MTC_Adapter
///
public AdapterSiemens(MainForm caller, AdapterConf adpConf) : base(caller, adpConf)
{
- lg.Info("Start init Adapter SIEMENS all'IP {0}", utils.CRS("ipPLC"));
+ lg.Info("Start init Adapter FANUC all'IP {0}", utils.CRS("ipPLC"));
Runtime.CreateNC(CNC.NcType.FANUC, utils.CRS("ipPLC"));
@@ -89,13 +89,15 @@ namespace MTC_Adapter
if (utils.CRB("verbose")) lg.Info("FANUC_ref da CMSCncLib");
// disconnetto e connetto...
- if (utils.CRB("verbose")) lg.Info("SIEMENS: tryDisconnect");
+ if (utils.CRB("verbose")) lg.Info("FANUC: tryDisconnect");
tryDisconnect();
- lg.Info("SIEMENS: tryConnect");
+ lg.Info("FANUC: tryConnect");
tryConnect();
- lg.Info("End init Adapter SIEMENS");
+ lg.Info("End init Adapter FANUC");
}
-
+ ///
+ /// Override disconnessione
+ ///
public override void tryDisconnect()
{
if (connectionOk)
@@ -106,11 +108,11 @@ namespace MTC_Adapter
FANUC_ref.Disconnect(ref szStatusConnection);
connectionOk = false;
lg.Info(szStatusConnection);
- lg.Info("Effettuata disconnessione adapter SIEMENS!");
+ lg.Info("Effettuata disconnessione adapter FANUC!");
}
catch (Exception exc)
{
- lg.Fatal(exc, "Errore nella disconnessione dall'adapter SIEMENS");
+ lg.Fatal(exc, "Errore nella disconnessione dall'adapter FANUC");
}
}
else
@@ -118,7 +120,9 @@ namespace MTC_Adapter
lg.Error("IMPOSSIBILE effettuare disconnessione: Connessione non disponibile...");
}
}
-
+ ///
+ /// Override connessione
+ ///
public override void tryConnect()
{
if (!connectionOk)
@@ -127,17 +131,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
{
@@ -146,7 +155,7 @@ namespace MTC_Adapter
}
catch (Exception exc)
{
- lg.Fatal(exc, "Errore nella connessione all'adapter SIEMENS", szStatusConnection);
+ lg.Fatal(string.Format("Errore nella connessione all'adapter FANUC: {0}{1}{2}", szStatusConnection, Environment.NewLine, exc));
connectionOk = false;
lg.Info(string.Format("Segnalo Adapter NON running, pausa di {0} msec prima di ulteriori tentativi di riconnessione", utils.CRI("waitRecMSec")));
}
@@ -154,7 +163,7 @@ namespace MTC_Adapter
}
///
- /// Verifico connessione fanuc...
+ /// Verifico connessione FANUC...
///
///
public override bool connectionOk
@@ -189,7 +198,6 @@ namespace MTC_Adapter
lg.Error("Errore connessione mancante in getStrobeAndAckStatus");
}
}
-
///
/// processing strobe!
///
@@ -197,6 +205,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;
@@ -205,93 +217,104 @@ namespace MTC_Adapter
inizio = DateTime.Now;
// byte di acknowledge...
byte[] retACK_DW1 = new byte[4];
- byte[] retACK_DW2 = new byte[4];
- // inizializzo userAction
- string UserAction = "";
- string TestingData = "";
- string UnkStrobe = "";
- // controllo TUTTI i flag: se ce ne sono di alzati DEVO processare...
- if (STRB_DW1 != StFlag32.NONE)
+ try
{
- // blocco memoria x lettura TUTTI i dati di buffer M/S/T: 46 byte: 2byte (16bit) x (11+6+6) aree
- byte[] MemBlock = new byte[46];
-
- // leggo tutto!!!
- memIndex = 10660;
- inizio = DateTime.Now;
- FanucMemRW(R, FANUC.MemType.R, memIndex, ref MemBlock);
- if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-STRB_DW1", MemBlock.Length), DateTime.Now.Subtract(inizio).Ticks);
-
- // check COD_M
- bitNum = 0;
- gestStrobeCodMST(bitNum, ref retACK_DW1, 0, MemBlock, "M");
-
- // check COD_S
- bitNum = 1;
- gestStrobeCodMST(bitNum, ref retACK_DW1, 11, MemBlock, "S");
-
- // check COD_T
- bitNum = 2;
- gestStrobeCodMST(bitNum, ref retACK_DW1, 17, MemBlock, "T");
-
- // check FILE DATI MODIFICATO: ricaricare...
- bitNum = 3;
- if (STRB_DW1.HasFlag((StFlag32)Math.Pow(2, bitNum)))
+ // controllo TUTTI i flag: se ce ne sono di alzati DEVO processare...
+ if (STRB_DW1 != StFlag32.NONE)
{
- // reload dati da file...
- reloadDataFromFile();
+ // blocco memoria x lettura TUTTI i dati di buffer M/S/T: 46 byte: 2byte (16bit) x (11+6+6) aree
+ byte[] MemBlock = new byte[46];
- // memorizzo allarme nel vettore ack....
- retACK_DW1 = utils.setBitOnStFlag(retACK_DW1, true, bitNum);
+ // leggo tutto!!!
+ memIndex = 10660;
+ inizio = DateTime.Now;
+ FanucMemRW(R, FANUC.MemType.R, memIndex, ref MemBlock);
+ if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-STRB_DW1", MemBlock.Length), DateTime.Now.Subtract(inizio).Ticks);
+
+ // check COD_M
+ bitNum = 0;
+ gestStrobeCodMST(bitNum, ref retACK_DW1, 0, MemBlock, "M");
+
+ // check COD_S
+ bitNum = 1;
+ gestStrobeCodMST(bitNum, ref retACK_DW1, 11, MemBlock, "S");
+
+ // check COD_T
+ bitNum = 2;
+ gestStrobeCodMST(bitNum, ref retACK_DW1, 17, MemBlock, "T");
+
+
+ // check FILE DATI MODIFICATO: ricaricare...
+ bitNum = 3;
+ if (STRB_DW1.HasFlag((StFlag32)Math.Pow(2, bitNum)))
+ {
+ lg.Info("Notifica file modificato");
+ try
+ {
+ // reload dati da file...
+ reloadDataFromFile();
+
+ // memorizzo allarme nel vettore ack....
+ retACK_DW1 = utils.setBitOnStFlag(retACK_DW1, true, bitNum);
+ }
+ catch
+ {
+ lg.Info("Errore lettura dati da file");
+ }
+ }
+
+ // AREA strobe USER ACTION
+ // chiamato Start...
+ bitNum = 4;
+ gestStrobeUserAction(bitNum, ref retACK_DW1, ref UserAction, " (START) ");
+ // chiamato Stop...
+ bitNum = 5;
+ gestStrobeUserAction(bitNum, ref retACK_DW1, ref UserAction, " (STOP) ");
+ // chiamato Reset...
+ bitNum = 6;
+ gestStrobeUserAction(bitNum, ref retACK_DW1, ref UserAction, " (RESET) ");
+
+ // processo tutti gli strobe x i BIT 7-29 NON gestiti in modo da dare comunque ACK e event...
+ for (int i = 7; i < 30; i++)
+ {
+ gestStrobeUserAction(i, ref retACK_DW1, ref UnkStrobe, string.Format(" [STROBE_{0:00}] ", i));
+ }
+
+ // AREA strobe x TEST
+ // INIZIO TEST...
+ bitNum = 30;
+ if (STRB_DW1.HasFlag((StFlag32)Math.Pow(2, bitNum)))
+ {
+ // formatto stringa risultato
+ TestingData = string.Format("START TEST{0}", getTestData(utils.CRS("testCharSep")));
+
+ // memorizzo allarme nel vettore ack....
+ retACK_DW1 = utils.setBitOnStFlag(retACK_DW1, true, bitNum);
+ }
+ // FINE TEST...
+ bitNum = 31;
+ if (STRB_DW1.HasFlag((StFlag32)Math.Pow(2, bitNum)))
+ {
+ // formatto stringa risultato
+ TestingData = string.Format("STOP TEST{0}", getTestData(utils.CRS("testCharSep")));
+
+ // memorizzo allarme nel vettore ack....
+ retACK_DW1 = utils.setBitOnStFlag(retACK_DW1, true, bitNum);
+ }
}
-
- // AREA strobe USER ACTION
- // chiamato Start...
- bitNum = 4;
- gestStrobeUserAction(bitNum, ref retACK_DW1, ref UserAction, " (START) ");
- // chiamato Stop...
- bitNum = 5;
- gestStrobeUserAction(bitNum, ref retACK_DW1, ref UserAction, " (STOP) ");
- // chiamato Reset...
- bitNum = 6;
- gestStrobeUserAction(bitNum, ref retACK_DW1, ref UserAction, " (RESET) ");
-
- // processo tutti gli strobe x i BIT 7-29 NON gestiti in modo da dare comunque ACK e event...
- for (int i = 7; i < 30; i++)
+ else
{
- gestStrobeUserAction(i, ref retACK_DW1, ref UnkStrobe, string.Format(" [STROBE_{0:00}] ", i));
- }
-
- // AREA strobe x TEST
- // INIZIO TEST...
- bitNum = 30;
- if (STRB_DW1.HasFlag((StFlag32)Math.Pow(2, bitNum)))
- {
- // formatto stringa risultato
- TestingData = string.Format("START TEST{0}", getTestData(utils.CRS("testCharSep")));
-
- // memorizzo allarme nel vettore ack....
- retACK_DW1 = utils.setBitOnStFlag(retACK_DW1, true, bitNum);
- }
- // FINE TEST...
- bitNum = 31;
- if (STRB_DW1.HasFlag((StFlag32)Math.Pow(2, bitNum)))
- {
- // formatto stringa risultato
- TestingData = string.Format("STOP TEST{0}", getTestData(utils.CRS("testCharSep")));
-
- // memorizzo allarme nel vettore ack....
- retACK_DW1 = utils.setBitOnStFlag(retACK_DW1, true, bitNum);
+ // se mi sono rimasti degli strobe di lettura allarmi alzati li abbasso
+ if (ACK_DW1 != StFlag32.NONE)
+ {
+ // inizializzo 4 byte a zero!!!
+ retACK_DW1 = new byte[4];
+ }
}
}
- else
+ catch
{
- // se mi sono rimasti degli strobe di lettura allarmi alzati li abbasso
- if (ACK_DW1 != StFlag32.NONE)
- {
- // inizializzo 4 byte a zero!!!
- retACK_DW1 = new byte[4];
- }
+ lg.Info("Errore in strobe");
}
// 2017.01.16 INVIO vettore azioni (1 o +)... SE CE NE SONO!
@@ -302,7 +325,10 @@ namespace MTC_Adapter
}
// Invio comunque strobe non riconosciuti
- mUnkStrobe.Value = UnkStrobe.Trim();
+ if (mUnkStrobe.Value.ToString() != UnkStrobe.Trim())
+ {
+ mUnkStrobe.Value = UnkStrobe.Trim();
+ }
// INVIO COMUNQUE stato test...
mTestingData.Value = TestingData.Trim();
@@ -316,20 +342,36 @@ namespace MTC_Adapter
if (utils.CRB("recTime")) TimingData.addResult(string.Format("W{0}-DW1", retACK_DW1.Length), DateTime.Now.Subtract(inizio).Ticks);
}
+ sendWatchDog();
+ }
+ ///
+ /// Invia (se necessario) il watchdog di stato in vita... blink 0/1 ogni secondo
+ ///
+ private void sendWatchDog()
+ {
+ int memIndex = 0;
+ bool setFlag = false;
+ byte[] retACK_DW = new byte[4];
// 2016.10.18 aggiungo scrittura del bit di "watchdog" al primo bit della DW2... come resto tra secondi / 2
if (utils.CRB("sendWatchDog"))
{
int resto = 0;
Math.DivRem(DateTime.Now.Second, 2, out resto);
- bool setFlag = resto == 0;
- retACK_DW2 = utils.setBitOnStFlag(retACK_DW2, setFlag, 0); // imposto primo bit!!!
- // scrivo su area PLC
- memIndex = 10508;
- inizio = DateTime.Now;
- FanucMemRW(W, FANUC.MemType.R, memIndex, ref retACK_DW2);
- if (utils.CRB("recTime")) TimingData.addResult(string.Format("W{0}-DW2", retACK_DW2.Length), DateTime.Now.Subtract(inizio).Ticks);
+ setFlag = resto == 0;
+ // se watchdog è cambiato lo invio, altrimenti lascio come è...
+ if (setFlag != lastWatchDog)
+ {
+ lastWatchDog = setFlag;
+ retACK_DW = utils.setBitOnStFlag(retACK_DW, setFlag, 0); // imposto primo bit!!!
+ // scrivo su area PLC
+ memIndex = 10508;
+ inizio = DateTime.Now;
+ FanucMemRW(W, FANUC.MemType.R, memIndex, ref retACK_DW);
+ if (utils.CRB("recTime")) TimingData.addResult(string.Format("W{0}-WatchDog", retACK_DW.Length), DateTime.Now.Subtract(inizio).Ticks);
+ }
}
}
+
///
/// Recupero info su test: numero + elenco parametri IN/OUT
///
@@ -414,25 +456,35 @@ namespace MTC_Adapter
// da rivedere: se sono N+1 file (N=path + generale) deve essere ad esempio nomeComune_*.mtc --> ciclo per leggerne N
string fileName = string.Format(@"{0}\{1}", utils.dataDir, utils.CRS("GeneralStatusFilePath"));
string linea;
- totRighe = File.ReadLines(fileName).Count();
// creo un vettore della dimensione corretta... conta anche commenti tanto poi riduco...
generalStatus = new Dictionary();
- // carica da file...
- System.IO.StreamReader file = new System.IO.StreamReader(fileName);
- // leggo 1 linea alla volta...
- string[] valori;
- while ((linea = file.ReadLine()) != null)
+ try
{
- // SE non è un commento...
- if (linea.Substring(0, 1) != "#")
+ totRighe = File.ReadLines(fileName).Count();
+ // carica da file...
+ System.IO.StreamReader file = new System.IO.StreamReader(fileName);
+ if (file != null)
{
- valori = linea.Split(utils.CRC("testCharSep"));
- generalStatus.Add(valori[0], valori[1]);
+ // leggo 1 linea alla volta...
+ string[] valori;
+ while ((linea = file.ReadLine()) != null)
+ {
+ // SE non è un commento...
+ if (linea.Substring(0, 1) != "#")
+ {
+ valori = linea.Split(utils.CRC("testCharSep"));
+ generalStatus.Add(valori[0], valori[1]);
+ }
+ }
+ // chiudo file
+ file.Close();
+ if (utils.CRB("verbose")) lg.Info("Fine lettura dati da file");
}
}
- // chiudo file
- file.Close();
- if (utils.CRB("verbose")) lg.Info("Fine lettura dati da file");
+ catch
+ {
+ lg.Info("Errore in lettura dati da file");
+ }
// ora salvo valori letti...
@@ -553,15 +605,17 @@ namespace MTC_Adapter
inizio = DateTime.Now;
FanucMemRW(R, FANUC.MemType.R, memIndex, ref MemBlock);
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-STRB_DW0", MemBlock.Length), DateTime.Now.Subtract(inizio).Ticks);
-
- try
+ if (AlarmFlags != null)
{
- // aggiorno vettore allarmi x intero!
- Buffer.BlockCopy(MemBlock, 0, AlarmFlags, 0, MemBlock.Length);
- }
- catch (Exception exc)
- {
- lg.Error(string.Format("Errore in BLOCKCOPY{0}{1}", Environment.NewLine, exc));
+ try
+ {
+ // aggiorno vettore allarmi x intero! size del vettore di destinazione (in byte!!!!)
+ Buffer.BlockCopy(MemBlock, 0, AlarmFlags, 0, MemBlock.Length);
+ }
+ catch (Exception exc)
+ {
+ lg.Error(string.Format("Errore in BLOCKCOPY{0}{1}", Environment.NewLine, exc));
+ }
}
}
else
@@ -592,7 +646,7 @@ namespace MTC_Adapter
}
else
{
- Buffer.BlockCopy(MemBlock, 0, AlarmFlags, 0, AlarmFlags.Length);
+ Buffer.BlockCopy(MemBlock, 0, AlarmFlags, i, MemBlock.Length);
}
// segnalo allarme letto! memorizzo allarme nel vettore ack....
@@ -628,7 +682,6 @@ namespace MTC_Adapter
}
}
}
-
///
/// processing!
///
@@ -646,69 +699,36 @@ namespace MTC_Adapter
mEStop.Value = "ARMED";
}
- // HARD CODE: forzo path 1 (indice 0...)
- int idxPath = 0;
- // switch su run mode...
+ // verifico POWER ON...
if (STRB_DW2.HasFlag(StFlag32.B01))
{
- vettPath[idxPath].mPathRunMode.Value = "AUTOMATIC";
+ mPower.Value = "ON";
}
- else if (STRB_DW2.HasFlag(StFlag32.B02))
+ else
{
- vettPath[idxPath].mPathRunMode.Value = "EDIT";
- }
- else if (STRB_DW2.HasFlag(StFlag32.B03))
- {
- vettPath[idxPath].mPathRunMode.Value = "MANUAL_DATA_INPUT";
- }
- else if (STRB_DW2.HasFlag(StFlag32.B04))
- {
- vettPath[idxPath].mPathRunMode.Value = "MANUAL";
- }
- else if (STRB_DW2.HasFlag(StFlag32.B05))
- {
- vettPath[idxPath].mPathRunMode.Value = "MANUAL"; // "JOG";
- }
- else if (STRB_DW2.HasFlag(StFlag32.B06))
- {
- vettPath[idxPath].mPathRunMode.Value = "MANUAL"; //"JOGINC";
- }
- else if (STRB_DW2.HasFlag(StFlag32.B07))
- {
- vettPath[idxPath].mPathRunMode.Value = "MANUAL"; //"HANDLE";
+ mPower.Value = "OFF";
}
- // switch su EXE mode...
- string exeMode = "";
- if (STRB_DW2.HasFlag(StFlag32.B08))
+ // Processo selezionato 0=P1, 1=P2
+ string procSel = "";
+ if (STRB_DW2.HasFlag(StFlag32.B02))
{
- exeMode = "ACTIVE";
+ procSel = "P2";
}
- else if (STRB_DW2.HasFlag(StFlag32.B09))
+ else
{
- exeMode = "READY";
+ procSel = "P1";
}
- else if (STRB_DW2.HasFlag(StFlag32.B10))
+ if (mProcSel.Value.ToString() != procSel)
{
- exeMode = "STOPPED"; // "HOLD";
- }
- else if (STRB_DW2.HasFlag(StFlag32.B11))
- {
- exeMode = "FEED_HOLD"; // "FEEDHOLD";
- }
- //// appunto: modi da creare
- //INTERRUPTED(da creare)
- //OPTIONAL_STOP(da creare)
- //PROGRAM_STOPPED(da creare)
- //PROGRAM_COMPLETED(da creare)
-
- if (vettPath[idxPath].mPathExeMode.Value.ToString() != exeMode)
- {
- vettPath[idxPath].mPathExeMode.Value = exeMode;
+ mProcSel.Value = procSel;
}
- // verifico tipo path...
- if (STRB_DW2.HasFlag(StFlag32.B12))
+ // HARD CODE: forzo path 1 (indice 0...)
+ int idxPath = 0;
+
+ // verifico tipo processo path...
+ if (STRB_DW2.HasFlag(StFlag32.B03))
{
vettPath[idxPath].mPathType.Value = "LAVORO";
}
@@ -717,15 +737,71 @@ namespace MTC_Adapter
vettPath[idxPath].mPathType.Value = "ASSERV";
}
- // verifico POWER ON...
- if (STRB_DW2.HasFlag(StFlag32.B13))
+ // switch su RUN mode...
+ string runMode = "";
+ if (STRB_DW2.HasFlag(StFlag32.B04))
{
- mPower.Value = "ON";
+ runMode = "AUTOMATIC";
}
- else
+ else if (STRB_DW2.HasFlag(StFlag32.B05))
{
- mPower.Value = "OFF";
+ runMode = "EDIT";
}
+ else if (STRB_DW2.HasFlag(StFlag32.B06))
+ {
+ runMode = "MANUAL_DATA_INPUT";
+ }
+ else if (STRB_DW2.HasFlag(StFlag32.B07))
+ {
+ runMode = "MANUAL";
+ }
+ else if (STRB_DW2.HasFlag(StFlag32.B08))
+ {
+ runMode = "SEMI_AUTO";
+ }
+ // salvo valore selezionato
+ if (vettPath[idxPath].mPathRunMode.Value.ToString() != runMode)
+ {
+ vettPath[idxPath].mPathRunMode.Value = runMode;
+ }
+
+ // switch su EXE mode...
+ string exeMode = "";
+ if (STRB_DW2.HasFlag(StFlag32.B09))
+ {
+ exeMode = "ACTIVE";
+ }
+ else if (STRB_DW2.HasFlag(StFlag32.B10))
+ {
+ exeMode = "READY";
+ }
+ else if (STRB_DW2.HasFlag(StFlag32.B11))
+ {
+ exeMode = "STOPPED";
+ }
+ else if (STRB_DW2.HasFlag(StFlag32.B12))
+ {
+ exeMode = "FEED_HOLD";
+ }
+ else if (STRB_DW2.HasFlag(StFlag32.B13))
+ {
+ exeMode = "OPTIONAL_STOP";
+ }
+ else if (STRB_DW2.HasFlag(StFlag32.B14))
+ {
+ exeMode = "PROGRAM_STOPPED";
+ }
+ else if (STRB_DW2.HasFlag(StFlag32.B15))
+ {
+ exeMode = "PROGRAM_COMPLETED";
+ }
+ // salvo valore selezionato
+ if (vettPath[idxPath].mPathExeMode.Value.ToString() != exeMode)
+ {
+ vettPath[idxPath].mPathExeMode.Value = exeMode;
+ }
+
+
// processo eventuali altri bit status non noti...
string UnkStatus = "";
@@ -769,7 +845,9 @@ namespace MTC_Adapter
{
base.getConfigParam();
}
-
+ ///
+ /// Recupera dati a lenta variazione
+ ///
public override void getSlowChangingData()
{
base.getSlowChangingData();
@@ -778,217 +856,43 @@ namespace MTC_Adapter
reloadDataFromFile();
// area gestione dati utensili... in base al num max di UnOp recupero i dati utensile... PROCEDURA AD HOC!!!
- getDatiUt_Fanuc(currAdpConf.nUnOp);
-
+ 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[] tabDatiMtz = new byte[4 * maintData.Length];
+ byte[] tabDatiMtzByte = new byte[4 * maintData.Length];
+ uint[] tabDatiMtz = new uint[maintData.Length];
inizio = DateTime.Now;
- FanucMemRW(R, FANUC.MemType.R, memIndex, ref tabDatiMtz);
- if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-DatiMtz", tabDatiMtz.Length), DateTime.Now.Subtract(inizio).Ticks);
- // 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(tabDatiMtz, shift * i);
- }
- else if (maintData[i].varName == "ACC_TIME_WORK")
- {
- istOreMaccLav = BitConverter.ToUInt32(tabDatiMtz, 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(tabDatiMtz, 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(tabDatiMtz, 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(tabDatiMtz, 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(tabDatiMtz, 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(tabDatiMtz, 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(tabDatiMtz, 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(tabDatiMtz, 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(tabDatiMtz, 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(tabDatiMtz, shift * i);
- }
- }
- }
- }
-
- // 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();
- // -------------------------------------------
-
+ FanucMemRW(R, FANUC.MemType.R, memIndex, ref tabDatiMtzByte);
+ if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-DatiMtz", tabDatiMtzByte.Length), DateTime.Now.Subtract(inizio).Ticks);
+ // copio byte --> word!
+ Buffer.BlockCopy(tabDatiMtzByte, 0, tabDatiMtz, 0, tabDatiMtzByte.Length);
+ // decodifico aree memoria secondo tab configurazione
+ processMaintData(tabDatiMtz, maintData);
+ // verifica se debba salvare e mostrare dati
+ checkSavePersDataLayer();
+ }
+ ///
+ /// Gestione lettura dati analogici
+ ///
+ private void getAnalogDataFromPlc()
+ {
+ // recupero i dati di manutenzione dall'area di memoria IN BLOCCO
+ int memIndex = 15000;
+ byte[] tabDatiAnalogByte = new byte[4 * analogData.Length];
+ uint[] tabDatiAnalog = new uint[analogData.Length];
+ inizio = DateTime.Now;
+ FanucMemRW(R, FANUC.MemType.R, memIndex, ref tabDatiAnalogByte);
+ if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-DatiAnalog", tabDatiAnalogByte.Length * 4), DateTime.Now.Subtract(inizio).Ticks);
+ // copio byte --> word!
+ Buffer.BlockCopy(tabDatiAnalogByte, 0, tabDatiAnalog, 0, tabDatiAnalogByte.Length);
+ // decodifico aree memoria secondo tab configurazione
+ processAnalogData(tabDatiAnalog, analogData);
}
///
@@ -998,91 +902,14 @@ 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);
- // 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;
- }
- }
- }
- }
+ // decodifico aree memoria secondo tab configurazione
+ processStatusData(tabDatiStatus, statusData);
}
///
/// Leggo dati globali comuni (x path, assi...)
@@ -1090,9 +917,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;
@@ -1113,15 +948,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();
@@ -1133,11 +968,19 @@ 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();
-
+ // gestisco lettura dati analogici da PLC...
+ getAnalogDataFromPlc();
// gestisco lettura dati status da PLC...
getStatusDataFromPlc();
}
@@ -1147,86 +990,19 @@ namespace MTC_Adapter
protected override void loadOtherFile()
{
base.loadOtherFile();
- loadMaintData();
- loadStatusData();
+ loadMaintData("R", 14000, 4);
+ loadStatusData("R", 14512, 1);
}
///
- /// Lettura file gestione dati manutenzione da PLC
+ /// Processing allarmi CNC
///
- private void loadMaintData()
- {
- // carico dati x Maintenance
- if (utils.CRB("verbose")) lg.Info("Inizio caricamento vettore variabili manutenzione gestite");
- int totRighe = 0;
- string fileName = string.Format(@"{0}\{1}", utils.confDir, utils.CRS("CounterListFilePath"));
- string linea;
- totRighe = File.ReadLines(fileName).Count();
- // creo un vettore della dimensione corretta... conta anche commenti tanto poi riduco...
- maintData = new otherData[File.ReadLines(fileName).Count()];
- // carica da file...
- System.IO.StreamReader file = new System.IO.StreamReader(fileName);
- // leggo 1 linea alla volta...
- int numRiga = 0;
- while ((linea = file.ReadLine()) != null)
- {
- // SE non è un commento...
- if (linea.Substring(0, 1) != "#")
- {
- //elencoAllarmi[rumRiga] = decodeAlarmLine(linea, ':');
- maintData[numRiga] = decodeOtherData(linea, utils.CRC("testCharSep"), "R", 14000, 4);
- numRiga++;
- }
- }
- // chiudo file
- file.Close();
- // ora trimmo vettore al solo numero VERO dei valori caricati...
- Array.Resize(ref maintData, numRiga);
-
- if (utils.CRB("verbose")) lg.Info(string.Format("Fine caricamento vettore di {0} variabili manutenzione gestite", numRiga));
- }
- ///
- /// Lettura file gestione dati status da PLC
- ///
- private void loadStatusData()
- {
- // carico dati x Maintenance
- if (utils.CRB("verbose")) lg.Info("Inizio caricamento vettore variabili status gestite");
- int totRighe = 0;
- string fileName = string.Format(@"{0}\{1}", utils.confDir, utils.CRS("StatusListFilePath"));
- string linea;
- totRighe = File.ReadLines(fileName).Count();
- // 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);
- // leggo 1 linea alla volta...
- int numRiga = 0;
- while ((linea = file.ReadLine()) != null)
- {
- // 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++;
- }
- }
- // chiudo file
- file.Close();
- // 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));
- }
-
public override void processAlarm()
{
base.processAlarm();
- // ggiungo gestione allarmi CNC
+ // aggiungo gestione allarmi CNC
checkCNCAlarms();
}
-
///
/// Verifica i 10 allarmi CNC SE presenti
///
@@ -1254,25 +1030,38 @@ namespace MTC_Adapter
// controllo valore...
if (allarme.alm_no > 0)
{
- //if (utils.CRB("verbose")) sb.AppendLine(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)
+ try
{
- mAlarmCNC.Add(MTConnect.Condition.Level.FAULT, allarme.alm_msg, codAllarme, "", "");
+ 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();
}
- else
+ catch (Exception exc)
{
- 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();
-
// leggo in blocco tutte le speed da memoria...
int memIndex = 3140;
// buffer memoria 60 byte... speed (16bit 2 * 20) + load (8bit 1 * 20) visto che sono 20 teste max
@@ -1282,169 +1071,88 @@ namespace MTC_Adapter
FanucMemRW(R, FANUC.MemType.D, memIndex, ref unOpSpeedMem);
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-SPEED_UNOP", unOpSpeedMem.Length), DateTime.Now.Subtract(inizio).Ticks);
- StringBuilder sb = new StringBuilder();
-
- int numUnOp = currAdpConf.nUnOp;
- // cicl su path x leggere le velocità dell'UnOp
- for (int i = 0; i < numUnOp; i++)
- {
- // leggo valore Codice
- SpeedRate = BitConverter.ToUInt16(unOpSpeedMem, 2 * i);
-
- // leggo 41° byte = indice 40 + 2*i x le var del carico UnOp
- UnOpLoad = unOpSpeedMem[40 + i];
-
- //vettUnOp[i].mUnOpNumCU.Value = uoData.UnOpNumCU;
- //vettUnOp[i].mUnOpStatus.Value = uoData.UnOpStatus;
- //vettUnOp[i].mUnOpAccTime.Value = uoData.UnOpAccTime;
-
- sb.AppendLine(string.Format("SpeedRate UnOp_{0}: {1} rpm", i + 1, SpeedRate));
- sb.AppendLine(string.Format("Load UnOp_{0}: {1}", i + 1, UnOpLoad));
- }
-
-
- parentForm.dataMonitor_1 += sb.ToString();
+ procUnOp(unOpSpeedMem);
}
///
- /// procedura di lettura (Multipla) dati da memoria x caricare dati utensile
+ /// Procedura di processing lettura memoria x DatiUt - Step 4
///
- /// num max di teste da recuperare
- private void getDatiUt_Fanuc(int maxNumOp)
+ ///
+ ///
+ ///
+ public override int getDatiUt_step4(ref byte[] int32Mem, int j)
{
- // variabili "Indice" utensile e famiglia da decodificare + utils
- int maxMemAddr = 200;
- int[] idUtMontato = new int[maxNumOp];
- int[] idFamUt = new int[maxNumOp];
- int[] idTipoVitaUt = new int[maxNumOp];
- int[] valVitaUtRes = new int[maxNumOp];
- int[] tabUt = new int[maxMemAddr];
- int[] tabFamUt = new int[maxMemAddr];
- int memIndex = 0;
- byte[] int32Mem = new byte[4];
- byte[] int16Mem = new byte[2];
- byte int8Mem = new byte();
-
- // step 1: lettura ID dell'utensile x ogni testa...
- byte[] elencoUtMem = new byte[2 * maxNumOp];
- // leggo area memoria degli UT montati
- memIndex = 2960;
+ int memIndex = 13100 + 4 * j;
inizio = DateTime.Now;
- FanucMemRW(R, FANUC.MemType.D, memIndex, ref elencoUtMem);
- if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-NUMUT", elencoUtMem.Length), DateTime.Now.Subtract(inizio).Ticks);
- // decodifica da byte a int16 dell'ID Utensile
- for (int i = 0; i < maxNumOp; i++)
- {
- idUtMontato[i] = BitConverter.ToUInt16(elencoUtMem, 2 * i);
- }
-
- // step 2a: leggo vettore memoria dei maxMemAddr(200) UT in Tabella Utensili
- memIndex = 11300;
- byte[] tabUt_UT = new byte[2 * maxMemAddr];
+ FanucMemRW(R, FANUC.MemType.D, memIndex, ref int32Mem);
+ if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TabUT-VitaRes", int32Mem.Length), DateTime.Now.Subtract(inizio).Ticks);
+ return memIndex;
+ }
+ ///
+ /// Procedura di processing lettura memoria x DatiUt - Step 3b
+ ///
+ ///
+ ///
+ ///
+ public override int getDatiUt_step3b(ref byte int8Mem, int j)
+ {
+ int memIndex = 10700 + 1 * j;
inizio = DateTime.Now;
- FanucMemRW(R, FANUC.MemType.D, memIndex, ref tabUt_UT);
- if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TabUT-UT", tabUt_UT.Length), DateTime.Now.Subtract(inizio).Ticks);
- // decodifico TUTTI i maxMemAddr utensili
- for (int i = 0; i < maxMemAddr; i++)
- {
- tabUt[i] = BitConverter.ToUInt16(tabUt_UT, 2 * i);
- }
- // step 2a: devo cercare l'UT di ogni UnOp nella Tabella Utensili
- for (int i = 0; i < maxNumOp; i++)
- {
- // spazzo la tab Utensili x cercare quelli delle UnOp...
- for (int j = 0; j < maxMemAddr; j++)
- {
- // controllo, se l'id utensile è quello dell'attuale UnOp...
- if (tabUt[j] == idUtMontato[i])
- {
- // leggo FamUt puntuale..
- memIndex = 11700 + 2 * j;
- inizio = DateTime.Now;
- FanucMemRW(R, FANUC.MemType.D, memIndex, ref int16Mem);
- if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TabUT-FamUT", int16Mem.Length), DateTime.Now.Subtract(inizio).Ticks);
- // step 2b: leggo puntualmente la FamUt dal suo indice...
- idFamUt[i] = BitConverter.ToUInt16(int16Mem, 0);
- }
- }
- }
-
-
- // step 3: leggo vettore memoria dei maxMemAddr(200) FamUT in Tabella Famiglie Utensili (x ricavare unità misura vita)
- memIndex = 8900;
- byte[] tabFam_FamUt = new byte[2 * maxMemAddr];
+ FanucMemRW(R, FANUC.MemType.D, memIndex, ref int8Mem);
+ if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TabUT-FamUT", 8), DateTime.Now.Subtract(inizio).Ticks);
+ return memIndex;
+ }
+ ///
+ /// Procedura di processing lettura memoria x DatiUt - Step 3a
+ ///
+ ///
+ ///
+ public override int getDatiUt_step3a(ref byte[] tabFam_FamUt)
+ {
+ int memIndex = 8900;
inizio = DateTime.Now;
FanucMemRW(R, FANUC.MemType.D, memIndex, ref tabFam_FamUt);
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TabFamUT-FamUT", tabFam_FamUt.Length), DateTime.Now.Subtract(inizio).Ticks);
- // decodifico TUTTI i maxMemAddr utensili
- for (int i = 0; i < maxMemAddr; i++)
- {
- tabFamUt[i] = BitConverter.ToUInt16(tabFam_FamUt, 2 * i);
- }
- // step 3a: devo cercare la famiglia dell'UT di ogni UnOp nella Tabella Famiglie
- for (int i = 0; i < maxNumOp; i++)
- {
- // poiché potrei trovarlo replicato dopo la prima volta che lo trovo evito di ricontrollare...
- bool found = false;
- // spazzo la tab Utensili x cercare quelli delle UnOp...
- for (int j = 0; j < maxMemAddr; j++)
- {
- // controllo, se l'id utensile è quello dell'attuale UnOp...
- if (tabFamUt[j] == idFamUt[i] && !found)
- {
- // leggo FamUt puntuale..
- memIndex = 10700 + 1 * j;
- inizio = DateTime.Now;
- FanucMemRW(R, FANUC.MemType.D, memIndex, ref int8Mem);
- if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TabUT-FamUT", 8), DateTime.Now.Subtract(inizio).Ticks);
- // step 3b: leggo puntualmente il TIPO DI vita UT dal suo indice...
- idTipoVitaUt[i] = int8Mem;
- found = true;
- }
- }
- }
-
- // step 4: recupero la vita residua dell'utente
- for (int i = 0; i < maxNumOp; i++)
- {
- // spazzo la tab Utensili x cercare quelli delle UnOp...
- for (int j = 0; j < maxMemAddr; j++)
- {
- // controllo, se l'id utensile è quello dell'attuale UnOp...
- if (tabUt[j] == idUtMontato[i])
- {
- // leggo FamUt puntuale..
- memIndex = 13100 + 4 * j;
- inizio = DateTime.Now;
- FanucMemRW(R, FANUC.MemType.D, memIndex, ref int32Mem);
- if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TabUT-VitaRes", int32Mem.Length), DateTime.Now.Subtract(inizio).Ticks);
- // leggo puntualmente valore della vita ut residua da indice utensile...
- valVitaUtRes[i] = BitConverter.ToInt32(int32Mem, 0);
- }
- }
- }
-
- // salvo in adapter vita UT residua...
- for (int i = 0; i < maxNumOp; i++)
- {
- vettUnOp[i].mUnOpToolId.Value = idUtMontato[i];
- vettUnOp[i].mUnOpVitaRes.Value = valVitaUtRes[i];
- // decodifico valore tipo VitaRes...
- string tipoVitaRes = "ND";
- switch (idTipoVitaUt[i])
- {
- case 1:
- tipoVitaRes = "Time";
- break;
- case 2:
- tipoVitaRes = "Stroke";
- break;
- case 3:
- tipoVitaRes = "Distance";
- break;
- default: break;
- }
- vettUnOp[i].mUnOpVitaResType.Value = tipoVitaRes;
- }
+ return memIndex;
+ }
+ ///
+ /// Procedura di processing lettura memoria x DatiUt - Step 2b
+ ///
+ ///
+ ///
+ ///
+ public override int getDatiUt_step2b(ref byte[] int16Mem, int j)
+ {
+ int memIndex = 11700 + 2 * j;
+ inizio = DateTime.Now;
+ FanucMemRW(R, FANUC.MemType.D, memIndex, ref int16Mem);
+ if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TabUT-FamUT", int16Mem.Length), DateTime.Now.Subtract(inizio).Ticks);
+ return memIndex;
+ }
+ ///
+ /// Procedura di processing lettura memoria x DatiUt - Step 2a
+ ///
+ ///
+ ///
+ public override int getDatiUt_step2a(ref byte[] tabUt_UT)
+ {
+ int memIndex = 11300;
+ inizio = DateTime.Now;
+ FanucMemRW(R, FANUC.MemType.D, memIndex, ref tabUt_UT);
+ if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TabUT-UT", tabUt_UT.Length), DateTime.Now.Subtract(inizio).Ticks);
+ return memIndex;
+ }
+ ///
+ /// Procedura di processing lettura memoria x DatiUt - Step 1
+ ///
+ ///
+ ///
+ public override int getDatiUt_step1(ref byte[] elencoUtMem)
+ {
+ int memIndex = 2960;
+ inizio = DateTime.Now;
+ FanucMemRW(R, FANUC.MemType.D, memIndex, ref elencoUtMem);
+ if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-NUMUT", elencoUtMem.Length), DateTime.Now.Subtract(inizio).Ticks);
+ return memIndex;
}
public override void getPath()
@@ -1498,11 +1206,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;
@@ -1517,22 +1228,23 @@ 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")));
- sb.AppendLine(string.Format("Path {0}, Asse 3: {1:N3}", i + 1, ((decimal)vettTTCoord.data3) / utils.CRI("fattdecimale")));
- 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")));
+ sb_3.AppendLine(string.Format("Path {0}, Asse 1: {1:N3}", i + 1, ((decimal)vettTTCoord.data1) / utils.CRI("fattdecimale")));
+ sb_3.AppendLine(string.Format("Path {0}, Asse 2: {1:N3}", i + 1, ((decimal)vettTTCoord.data2) / utils.CRI("fattdecimale")));
+ sb_3.AppendLine(string.Format("Path {0}, Asse 3: {1:N3}", i + 1, ((decimal)vettTTCoord.data3) / utils.CRI("fattdecimale")));
+ sb_3.AppendLine(string.Format("Path {0}, Cent 1: {1:N3}", i + 1, ((decimal)vettTTCoord.c1) / utils.CRI("fattdecimale")));
+ sb_3.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();
}
}
public override void getAxis()
{
-
// mostro assi in DataMonitor......
StringBuilder sb = new StringBuilder();
@@ -1556,95 +1268,207 @@ namespace MTC_Adapter
for (int i = 0; i < currAdpConf.nAxis; i++)
{
-
- // in base a indice scelgo valore posizione e load
- switch (i)
+ // per sicurezza try-catch
+ try
{
- case 0:
- valPos = posAssi.p1;
- valLoad = loadAssi.svload1;
- break;
- case 1:
- valPos = posAssi.p2;
- valLoad = loadAssi.svload2;
- break;
- case 2:
- valPos = posAssi.p3;
- valLoad = loadAssi.svload3;
- break;
- case 3:
- valPos = posAssi.p4;
- valLoad = loadAssi.svload4;
- break;
- case 4:
- valPos = posAssi.p5;
- valLoad = loadAssi.svload5;
- break;
- case 5:
- valPos = posAssi.p6;
- valLoad = loadAssi.svload6;
- break;
- default:
- valPos = posAssi.p1;
- valLoad = loadAssi.svload1;
- break;
+ // in base a indice scelgo valore posizione e load
+ switch (i)
+ {
+ case 0:
+ valPos = posAssi.p1;
+ valLoad = loadAssi.svload1;
+ break;
+ case 1:
+ valPos = posAssi.p2;
+ valLoad = loadAssi.svload2;
+ break;
+ case 2:
+ valPos = posAssi.p3;
+ valLoad = loadAssi.svload3;
+ break;
+ case 3:
+ valPos = posAssi.p4;
+ valLoad = loadAssi.svload4;
+ break;
+ case 4:
+ valPos = posAssi.p5;
+ valLoad = loadAssi.svload5;
+ break;
+ case 5:
+ valPos = posAssi.p6;
+ valLoad = loadAssi.svload6;
+ break;
+ case 6:
+ valPos = posAssi.p7;
+ valLoad = loadAssi.svload7;
+ break;
+ case 7:
+ valPos = posAssi.p8;
+ valLoad = loadAssi.svload8;
+ break;
+ case 8:
+ valPos = posAssi.p9;
+ valLoad = loadAssi.svload9;
+ break;
+ case 9:
+ valPos = posAssi.p10;
+ valLoad = loadAssi.svload10;
+ break;
+ case 10:
+ valPos = posAssi.p11;
+ valLoad = loadAssi.svload11;
+ break;
+ case 11:
+ valPos = posAssi.p12;
+ valLoad = loadAssi.svload12;
+ break;
+ case 12:
+ valPos = posAssi.p13;
+ valLoad = loadAssi.svload13;
+ break;
+ case 13:
+ valPos = posAssi.p14;
+ valLoad = loadAssi.svload14;
+ break;
+ case 14:
+ valPos = posAssi.p15;
+ valLoad = loadAssi.svload15;
+ break;
+ case 15:
+ valPos = posAssi.p16;
+ valLoad = loadAssi.svload16;
+ break;
+ case 16:
+ valPos = posAssi.p17;
+ valLoad = loadAssi.svload17;
+ break;
+ case 17:
+ valPos = posAssi.p18;
+ valLoad = loadAssi.svload18;
+ break;
+ case 18:
+ valPos = posAssi.p19;
+ valLoad = loadAssi.svload19;
+ break;
+ case 19:
+ valPos = posAssi.p20;
+ valLoad = loadAssi.svload20;
+ break;
+ case 20:
+ valPos = posAssi.p21;
+ valLoad = loadAssi.svload21;
+ break;
+ case 21:
+ valPos = posAssi.p22;
+ valLoad = loadAssi.svload22;
+ break;
+ case 22:
+ valPos = posAssi.p23;
+ valLoad = loadAssi.svload23;
+ break;
+ case 23:
+ valPos = posAssi.p24;
+ valLoad = loadAssi.svload24;
+ break;
+ case 24:
+ valPos = posAssi.p25;
+ valLoad = loadAssi.svload25;
+ break;
+ case 25:
+ valPos = posAssi.p26;
+ valLoad = loadAssi.svload26;
+ break;
+ case 26:
+ valPos = posAssi.p27;
+ valLoad = loadAssi.svload27;
+ break;
+ case 27:
+ valPos = posAssi.p28;
+ valLoad = loadAssi.svload28;
+ break;
+ case 28:
+ valPos = posAssi.p29;
+ valLoad = loadAssi.svload29;
+ break;
+ case 29:
+ valPos = posAssi.p30;
+ valLoad = loadAssi.svload30;
+ break;
+ case 30:
+ valPos = posAssi.p31;
+ valLoad = loadAssi.svload31;
+ break;
+ case 31:
+ valPos = posAssi.p32;
+ valLoad = loadAssi.svload32;
+ break;
+ default:
+ // 2017.03.01 suggerimento Fabio: in CMS_FANUC in advanced compiler options mettere FS30D=1,SIEMENS=1 x leggere + assi?!?
+ valPos = posAssi.p1;
+ valLoad = loadAssi.svload1;
+ break;
+ }
+
+ // popolo valori...
+ vettAxis[i].mAxLoad.Value = (double)(valLoad.data) / Math.Pow(10, valLoad.dec);
+ newPos = (double)(valPos.abs.data) / Math.Pow(10, valPos.abs.dec);
+ vettAxis[i].mAxPosAct.Value = newPos;
+ vettAxis[i].mAxPosTgt.Value = newPos + (double)(valPos.dist.data) / Math.Pow(10, valPos.dist.dec);
+
+ vettAxis[i].mAxFeedAct.Value = FeedRate;
+
+ // calcolo distanza e salvo valore...
+ distPerc = newPos - prevPosAxis[i];
+
+ // sistemo direzione +/- (POS/NEG se lineari, CCW/CW se rotativi)
+ if (distPerc != 0)
+ {
+ newDir = Convert.ToInt32(distPerc / Math.Abs(distPerc));
+ }
+ else
+ {
+ newDir = prevDirAxis[i];
+ }
+
+ // verifico tipo direzione da tipo asse...
+ tipoAsse = vettAxis[i].mAxType.Value.ToString();
+ if (tipoAsse == "LINEAR")
+ {
+ // ?: conditional operator.
+ direzione = (newDir > 0) ? "POSITIVE" : "NEGATIVE";
+ }
+ else if (tipoAsse == "ROTARY")
+ {
+ direzione = (newDir > 0) ? "CLOCKWISE" : "COUNTER_CLOCKWISE";
+ }
+
+ vettAxis[i].mAxDir.Value = direzione;
+
+
+ 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));
+ }
+
+ // salvo valori vettore prec...
+ prevPosAxis[i] = newPos;
+ prevDirAxis[i] = newDir;
+
+ //vettAxis[i].mAxMainProc.Value = AxData.AxisMainProc;
+ //vettAxis[i].mAxIsMaster.Value = AxData.AxisIsMaster;
+ //vettAxis[i].mAxMastId.Value = AxData.AxisMastId;
+ vettAxis[i].mAxFeedOver.Value = FeedRateOver;
+ //vettAxis[i].mAxAccelAct.Value = AxData.AxisAccel;
+ //vettAxis[i].mAxBattery.Value = AxData.AxisBattery;
}
-
- // popolo valori...
- vettAxis[i].mAxLoad.Value = (double)(valLoad.data) / Math.Pow(10, valLoad.dec);
- newPos = (double)(valPos.abs.data) / Math.Pow(10, valPos.abs.dec);
- vettAxis[i].mAxPosAct.Value = newPos;
- vettAxis[i].mAxPosTgt.Value = newPos + (double)(valPos.dist.data) / Math.Pow(10, valPos.dist.dec);
-
- vettAxis[i].mAxFeedAct.Value = FeedRate;
-
- // calcolo distanza e salvo valore...
- distPerc = newPos - prevPosAxis[i];
-
- // sistemo direzione +/- (POS/NEG se lineari, CCW/CW se rotativi)
- if (distPerc != 0)
+ catch
{
- newDir = Convert.ToInt32(distPerc / Math.Abs(distPerc));
+ lg.Error(string.Format("Errore in lettura asse {0}", i));
}
- else
- {
- newDir = prevDirAxis[i];
- }
-
- // verifico tipo direzione da tipo asse...
- tipoAsse = vettAxis[i].mAxType.Value.ToString();
- if (tipoAsse == "LINEAR")
- {
- // ?: conditional operator.
- direzione = (newDir > 0) ? "POSITIVE" : "NEGATIVE";
- }
- else if (tipoAsse == "ROTARY")
- {
- direzione = (newDir > 0) ? "CLOCKWISE" : "COUNTER_CLOCKWISE";
- }
-
- vettAxis[i].mAxDir.Value = direzione;
-
-
- 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));
- }
-
- // salvo valori vettore prec...
- prevPosAxis[i] = newPos;
- prevDirAxis[i] = newDir;
-
- //vettAxis[i].mAxMainProc.Value = AxData.AxisMainProc;
- //vettAxis[i].mAxIsMaster.Value = AxData.AxisIsMaster;
- //vettAxis[i].mAxMastId.Value = AxData.AxisMastId;
- vettAxis[i].mAxFeedOver.Value = FeedRateOver;
- //vettAxis[i].mAxAccelAct.Value = AxData.AxisAccel;
- //vettAxis[i].mAxBattery.Value = AxData.AxisBattery;
}
- parentForm.dataMonitor_1 += sb.ToString();
+ parentForm.dataMonitor_3 += sb.ToString();
}
}
}
+