diff --git a/IOB-WIN/IobKawasaki.cs b/IOB-WIN/IobKawasaki.cs
index 3c062701..ad9ba879 100644
--- a/IOB-WIN/IobKawasaki.cs
+++ b/IOB-WIN/IobKawasaki.cs
@@ -6,139 +6,500 @@ using System.Net.NetworkInformation;
namespace IOB_WIN
{
- public class IobKawasaki : IobGeneric
- {
-
- ///
- /// Enum segnali status macchina (ByteStatus) come flag
- ///
- [Flags]
- public enum bitStatus
+ public class IobKawasaki : IobGeneric
{
- NONE = 0,
- POWER_ON = 1 << 0,
- AUTO = 1 << 1,
- RUN = 1 << 2,
- ERROR = 1 << 3,
- ALARM = 1 << 4,
- EMERG_OK = 1 << 5,
- DOOR_CLOSED = 1 << 6,
- READY_LOAD = 1 << 7
- }
- ///
- /// Enum segnali macchina ulteriori (ByteSignals)
- ///
- [Flags]
- public enum bitSignals
- {
- NONE = 0,
- TRANSF_AUTO = 1 << 0,
- PUNZ_AUTO = 1 << 1,
- BARR_TAV_RIPR = 1 << 2,
- ARIA_OK = 1 << 3,
- CONS_TRANS_OK = 1 << 4,
- TAV_A = 1 << 5,
- TAV_B = 1 << 6,
- RICH_ACCESSO = 1 << 7
- }
+ #region Private Fields
- ///
- /// LookUpTable di decodifica da CNC a segnali tipo bitmap MAPO
- ///
- Dictionary signLUT = new Dictionary();
- ///
- /// Oggetto MAIN x connessione KAWASAKI
- ///
- protected KRcc.Commu KAWASAKI_ref;
- ///
- /// Array delle risposte dal controllo KAWASAKI
- ///
- protected System.Collections.ArrayList resDataArray;
- ///
- /// Comando inviato al robot
- ///
- protected string comando;
- ///
- /// Variabile verifica thread comunicazione
- ///
- protected bool threadOk = false;
- ///
- /// Nome e seriale macchina
- ///
- protected string macName = "";
- ///
- /// Variabile STATUS corrente (8bit INT)
- ///
- protected string cStatus;
- ///
- /// Variabile SIGNALS corrente (8bit INT)
- ///
- protected string cSignals;
- ///
- /// Num pezzi prelevati
- ///
- protected int numPzPrel;
- ///
- /// Ultimo TC registrato da robot
- ///
- protected decimal lastRecTC;
- ///
- /// Ultima missione svolta da robot
- ///
- protected string lastMissRobot;
+ ///
+ /// LookUpTable di decodifica da CNC a segnali tipo bitmap MAPO
+ ///
+ private Dictionary signLUT = new Dictionary();
- ///
- /// estende l'init della classe base...
- ///
- ///
- ///
- public IobKawasaki(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf)
- {
- // gestione invio ritardato contapezzi
- pzCountDelay = utils.CRI("pzCountDelay");
- lastPzCountSend = DateTime.Now;
- lastWarnODL = DateTime.Now;
- // init connessione
- setConnection();
+ #endregion Private Fields
- // test completo funzionalità kawasaki, da TOGLIERE in prod...
-#if DEBUG
- kawasakiFullTest();
-#endif
- }
- ///
- /// Test completo funzioni kawasaki
- ///
- private void kawasakiFullTest()
- {
- // faccio un try-catch di test vari...
- try
- {
- //string connPar = string.Format("TCP {0}", cIobConf.cncIpAddr);
- //KAWASAKI_ref = new KRcc.Commu(connPar);
- //KAWASAKI_ref = new KRcc.Commu("TCP 192.168.0.92");
- if (KAWASAKI_ref.IsConnected)
+ #region Protected Fields
+
+ ///
+ /// Comando inviato al robot
+ ///
+ protected string comando;
+
+ ///
+ /// Variabile SIGNALS corrente (8bit INT)
+ ///
+ protected string cSignals;
+
+ ///
+ /// Variabile STATUS corrente (8bit INT)
+ ///
+ protected string cStatus;
+
+ ///
+ /// Oggetto MAIN x connessione KAWASAKI
+ ///
+ protected KRcc.Commu KAWASAKI_ref;
+
+ ///
+ /// Ultima missione svolta da robot
+ ///
+ protected string lastMissRobot;
+
+ ///
+ /// Ultimo TC registrato da robot
+ ///
+ protected decimal lastRecTC;
+
+ ///
+ /// Nome e seriale macchina
+ ///
+ protected string macName = "";
+
+ ///
+ /// Num pezzi prelevati
+ ///
+ protected int numPzPrel;
+
+ ///
+ /// Array delle risposte dal controllo KAWASAKI
+ ///
+ protected System.Collections.ArrayList resDataArray;
+
+ ///
+ /// Variabile verifica thread comunicazione
+ ///
+ protected bool threadOk = false;
+
+ #endregion Protected Fields
+
+ #region Public Constructors
+
+ ///
+ /// estende l'init della classe base...
+ ///
+ ///
+ ///
+ public IobKawasaki(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf)
{
- // connect ok
- resDataArray = KAWASAKI_ref.command("where", 3000);
- // WHERE [RET]
- // Console.WriteLine(resDataArray[1]);
- // [0] = 0
- // [1] = JT1 JT2 JT3 JT4 JT5 JT6
- // -23.205 - 39.967 - 13.176 95.663 71.402 - 21.512
- // X[mm] Y[mm] Z[mm] O[deg] A[deg] T[deg]
- // - 489.620 693.940 1564.733 92.612 131.285 7.482
+ // gestione invio ritardato contapezzi
+ pzCountDelay = utils.CRI("pzCountDelay");
+ lastPzCountSend = DateTime.Now;
+ lastWarnODL = DateTime.Now;
+ // init connessione
+ setConnection();
- threadOk = commThreadOk;
- macName = machineName;
- cStatus = currBitmapStatus;
- cSignals = currBitmapSignals;
- contapezziPLC = pzCounter;
- numPzPrel = pzPrelevati;
- lastRecTC = lastTC;
- lastMissRobot = lastMission;
+ // test completo funzionalità kawasaki, da TOGLIERE in prod...
+#if DEBUG
+ kawasakiFullTest();
+#endif
}
- // test contapezzi
+
+ #endregion Public Constructors
+
+ #region Public Enums
+
+ ///
+ /// Enum segnali macchina ulteriori (ByteSignals)
+ ///
+ [Flags]
+ public enum bitSignals
+ {
+ NONE = 0,
+ TRANSF_AUTO = 1 << 0,
+ PUNZ_AUTO = 1 << 1,
+ BARR_TAV_RIPR = 1 << 2,
+ ARIA_OK = 1 << 3,
+ CONS_TRANS_OK = 1 << 4,
+ TAV_A = 1 << 5,
+ TAV_B = 1 << 6,
+ RICH_ACCESSO = 1 << 7
+ }
+
+ ///
+ /// Enum segnali status macchina (ByteStatus) come flag
+ ///
+ [Flags]
+ public enum bitStatus
+ {
+ NONE = 0,
+ POWER_ON = 1 << 0,
+ AUTO = 1 << 1,
+ RUN = 1 << 2,
+ ERROR = 1 << 3,
+ ALARM = 1 << 4,
+ EMERG_OK = 1 << 5,
+ DOOR_CLOSED = 1 << 6,
+ READY_LOAD = 1 << 7
+ }
+
+ #endregion Public Enums
+
+ #region Protected Properties
+
+ ///
+ /// Verifica se il thread 4 di comm sia attivo
+ ///
+ protected bool commThreadOk
+ {
+ get
+ {
+ bool answ = false;
+ if (KAWASAKI_ref.IsConnected)
+ {
+ int retVal = 0;
+ resDataArray = KAWASAKI_ref.command("TYPE TASK (1004)", 3000); // thread 4 ok --> " 1\r\n"
+ int.TryParse(resDataArray[1].ToString().Replace("\n", "").Replace("\r", ""), out retVal);
+ answ = (retVal == 1);
+ }
+ return answ;
+ }
+ }
+
+ ///
+ /// Restituisce SEGNALI macchina nel formato:
+ /// B0: Transfer in auto
+ /// B1: Punzonatrice in AUTO
+ /// B2: Barriera tavola ripristinata
+ /// B3: Aria in linea OK
+ /// B4: Console Transfer in fuori ingombro
+ /// B5: TAV A
+ /// B6: TAV B
+ /// B7: Richiesta accesso attiva
+ ///
+ protected string currBitmapSignals
+ {
+ get
+ {
+ string answ = "";
+ if (KAWASAKI_ref.IsConnected)
+ {
+ resDataArray = KAWASAKI_ref.command("TYPE $signal", 3000); // segnali --> "1|0|1|1|1|0|0|0\r\n"
+ answ = resDataArray[1].ToString().Replace("\n", "").Replace("\r", "").Replace("|", "");
+#if false
+ // reverse stringa (B0 portato a sx)
+ szBitmap = utils.reverseStr(szBitmap);
+ // ora converto bitmap string in INT
+ answ = Convert.ToInt32(szBitmap, 2);
+#endif
+ }
+ return answ;
+ }
+ }
+
+ ///
+ /// Restituisce stato macchina nel formato (da sx a dx):
+ /// B0: POWER_ON
+ /// B1: AUTO
+ /// B2: RUN
+ /// B3: ERROR
+ /// B4: ALLARME
+ /// B5: EMERGENZA OK
+ /// B6: PORTA CHIUSA
+ /// B7: PRONTO AL LOAD
+ ///
+ protected string currBitmapStatus
+ {
+ get
+ {
+ string answ = "";
+ if (KAWASAKI_ref.IsConnected)
+ {
+ resDataArray = KAWASAKI_ref.command("TYPE $status", 3000); // status --> "0|0|1|0|0|1|0|0\r\n"
+ answ = resDataArray[1].ToString().Replace("\n", "").Replace("\r", "").Replace("|", "");
+#if false
+ // reverse stringa (B0 portato a sx)
+ szBitmap = utils.reverseStr(szBitmap);
+ // ora converto bitmap string in INT
+ answ = Convert.ToInt32(szBitmap, 2);
+#endif
+ }
+ return answ;
+ }
+ }
+
+ ///
+ /// Recupera ultima missione svolta
+ ///
+ protected string lastMission
+ {
+ get
+ {
+ string answ = "";
+ if (KAWASAKI_ref.IsConnected)
+ {
+ resDataArray = KAWASAKI_ref.command("TYPE $exe", 3000); // missione --> "\r\n" (vuoto, no missione)
+ answ = resDataArray[1].ToString().Replace("\n", "").Replace("\r", "");
+ }
+ return answ;
+ }
+ }
+
+ ///
+ /// Oggetto per lettura ULTIMO TC rilevato
+ ///
+ protected decimal lastTC
+ {
+ get
+ {
+ decimal answ = 0;
+ if (KAWASAKI_ref.IsConnected)
+ {
+ resDataArray = KAWASAKI_ref.command("TYPE r_tempo", 3000); // ultimo TCiclo rilevato --> " 349.19\r\n"
+ decimal.TryParse(resDataArray[1].ToString().Replace("\n", "").Replace("\r", "").Replace(".", ","), out answ);
+ }
+ return answ;
+ }
+ }
+
+ ///
+ /// Recupera nome e seriale macchina
+ ///
+ protected string machineName
+ {
+ get
+ {
+ string answ = "";
+ if (KAWASAKI_ref.IsConnected)
+ {
+ resDataArray = KAWASAKI_ref.command("TYPE $id_true", 3000); // id macchina --> "BX100N-B001 Sn. 2366\r\n"
+ answ = resDataArray[1].ToString().Replace("\n", "").Replace("\r", "");
+ }
+ return answ;
+ }
+ }
+
+ ///
+ /// Oggetto per lettura/scrittura counter pezzi robot
+ ///
+ protected int pzCounter
+ {
+ get
+ {
+ int answ = 0;
+ if (KAWASAKI_ref.IsConnected)
+ {
+ resDataArray = KAWASAKI_ref.command("TYPE i_cicli", 3000); // num cicli depositati/fatti --> " 0\r\n"
+ int.TryParse(resDataArray[1].ToString().Replace("\n", "").Replace("\r", ""), out answ);
+ }
+ return answ;
+ }
+ set
+ {
+ if (KAWASAKI_ref.IsConnected)
+ {
+ comando = string.Format("i_cicli={0}", value);
+ // scrivo valore cicli
+ resDataArray = KAWASAKI_ref.command(comando, 3000); // imposto cicli depositati/fatti --> " 0\r\n"
+ }
+ }
+ }
+
+ ///
+ /// Oggetto per lettura counter pezzi PRELEVATI
+ ///
+ protected int pzPrelevati
+ {
+ get
+ {
+ int answ = 0;
+ if (KAWASAKI_ref.IsConnected)
+ {
+ resDataArray = KAWASAKI_ref.command("TYPE i_prelevati", 3000); // num pz prelevati --> "0\r\n"
+ int.TryParse(resDataArray[1].ToString().Replace("\n", "").Replace("\r", ""), out answ);
+ }
+ return answ;
+ }
+ }
+
+ #endregion Protected Properties
+
+ #region Private Methods
+
+ ///
+ /// Decodifica il resto dell'area x i dati accessori (allarmi, ...)
+ ///
+ private void decodeOtherData()
+ {
+ if (verboseLog)
+ {
+ }
+ }
+
+ ///
+ /// Effettua decodifica aree memoria alla bitmap usata x MAPO
+ ///
+ private void decodeToBaseBitmap()
+ {
+ // init a zero...
+ B_input = 0;
+ /* -----------------------------------------------------
+ * bitmap MAPO
+ * B0: POWER_ON
+ * B1: RUN
+ * B2: pzCount
+ * B3: allarme
+ * B4: manuale
+ * B5: emergenza
+ * B6: error prog
+ * B7: auto mode
+ ----------------------------------------------------- */
+ // bit 0 (poweron) imposto a 1 SE connected...
+ B_input = KAWASAKI_ref.IsConnected ? 1 : 0;
+ // RUN
+ if (cStatus[2] == '1')
+ {
+ B_input += (1 << 1);
+ }
+ // ERROR prog/macchina
+ if (cStatus[3] == '1')
+ {
+ B_input += (1 << 6);
+ }
+ // allarme
+ if (cStatus[4] == '1')
+ {
+ B_input += (1 << 3);
+ }
+ // Automatico (porta chiusa)
+ if (cStatus[6] == '1' || cStatus[1] == '1')
+ {
+ B_input += (1 << 4);
+ }
+ // NON EMERGENZA (1=armed, 0=triggered)
+ if (cStatus[5] == '0')
+ {
+ B_input += (1 << 5);
+ }
+
+ // process ODL e contapezzi
+ string currODL = "";
+ try
+ {
+ currODL = utils.callUrl(urlGetCurrODL);
+ // solo SE HO un ODL...
+ if (string.IsNullOrEmpty(currODL) || currODL == "0")
+ {
+ if (periodicLog)
+ {
+ lgInfo(string.Format("Kawasaki | Lettura ODL andata a vuoto: currODL: {0}", currODL));
+ }
+ }
+ else
+ { // se variato o scaduto timeout log...
+ if (periodicLog || (currIdxODL.ToString() != currODL))
+ {
+ lgInfo(string.Format("Kawasaki | Lettura ODL, currODL: {0} --> currIdxODL prec: {1}", currODL, currIdxODL));
+ }
+ // provo a salvare nuovo ODL
+ int.TryParse(currODL, out currIdxODL);
+ }
+ }
+ catch (Exception exc)
+ {
+ if (DateTime.Now.Subtract(lastWarnODL).TotalSeconds > 15)
+ {
+ lgError(exc, "Errore in fase di chiamata URL x ODL corrente | URL chiamato: {0}", urlGetCurrODL);
+ lastWarnODL = DateTime.Now;
+ }
+ }
+ if (!string.IsNullOrEmpty(currODL))
+ {
+ if (currODL != "0")
+ {
+ // ora processo il contapezzi...
+ // controllo se è passato intervallo minimo tra 2 controlli/elaborazioni x distanziare invio e ridurre letture
+ if (DateTime.Now >= lastPzCountSend.AddMilliseconds(pzCountDelay))
+ {
+ // se sono differenti MOSTRO...
+ if (contapezziPLC != contapezziIOB)
+ {
+ // registro contapezzi
+ lgInfo($"Differenza Contapezzi CNC/IOB: contapezziPLC: {contapezziPLC} | contapezziIOB: {contapezziIOB}");
+ }
+ // verifico se variato contapezzi... e se passato ritardo minimo...
+ if (contapezziPLC > contapezziIOB)
+ {
+ // salvo nuovo contapezzi (incremento di 1...) + richiesta refresh conteggio
+ contapezziIOB++;
+ needRefreshPzCount = true;
+ // salvo in semaforo!
+ B_input += (1 << 2);
+ // registro contapezzi
+ lgInfo($"contapezziPLC KAWASAKI: {contapezziPLC} | contapezziIOB {contapezziIOB}");
+ }
+ else if (contapezziIOB > contapezziPLC)
+ {
+ lgInfo($"Contapezzi IOB > CNC --> NON INVIO (contapezziPLC: {contapezziPLC} < contapezziIOB: {contapezziIOB})");
+ }
+
+ // invio a server contapezzi (aggiornato)
+ string retVal = utils.callUrl(urlSetPzCount + contapezziIOB.ToString());
+ // verifica se tutto OK
+ if (retVal != contapezziIOB.ToString())
+ {
+ // errore salvataggio contapezzi
+ lgInfo($"Errore salvataggio Contapezzi KAWASAKI: contapezziPLC {contapezziPLC} | contapezziIOB {contapezziIOB} | risposta: {retVal}");
+ // rileggo il counter pezzi da server
+ pzCntReload(true);
+ }
+ // resetto timer...
+ lastPzCountSend = DateTime.Now;
+ }
+ }
+ else
+ {
+ lgError("Attenzione non trovato ODL --> currODL = 0");
+ }
+ }
+ else
+ {
+ if (DateTime.Now >= lastPzCountSend.AddMilliseconds(pzCountDelay))
+ {
+ lgError($"Attenzione: mancanza ODL non procedo con gestione contapezzi. contapezziPLC KAWASAKI {contapezziPLC} | contapezziIOB {contapezziIOB}");
+ // resetto timer...
+ lastPzCountSend = DateTime.Now;
+ }
+ }
+
+ // log opzionale!
+ if (verboseLog)
+ {
+ lgInfo($"Trasformazione B_input: {B_input}");
+ }
+ }
+
+ ///
+ /// Test completo funzioni kawasaki
+ ///
+ private void kawasakiFullTest()
+ {
+ // faccio un try-catch di test vari...
+ try
+ {
+ //string connPar = string.Format("TCP {0}", cIobConf.cncIpAddr);
+ //KAWASAKI_ref = new KRcc.Commu(connPar);
+ //KAWASAKI_ref = new KRcc.Commu("TCP 192.168.0.92");
+ if (KAWASAKI_ref.IsConnected)
+ {
+ // connect ok
+ resDataArray = KAWASAKI_ref.command("where", 3000);
+ // WHERE [RET]
+ // Console.WriteLine(resDataArray[1]);
+ // [0] = 0
+ // [1] = JT1 JT2 JT3 JT4 JT5 JT6
+ // -23.205 - 39.967 - 13.176 95.663 71.402 - 21.512
+ // X[mm] Y[mm] Z[mm] O[deg] A[deg] T[deg]
+ // - 489.620 693.940 1564.733 92.612 131.285 7.482
+
+ threadOk = commThreadOk;
+ macName = machineName;
+ cStatus = currBitmapStatus;
+ cSignals = currBitmapSignals;
+ contapezziPLC = pzCounter;
+ numPzPrel = pzPrelevati;
+ lastRecTC = lastTC;
+ lastMissRobot = lastMission;
+ }
+ // test contapezzi
#if false
// leggo i pezzi
int currCount = pzCounter;
@@ -149,582 +510,310 @@ namespace IOB_WIN
// reimposto corretti
pzCounter = currCount;
#endif
- // test gest programmi
+ // test gest programmi
#if true
- //saveProgram("prog", "default");
- sendProgram("prog", "default2");
+ //saveProgram("prog", "default");
+ sendProgram("prog", "default2");
#endif
- }
- catch (Exception e)
- { // e.Message = "can't connect TCP/IP" or // "can't login"
- Console.WriteLine(e.Message);
- }
- }
-
-
- ///
- /// Processo i task richiesti e li elimino dalla coda 1:1
- ///
- ///
- public override Dictionary executeTasks(Dictionary task2exe)
- {
- // Verificare il protocollo: dovrebbe togliere SOLO i task eseguiti...
- Dictionary taskDone = new Dictionary();
- bool taskOk = false;
- string taskVal = "";
-
- // cerco task specifici: se ho startSetup --> imposto bit DBB701.DBB0.4
- foreach (var item in task2exe)
- {
- taskOk = false;
- taskVal = "";
- // converto richiesta in enum...
- taskType tName = taskType.nihil;
- Enum.TryParse(item.Key, out tName);
- // controllo sulla KEY
- switch (tName)
- {
- case taskType.nihil:
- case taskType.fixStopSetup:
- case taskType.setArt:
- case taskType.setComm:
- case taskType.setProg:
- case taskType.sendWatchDogMes2Plc:
- taskVal = $"taskReq: {tName} | key: {item.Key} | val: {item.Value} | SKIPPED | NO EXEC";
- break;
- case taskType.forceResetPzCount:
- // reset contapezzi inizio setup
- taskOk = resetcontapezziPLC();
- taskVal = taskOk ? "FORCE RESET PZ COUNT" : "FORCE RESET DISABLED | NO EXEC";
- break;
- case taskType.forceSetPzCount:
- // reset contapezzi inizio setup
- int newPzCount = 0;
- int.TryParse(item.Value, out newPzCount);
- if (newPzCount >= 0)
- {
- taskOk = setcontapezziPLC(newPzCount);
- taskVal = taskOk ? $"FORCE SET PZ COUNT TO {newPzCount}" : $"FORCE SET PZ COUNT TO {newPzCount} | NO EXEC";
}
- else
- {
- taskVal = $"ERROR IN FORCE SET PZ COUNT TO {newPzCount}";
+ catch (Exception e)
+ { // e.Message = "can't connect TCP/IP" or // "can't login"
+ Console.WriteLine(e.Message);
}
- break;
- case taskType.startSetup:
- // reset contapezzi inizio setup
- taskOk = resetcontapezziPLC();
- taskVal = taskOk ? "RESET: SETUP START" : "PZ RESET DISABLED | NO EXEC";
- break;
- case taskType.stopSetup:
- // reset contapezzi fine setup // reset contapezzi fine setup SE ESPLICITAMENTE IMPOSTATO
- if (cIobConf.optPar.Count > 0 && getOptPar("ENABLE_PZ_RESET_stopSetup") == "TRUE")
- {
- resetcontapezziPLC();
- }
- taskVal = taskOk ? "RESET: SETUP END" : "PZ RESET DISABLED | NO EXEC";
- break;
- default:
- taskVal = "SKIPPED | NO EXEC";
- break;
}
- taskDone.Add(item.Key, taskVal);
- }
- return taskDone;
- }
- ///
- /// Effettua reset del contapezzi
- ///
- ///
- public override bool resetcontapezziPLC()
- {
- bool answ = false;
- // ...SE abilitato da conf IOB
- if (cIobConf.optPar.Count > 0 && getOptPar("ENABLE_PZ_RESET") == "TRUE")
- {
- // scrivo valore 0 x il contapezzi
- try
+ ///
+ /// Effettua salvataggio del programma corrente
+ ///
+ /// Dir di riferimento
+ /// Nome Programma (se mancasse *.as lo aggiunge)
+ private void saveProgram(string progDir = "prog", string progName = "current.as")
{
- pzCounter = 0;
- }
- catch (Exception exc)
- {
- lgError(exc, "Errore in RESET contapezzi KAWASAKI");
- connectionOk = false;
- }
- answ = true;
- }
- else
- {
- lgError("Impossibile effettuare RESET contapezzi KAWASAKI, mancanza parametro OPT:ENABLE_PZ_RESET");
- }
- return answ;
- }
- ///
- /// Effettua IMPOSTAZIONE FORZATA del contapezzi
- ///
- ///
- public override bool setcontapezziPLC(int newPzCount)
- {
- bool answ = false;
- // ...SE abilitato da conf IOB
- if (cIobConf.optPar.Count > 0 && getOptPar("ENABLE_PZ_RESET") == "TRUE")
- {
- // scrivo valore 0 x il contapezzi
- try
- {
- pzCounter = newPzCount;
- }
- catch (Exception exc)
- {
- lgError(exc, "Errore in SET contapezzi KAWASAKI");
- connectionOk = false;
- }
- answ = true;
- }
- else
- {
- lgError("Impossibile effettuare SET contapezzi KAWASAKI, mancanza parametro OPT:ENABLE_PZ_RESET");
- }
- return answ;
- }
+ // path completo
+ progName = progName.EndsWith(".as") ? progName : progName + ".as";
+ string prgPath = progName;// string.Format("{0}/{1}", progDir, progName);
+ if (KAWASAKI_ref.IsConnected)
+ {
+ // comandi x setup programma...
+ resDataArray = KAWASAKI_ref.command("ferma", 3000); // ferma processi (all) --> ""
+ resDataArray = KAWASAKI_ref.command("togli", 3000); // toglie processi da pronta esecuzione --> ""
- ///
- /// Imposto connessione
- ///
- protected virtual void setConnection()
- {
- // Creo oggetto connessione NC
- parentForm.commPlcActive = true;
- lgInfo("Start init Adapter KAWASAKI all'IP {0} | --> IOB {1}", cIobConf.cncIpAddr, cIobConf.codIOB);
+ //resp = com.command("SAVE nome_del_file", 3000); // salvataggio file... FORSE --> "\u0005\u0002Bnome_del_file.as\u0017" --> verificare DOVE salva...
- // inizializzo correttamente aree memoria secondo CONF - iniFileName
- IniFile fIni = new IniFile(cIobConf.iniFileName);
- // fix enable prgName
- enablePrgName = fIni.ReadBoolean("CNC", "GETPRGNAME", true);
-
- // SE è necessario refresh...
- if (needRefresh)
- {
- lgInfo("Refreshing connection...");
- // ora tento avvio PLC... SE PING OK...
- if (testPingMachine == IPStatus.Success)
- {
- try
- {
- string connPar = string.Format("TCP {0}", cIobConf.cncIpAddr);
- KAWASAKI_ref = new KRcc.Commu(connPar);
- // disconnetto e connetto...
- if (isVerboseLog)
- {
- lgInfo("KAWASAKI: tryDisconnect");
- }
-
- lgInfo("End init Adapter KAWASAKI");
- if (isVerboseLog)
- {
- lgInfo("KAWASAKI CONNESSIONE AVVENUTA");
- }
- }
- catch (Exception exc)
- {
- lgError(exc, "Errore in INIT KAWASAKI Commu");
- }
- needRefresh = false;
- }
- parentForm.commPlcActive = false;
- // gestione pzCounter
- if (utils.CRB("enableContapezzi"))
- {
- lgInfo("KAWASAKI: inizio gestione contapezzi");
- try
- {
- // verifico quale modalità sia richiesta: STD (6711) oppure BIT (Custom, con indicazione area)
- if (cIobConf.optPar.Count > 0 && !string.IsNullOrEmpty(getOptPar("PZCOUNT_MODE")))
- {
- if (getOptPar("PZCOUNT_MODE").StartsWith("STD"))
- {
- lgInfo("Init contapezzi KAWASAKI: pzCntReload(true)");
- pzCntReload(true);
- // refresh associazione Macchina - IOB
- sendM2IOB();
- // per adesso imposto lettura fanuc == contapezzi (poi farà vera lettura...)
- contapezziPLC = contapezziIOB;
- }
- else
- {
- contapezziIOB = 0;
- lgInfo("Contapezzi STD disabilitato: modalità {0}", getOptPar("PZCOUNT_MODE"));
- }
- }
- else
- {
- contapezziIOB = 0;
- lgInfo("Parametro mancante PZCOUNT_MODE");
- }
- }
- catch (Exception exc)
- {
- lgError(exc, "Errore in contapezzi KAWASAKI");
- }
- }
- }
- }
- ///
- /// Override disconnessione
- ///
- public override void tryDisconnect()
- {
- if (connectionOk)
- {
- connectionOk = false;
- string szStatusConnection = "";
- try
- {
- KAWASAKI_ref.disconnect();
- lgInfo(szStatusConnection);
- lgInfo("Effettuata disconnessione adapter KAWASAKI!");
- }
- catch (Exception exc)
- {
- lgFatal(exc, "Errore nella disconnessione dall'adapter KAWASAKI");
- }
- }
- else
- {
- lgError("IMPOSSIBILE effettuare disconnessione KAWASAKI: Connessione non disponibile...");
- }
- needRefresh = true;
- }
- ///
- /// Override connessione
- ///
- public override void tryConnect()
- {
- if (!connectionOk)
- {
- // controllo che il ping sia stato tentato almeno pingTestSec fa...
- if (DateTime.Now.Subtract(lastPING).TotalSeconds > utils.CRI("pingTestSec"))
- {
- if (verboseLog || periodicLog)
- {
- lgInfo("KAWASAKI: ConnKO - tryConnect");
- }
- // in primis salvo data ping...
- lastPING = DateTime.Now;
- // se passa il ping faccio il resto...
- if (testPingMachine == IPStatus.Success)
- {
- string szStatusConnection = "";
- try
- {
- // ora provo connessione...
- parentForm.commPlcActive = true;
- string connPar = string.Format("TCP {0}", cIobConf.cncIpAddr);
- KAWASAKI_ref.connect(connPar);
- parentForm.commPlcActive = false;
- lgInfo("szStatusConnection: " + KAWASAKI_ref.IsConnected);
- connectionOk = true;
- // verifico se sta girando
- if (connectionOk)
- {
- if (adpRunning)
+ int ret = KAWASAKI_ref.save(prgPath); // SAVE current.as[RET]
+ if (ret == 0)
{
- lgInfo("Connessione OK");
+ // Success
+ }
+ if (ret == -1)
+ {
+ // Communication error
+ }
+ if (ret == -2)
+ {
+ // Robot Controller error
+ }
+ if (ret == -3)
+ {
+ // Internal error
}
- }
- else
- {
- lgError("Impossibile procedere, connessione mancante...");
- }
}
- catch (Exception exc)
+ }
+
+ ///
+ /// Effettua invio del programma di alvorazione al ROBOT
+ /// Dir di riferimento
+ /// Nome Programma (se mancasse *.as lo aggiunge)
+ ///
+ private void sendProgram(string progDir = "prog", string progName = "default.as")
+ {
+ // path completo
+ progName = progName.EndsWith(".as") ? progName : progName + ".as";
+ string prgPath = progName;// string.Format("{0}/{1}", progDir, progName);
+
+ // comandi x setup programma...
+ resDataArray = KAWASAKI_ref.command("ferma", 3000); // ferma processi (all) --> ""
+ resDataArray = KAWASAKI_ref.command("togli", 3000); // toglie processi da pronta esecuzione --> ""
+
+ if (KAWASAKI_ref.IsConnected)
{
- lgFatal(string.Format("Errore nella connessione all'adapter KAWASAKI: {0}{1}{2}", szStatusConnection, Environment.NewLine, exc));
- connectionOk = false;
- lgInfo(string.Format("Eccezione in TryConnect, Adapter KAWASAKI NON running, pausa di {0} msec prima di ulteriori tentativi di riconnessione", utils.CRI("waitRecMSec")));
+ // carico...
+ KAWASAKI_ref.asInquiry = delegate (string as_msg)
+ {
+ Console.WriteLine(as_msg); if (as_msg.StartsWith("Are you sure ?"))
+ {
+ return "0\n"; // 0 [RET]
+ }
+
+ if (as_msg.StartsWith("Load data?"))
+ {
+ return "1\n"; // 1 [RET]
+ }
+
+ return null;
+ };
+ int retLoad = KAWASAKI_ref.load(prgPath, "/Q"); // LOAD/Q default.as[RET]
}
- }
- else
- {
- // loggo no risposta ping ...
- connectionOk = false;
- needRefresh = true;
- if (verboseLog || periodicLog)
+ }
+
+ #endregion Private Methods
+
+ #region Protected Methods
+
+ ///
+ /// Imposto connessione
+ ///
+ protected virtual void setConnection()
+ {
+ // Creo oggetto connessione NC
+ parentForm.commPlcActive = true;
+ lgInfo("Start init Adapter KAWASAKI all'IP {0} | --> IOB {1}", cIobConf.cncIpAddr, cIobConf.codIOB);
+
+ // inizializzo correttamente aree memoria secondo CONF - iniFileName
+ IniFile fIni = new IniFile(cIobConf.iniFileName);
+ // fix enable prgName
+ enablePrgName = fIni.ReadBoolean("CNC", "GETPRGNAME", true);
+
+ // SE è necessario refresh...
+ if (needRefresh)
{
- lgInfo(string.Format("Attenzione: KAWASAKI controllo PING fallito per IP {0}", cIobConf.cncIpAddr));
+ lgInfo("Refreshing connection...");
+ // ora tento avvio PLC... SE PING OK...
+ if (testPingMachine == IPStatus.Success)
+ {
+ try
+ {
+ string connPar = string.Format("TCP {0}", cIobConf.cncIpAddr);
+ KAWASAKI_ref = new KRcc.Commu(connPar);
+ // disconnetto e connetto...
+ if (isVerboseLog)
+ {
+ lgInfo("KAWASAKI: tryDisconnect");
+ }
+
+ lgInfo("End init Adapter KAWASAKI");
+ if (isVerboseLog)
+ {
+ lgInfo("KAWASAKI CONNESSIONE AVVENUTA");
+ }
+ }
+ catch (Exception exc)
+ {
+ lgError(exc, "Errore in INIT KAWASAKI Commu");
+ }
+ needRefresh = false;
+ }
+ parentForm.commPlcActive = false;
+ // gestione pzCounter
+ if (utils.CRB("enableContapezzi"))
+ {
+ lgInfo("KAWASAKI: inizio gestione contapezzi");
+ try
+ {
+ // verifico quale modalità sia richiesta: STD (6711) oppure BIT (Custom, con indicazione area)
+ if (cIobConf.optPar.Count > 0 && !string.IsNullOrEmpty(getOptPar("PZCOUNT_MODE")))
+ {
+ if (getOptPar("PZCOUNT_MODE").StartsWith("STD"))
+ {
+ lgInfo("Init contapezzi KAWASAKI: pzCntReload(true)");
+ pzCntReload(true);
+ // refresh associazione Macchina - IOB
+ sendM2IOB();
+ // per adesso imposto lettura fanuc == contapezzi (poi farà vera lettura...)
+ contapezziPLC = contapezziIOB;
+ }
+ else
+ {
+ contapezziIOB = 0;
+ lgInfo("Contapezzi STD disabilitato: modalità {0}", getOptPar("PZCOUNT_MODE"));
+ }
+ }
+ else
+ {
+ contapezziIOB = 0;
+ lgInfo("Parametro mancante PZCOUNT_MODE");
+ }
+ }
+ catch (Exception exc)
+ {
+ lgError(exc, "Errore in contapezzi KAWASAKI");
+ }
+ }
}
- }
}
- }
- // se non è ancora connesso faccio processing memoria caso disconnesso...
- if (!connectionOk)
- {
- // processo semafori ed invio...
- processMemoryDiscon();
- }
- }
- ///
- /// Oggetto per lettura counter pezzi PRELEVATI
- ///
- protected int pzPrelevati
- {
- get
- {
- int answ = 0;
- if (KAWASAKI_ref.IsConnected)
- {
- resDataArray = KAWASAKI_ref.command("TYPE i_prelevati", 3000); // num pz prelevati --> "0\r\n"
- int.TryParse(resDataArray[1].ToString().Replace("\n", "").Replace("\r", ""), out answ);
- }
- return answ;
- }
- }
- ///
- /// Oggetto per lettura ULTIMO TC rilevato
- ///
- protected decimal lastTC
- {
- get
- {
- decimal answ = 0;
- if (KAWASAKI_ref.IsConnected)
- {
- resDataArray = KAWASAKI_ref.command("TYPE r_tempo", 3000); // ultimo TCiclo rilevato --> " 349.19\r\n"
- decimal.TryParse(resDataArray[1].ToString().Replace("\n", "").Replace("\r", "").Replace(".", ","), out answ);
- }
- return answ;
- }
- }
- ///
- /// Oggetto per lettura/scrittura counter pezzi robot
- ///
- protected int pzCounter
- {
- get
- {
- int answ = 0;
- if (KAWASAKI_ref.IsConnected)
- {
- resDataArray = KAWASAKI_ref.command("TYPE i_cicli", 3000); // num cicli depositati/fatti --> " 0\r\n"
- int.TryParse(resDataArray[1].ToString().Replace("\n", "").Replace("\r", ""), out answ);
- }
- return answ;
- }
- set
- {
- if (KAWASAKI_ref.IsConnected)
- {
- comando = string.Format("i_cicli={0}", value);
- // scrivo valore cicli
- resDataArray = KAWASAKI_ref.command(comando, 3000); // imposto cicli depositati/fatti --> " 0\r\n"
- }
- }
- }
- ///
- /// Verifica se il thread 4 di comm sia attivo
- ///
- protected bool commThreadOk
- {
- get
- {
- bool answ = false;
- if (KAWASAKI_ref.IsConnected)
- {
- int retVal = 0;
- resDataArray = KAWASAKI_ref.command("TYPE TASK (1004)", 3000); // thread 4 ok --> " 1\r\n"
- int.TryParse(resDataArray[1].ToString().Replace("\n", "").Replace("\r", ""), out retVal);
- answ = (retVal == 1);
- }
- return answ;
- }
- }
- ///
- /// Recupera nome e seriale macchina
- ///
- protected string machineName
- {
- get
- {
- string answ = "";
- if (KAWASAKI_ref.IsConnected)
- {
- resDataArray = KAWASAKI_ref.command("TYPE $id_true", 3000); // id macchina --> "BX100N-B001 Sn. 2366\r\n"
- answ = resDataArray[1].ToString().Replace("\n", "").Replace("\r", "");
- }
- return answ;
- }
- }
- ///
- /// Recupera ultima missione svolta
- ///
- protected string lastMission
- {
- get
- {
- string answ = "";
- if (KAWASAKI_ref.IsConnected)
- {
- resDataArray = KAWASAKI_ref.command("TYPE $exe", 3000); // missione --> "\r\n" (vuoto, no missione)
- answ = resDataArray[1].ToString().Replace("\n", "").Replace("\r", "");
- }
- return answ;
- }
- }
- ///
- /// Restituisce stato macchina nel formato (da sx a dx):
- /// B0: POWER_ON
- /// B1: AUTO
- /// B2: RUN
- /// B3: ERROR
- /// B4: ALLARME
- /// B5: EMERGENZA OK
- /// B6: PORTA CHIUSA
- /// B7: PRONTO AL LOAD
- ///
- protected string currBitmapStatus
- {
- get
- {
- string answ = "";
- if (KAWASAKI_ref.IsConnected)
- {
- resDataArray = KAWASAKI_ref.command("TYPE $status", 3000); // status --> "0|0|1|0|0|1|0|0\r\n"
- answ = resDataArray[1].ToString().Replace("\n", "").Replace("\r", "").Replace("|", "");
-#if false
- // reverse stringa (B0 portato a sx)
- szBitmap = utils.reverseStr(szBitmap);
- // ora converto bitmap string in INT
- answ = Convert.ToInt32(szBitmap, 2);
-#endif
- }
- return answ;
- }
- }
- ///
- /// Restituisce SEGNALI macchina nel formato:
- /// B0: Transfer in auto
- /// B1: Punzonatrice in AUTO
- /// B2: Barriera tavola ripristinata
- /// B3: Aria in linea OK
- /// B4: Console Transfer in fuori ingombro
- /// B5: TAV A
- /// B6: TAV B
- /// B7: Richiesta accesso attiva
- ///
- protected string currBitmapSignals
- {
- get
- {
- string answ = "";
- if (KAWASAKI_ref.IsConnected)
- {
- resDataArray = KAWASAKI_ref.command("TYPE $signal", 3000); // segnali --> "1|0|1|1|1|0|0|0\r\n"
- answ = resDataArray[1].ToString().Replace("\n", "").Replace("\r", "").Replace("|", "");
-#if false
- // reverse stringa (B0 portato a sx)
- szBitmap = utils.reverseStr(szBitmap);
- // ora converto bitmap string in INT
- answ = Convert.ToInt32(szBitmap, 2);
-#endif
- }
- return answ;
- }
- }
+ #endregion Protected Methods
- ///
- /// Effettua salvataggio del programma corrente
- ///
- /// Dir di riferimento
- /// Nome Programma (se mancasse *.as lo aggiunge)
- private void saveProgram(string progDir = "prog", string progName = "current.as")
- {
- // path completo
- progName = progName.EndsWith(".as") ? progName : progName + ".as";
- string prgPath = progName;// string.Format("{0}/{1}", progDir, progName);
- if (KAWASAKI_ref.IsConnected)
- {
- // comandi x setup programma...
- resDataArray = KAWASAKI_ref.command("ferma", 3000); // ferma processi (all) --> ""
- resDataArray = KAWASAKI_ref.command("togli", 3000); // toglie processi da pronta esecuzione --> ""
+ #region Public Methods
- //resp = com.command("SAVE nome_del_file", 3000); // salvataggio file... FORSE --> "\u0005\u0002Bnome_del_file.as\u0017" --> verificare DOVE salva...
-
- int ret = KAWASAKI_ref.save(prgPath); // SAVE current.as[RET]
- if (ret == 0)
+ ///
+ /// Processo i task richiesti e li elimino dalla coda 1:1
+ ///
+ ///
+ public override Dictionary executeTasks(Dictionary task2exe)
{
- // Success
+ // Verificare il protocollo: dovrebbe togliere SOLO i task eseguiti...
+ Dictionary taskDone = new Dictionary();
+ bool taskOk = false;
+ string taskVal = "";
+
+ // cerco task specifici: se ho startSetup --> imposto bit DBB701.DBB0.4
+ foreach (var item in task2exe)
+ {
+ taskOk = false;
+ taskVal = "";
+ // converto richiesta in enum...
+ taskType tName = taskType.nihil;
+ Enum.TryParse(item.Key, out tName);
+ // controllo sulla KEY
+ switch (tName)
+ {
+ case taskType.nihil:
+ case taskType.fixStopSetup:
+ case taskType.setArt:
+ case taskType.setComm:
+ case taskType.setProg:
+ case taskType.sendWatchDogMes2Plc:
+ taskVal = $"taskReq: {tName} | key: {item.Key} | val: {item.Value} | SKIPPED | NO EXEC";
+ break;
+
+ case taskType.forceResetPzCount:
+ // reset contapezzi inizio setup
+ taskOk = resetcontapezziPLC();
+ taskVal = taskOk ? "FORCE RESET PZ COUNT" : "FORCE RESET DISABLED | NO EXEC";
+ break;
+
+ case taskType.forceSetPzCount:
+ // reset contapezzi inizio setup
+ int newPzCount = 0;
+ int.TryParse(item.Value, out newPzCount);
+ if (newPzCount >= 0)
+ {
+ taskOk = setcontapezziPLC(newPzCount);
+ taskVal = taskOk ? $"FORCE SET PZ COUNT TO {newPzCount}" : $"FORCE SET PZ COUNT TO {newPzCount} | NO EXEC";
+ }
+ else
+ {
+ taskVal = $"ERROR IN FORCE SET PZ COUNT TO {newPzCount}";
+ }
+ break;
+
+ case taskType.startSetup:
+ // reset contapezzi inizio setup
+ taskOk = resetcontapezziPLC();
+ taskVal = taskOk ? "RESET: SETUP START" : "PZ RESET DISABLED | NO EXEC";
+ break;
+
+ case taskType.stopSetup:
+ // reset contapezzi fine setup // reset contapezzi fine setup SE ESPLICITAMENTE IMPOSTATO
+ if (cIobConf.optPar.Count > 0 && getOptPar("ENABLE_PZ_RESET_stopSetup") == "TRUE")
+ {
+ resetcontapezziPLC();
+ }
+ taskVal = taskOk ? "RESET: SETUP END" : "PZ RESET DISABLED | NO EXEC";
+ break;
+
+ default:
+ taskVal = "SKIPPED | NO EXEC";
+ break;
+ }
+ taskDone.Add(item.Key, taskVal);
+ }
+
+ return taskDone;
}
- if (ret == -1)
+
+ ///
+ /// Recupero dati dinamici...
+ ///
+ public override Dictionary getDynData()
{
- // Communication error
+ // valore non presente in vers default... se gestito fare override
+ Dictionary outVal = new Dictionary();
+ outVal.Add("LAST_MISS", lastMissRobot);
+ outVal.Add("LAST_TC", lastTC.ToString());
+ outVal.Add("NUM_PZ_PREL", pzPrelevati.ToString());
+ outVal.Add("NUM_PZ_LAV", pzCounter.ToString());
+ outVal.Add("CURR_SIGNALS", currBitmapSignals.ToString());
+ return outVal;
}
- if (ret == -2)
+
+ ///
+ /// Recupero programma in lavorazione
+ ///
+ ///
+ public override string getPrgName()
{
- // Robot Controller error
+ // valore non presente in vers default... se gestito fare override
+ string prgName = "";
+ return prgName;
}
- if (ret == -3)
+
+ ///
+ /// Recupero info sistema generiche
+ ///
+ public override Dictionary getSysInfo()
{
- // Internal error
+ // valore non presente in vers default... se gestito fare override
+ Dictionary outVal = new Dictionary();
+ outVal.Add("MACHINE", machineName);
+ return outVal;
}
- }
- }
- ///
- /// Effettua invio del programma di alvorazione al ROBOT
- /// Dir di riferimento
- /// Nome Programma (se mancasse *.as lo aggiunge)
- ///
- private void sendProgram(string progDir = "prog", string progName = "default.as")
- {
- // path completo
- progName = progName.EndsWith(".as") ? progName : progName + ".as";
- string prgPath = progName;// string.Format("{0}/{1}", progDir, progName);
- // comandi x setup programma...
- resDataArray = KAWASAKI_ref.command("ferma", 3000); // ferma processi (all) --> ""
- resDataArray = KAWASAKI_ref.command("togli", 3000); // toglie processi da pronta esecuzione --> ""
-
- if (KAWASAKI_ref.IsConnected)
- {
- // carico...
- KAWASAKI_ref.asInquiry = delegate (string as_msg)
+ ///
+ /// Effettua vero processing contapezzi
+ ///
+ public override void processContapezzi()
{
- Console.WriteLine(as_msg); if (as_msg.StartsWith("Are you sure ?"))
- {
- return "0\n"; // 0 [RET]
- }
-
- if (as_msg.StartsWith("Load data?"))
- {
- return "1\n"; // 1 [RET]
- }
-
- return null;
- };
- int retLoad = KAWASAKI_ref.load(prgPath, "/Q"); // LOAD/Q default.as[RET]
- }
- }
-
-
- #region Metodi specifici (da verificare/completare in implementazione)
-
-
- ///
- /// Effettua vero processing contapezzi
- ///
- public override void processContapezzi()
- {
- if (utils.CRB("enableContapezzi"))
- {
- try
- {
- // hard coded... !!!FARE!!! rivedere megio conf
- contapezziPLC = pzCounter;
- // verifico quale modalità sia richiesta: STD (6711) oppure BIT (Custom, con indicazione area)
- if (cIobConf.optPar.Count > 0 && !string.IsNullOrEmpty(getOptPar("PZCOUNT_MODE")))
- {
+ if (utils.CRB("enableContapezzi"))
+ {
+ try
+ {
+ // hard coded... !!!FARE!!! rivedere megio conf
+ contapezziPLC = pzCounter;
+ // verifico quale modalità sia richiesta: STD (6711) oppure BIT (Custom, con indicazione area)
+ if (cIobConf.optPar.Count > 0 && !string.IsNullOrEmpty(getOptPar("PZCOUNT_MODE")))
+ {
#if false
string memAddr = getOptPar("PZCOUNT_MODE");
if (memAddr.StartsWith("STD"))
@@ -748,15 +837,18 @@ namespace IOB_WIN
byte valB = RawInput[areaCounter.indiceMem];
outputVal = valB;
break;
+
case "W":
ushort valW = S7.Net.Types.Word.FromByteArray(RawInput.Skip(areaCounter.indiceMem).Take(2).ToArray());
outputVal = valW;
break;
+
case "DW":
uint valDW = S7.Net.Types.Word.FromByteArray(RawInput.Skip(areaCounter.indiceMem).Take(4).ToArray());
outputVal = valDW;
break;
+
default:
break;
}
@@ -769,246 +861,213 @@ namespace IOB_WIN
}
}
stopwatch.Stop();
- }
+ }
#endif
- }
- }
- catch (Exception exc)
- {
- lgError(exc, "Errore in contapezzi KAWASAKI");
- }
- }
- }
- ///
- /// Effettua processing del recupero delle OVERRIDE (spindle, feedrate, rapid)
- ///
- public override void processOverride()
- {
- }
- ///
- /// Effettua lettura semafori principale
- /// Parametri da aggiornare x display in form
- ///
- public override void readSemafori(ref newDisplayData currDispData)
- {
- try
- {
- if (verboseLog)
- {
- lgInfo("inizio read semafori");
- }
- currDispData.semIn = Semaforo.SV;
-
- // effettuo TUTTE le letture
- threadOk = commThreadOk;
- cStatus = currBitmapStatus;
- cSignals = currBitmapSignals;
- contapezziPLC = pzCounter;
- // decodifica e gestione
- decodeToBaseBitmap();
- decodeOtherData();
- reportRawInput(ref currDispData);
- // se trova ok thread --> aggiorno ultima lettura
- if (threadOk)
- {
- lastReadPLC = DateTime.Now;
- }
- }
- catch
- {
- currDispData.semIn = Semaforo.SR;
- }
- }
-
- ///
- /// Effettua decodifica aree memoria alla bitmap usata x MAPO
- ///
- private void decodeToBaseBitmap()
- {
- // init a zero...
- B_input = 0;
- /* -----------------------------------------------------
- * bitmap MAPO
- * B0: POWER_ON
- * B1: RUN
- * B2: pzCount
- * B3: allarme
- * B4: manuale
- * B5: emergenza
- * B6: error prog
- * B7: auto mode
- ----------------------------------------------------- */
- // bit 0 (poweron) imposto a 1 SE connected...
- B_input = KAWASAKI_ref.IsConnected ? 1 : 0;
- // RUN
- if (cStatus[2] == '1')
- {
- B_input += (1 << 1);
- }
- // ERROR prog/macchina
- if (cStatus[3] == '1')
- {
- B_input += (1 << 6);
- }
- // allarme
- if (cStatus[4] == '1')
- {
- B_input += (1 << 3);
- }
- // Automatico (porta chiusa)
- if (cStatus[6] == '1' || cStatus[1] == '1')
- {
- B_input += (1 << 4);
- }
- // NON EMERGENZA (1=armed, 0=triggered)
- if (cStatus[5] == '0')
- {
- B_input += (1 << 5);
- }
-
- // process ODL e contapezzi
- string currODL = "";
- try
- {
- currODL = utils.callUrl(urlGetCurrODL);
- // solo SE HO un ODL...
- if (string.IsNullOrEmpty(currODL) || currODL == "0")
- {
- if (periodicLog)
- {
- lgInfo(string.Format("Kawasaki | Lettura ODL andata a vuoto: currODL: {0}", currODL));
- }
- }
- else
- { // se variato o scaduto timeout log...
- if (periodicLog || (currIdxODL.ToString() != currODL))
- {
- lgInfo(string.Format("Kawasaki | Lettura ODL, currODL: {0} --> currIdxODL prec: {1}", currODL, currIdxODL));
- }
- // provo a salvare nuovo ODL
- int.TryParse(currODL, out currIdxODL);
- }
- }
- catch (Exception exc)
- {
- if (DateTime.Now.Subtract(lastWarnODL).TotalSeconds > 15)
- {
- lgError(exc, "Errore in fase di chiamata URL x ODL corrente | URL chiamato: {0}", urlGetCurrODL);
- lastWarnODL = DateTime.Now;
- }
- }
- if (!string.IsNullOrEmpty(currODL))
- {
- if (currODL != "0")
- {
- // ora processo il contapezzi...
- // controllo se è passato intervallo minimo tra 2 controlli/elaborazioni x distanziare invio e ridurre letture
- if (DateTime.Now >= lastPzCountSend.AddMilliseconds(pzCountDelay))
- {
- // se sono differenti MOSTRO...
- if (contapezziPLC != contapezziIOB)
- {
- // registro contapezzi
- lgInfo($"Differenza Contapezzi CNC/IOB: contapezziPLC: {contapezziPLC} | contapezziIOB: {contapezziIOB}");
+ }
+ }
+ catch (Exception exc)
+ {
+ lgError(exc, "Errore in contapezzi KAWASAKI");
+ }
}
- // verifico se variato contapezzi... e se passato ritardo minimo...
- if (contapezziPLC > contapezziIOB)
- {
- // salvo nuovo contapezzi (incremento di 1...) + richiesta refresh conteggio
- contapezziIOB++;
- needRefreshPzCount = true;
- // salvo in semaforo!
- B_input += (1 << 2);
- // registro contapezzi
- lgInfo($"contapezziPLC KAWASAKI: {contapezziPLC} | contapezziIOB {contapezziIOB}");
- }
- else if (contapezziIOB > contapezziPLC)
- {
- lgInfo($"Contapezzi IOB > CNC --> NON INVIO (contapezziPLC: {contapezziPLC} < contapezziIOB: {contapezziIOB})");
- }
-
- // invio a server contapezzi (aggiornato)
- string retVal = utils.callUrl(urlSetPzCount + contapezziIOB.ToString());
- // verifica se tutto OK
- if (retVal != contapezziIOB.ToString())
- {
- // errore salvataggio contapezzi
- lgInfo($"Errore salvataggio Contapezzi KAWASAKI: contapezziPLC {contapezziPLC} | contapezziIOB {contapezziIOB} | risposta: {retVal}");
- // rileggo il counter pezzi da server
- pzCntReload(true);
- }
- // resetto timer...
- lastPzCountSend = DateTime.Now;
- }
}
- else
+
+ ///
+ /// Effettua processing del recupero delle OVERRIDE (spindle, feedrate, rapid)
+ ///
+ public override void processOverride()
{
- lgError("Attenzione non trovato ODL --> currODL = 0");
}
- }
- else
- {
- if (DateTime.Now >= lastPzCountSend.AddMilliseconds(pzCountDelay))
+
+ ///
+ /// Effettua lettura semafori principale
+ /// Parametri da aggiornare x display in form
+ ///
+ public override void readSemafori(ref newDisplayData currDispData)
{
- lgError($"Attenzione: mancanza ODL non procedo con gestione contapezzi. contapezziPLC KAWASAKI {contapezziPLC} | contapezziIOB {contapezziIOB}");
- // resetto timer...
- lastPzCountSend = DateTime.Now;
+ try
+ {
+ if (verboseLog)
+ {
+ lgInfo("inizio read semafori");
+ }
+ currDispData.semIn = Semaforo.SV;
+
+ // effettuo TUTTE le letture
+ threadOk = commThreadOk;
+ cStatus = currBitmapStatus;
+ cSignals = currBitmapSignals;
+ contapezziPLC = pzCounter;
+ // decodifica e gestione
+ decodeToBaseBitmap();
+ decodeOtherData();
+ reportRawInput(ref currDispData);
+ // se trova ok thread --> aggiorno ultima lettura
+ if (threadOk)
+ {
+ lastReadPLC = DateTime.Now;
+ }
+ }
+ catch
+ {
+ currDispData.semIn = Semaforo.SR;
+ }
}
- }
- // log opzionale!
- if (verboseLog)
- {
- lgInfo($"Trasformazione B_input: {B_input}");
- }
- }
+ ///
+ /// Effettua reset del contapezzi
+ ///
+ ///
+ public override bool resetcontapezziPLC()
+ {
+ bool answ = false;
+ // ...SE abilitato da conf IOB
+ if (cIobConf.optPar.Count > 0 && getOptPar("ENABLE_PZ_RESET") == "TRUE")
+ {
+ // scrivo valore 0 x il contapezzi
+ try
+ {
+ pzCounter = 0;
+ }
+ catch (Exception exc)
+ {
+ lgError(exc, "Errore in RESET contapezzi KAWASAKI");
+ connectionOk = false;
+ }
+ answ = true;
+ }
+ else
+ {
+ lgError("Impossibile effettuare RESET contapezzi KAWASAKI, mancanza parametro OPT:ENABLE_PZ_RESET");
+ }
+ return answ;
+ }
- ///
- /// Decodifica il resto dell'area x i dati accessori (allarmi, ...)
- ///
- private void decodeOtherData()
- {
- if (verboseLog)
- {
+ ///
+ /// Effettua IMPOSTAZIONE FORZATA del contapezzi
+ ///
+ ///
+ public override bool setcontapezziPLC(int newPzCount)
+ {
+ bool answ = false;
+ // ...SE abilitato da conf IOB
+ if (cIobConf.optPar.Count > 0 && getOptPar("ENABLE_PZ_RESET") == "TRUE")
+ {
+ // scrivo valore 0 x il contapezzi
+ try
+ {
+ pzCounter = newPzCount;
+ }
+ catch (Exception exc)
+ {
+ lgError(exc, "Errore in SET contapezzi KAWASAKI");
+ connectionOk = false;
+ }
+ answ = true;
+ }
+ else
+ {
+ lgError("Impossibile effettuare SET contapezzi KAWASAKI, mancanza parametro OPT:ENABLE_PZ_RESET");
+ }
+ return answ;
+ }
- }
- }
+ ///
+ /// Override connessione
+ ///
+ public override void tryConnect()
+ {
+ if (!connectionOk)
+ {
+ // controllo che il ping sia stato tentato almeno pingTestSec fa...
+ if (DateTime.Now.Subtract(lastPING).TotalSeconds > utils.CRI("pingTestSec"))
+ {
+ if (verboseLog || periodicLog)
+ {
+ lgInfo("KAWASAKI: ConnKO - tryConnect");
+ }
+ // in primis salvo data ping...
+ lastPING = DateTime.Now;
+ // se passa il ping faccio il resto...
+ if (testPingMachine == IPStatus.Success)
+ {
+ string szStatusConnection = "";
+ try
+ {
+ // ora provo connessione...
+ parentForm.commPlcActive = true;
+ string connPar = string.Format("TCP {0}", cIobConf.cncIpAddr);
+ KAWASAKI_ref.connect(connPar);
+ parentForm.commPlcActive = false;
+ lgInfo("szStatusConnection: " + KAWASAKI_ref.IsConnected);
+ connectionOk = true;
+ // verifico se sta girando
+ if (connectionOk)
+ {
+ if (adpRunning)
+ {
+ lgInfo("Connessione OK");
+ }
+ }
+ else
+ {
+ lgError("Impossibile procedere, connessione mancante...");
+ }
+ }
+ catch (Exception exc)
+ {
+ lgFatal(string.Format("Errore nella connessione all'adapter KAWASAKI: {0}{1}{2}", szStatusConnection, Environment.NewLine, exc));
+ connectionOk = false;
+ lgInfo(string.Format("Eccezione in TryConnect, Adapter KAWASAKI NON running, pausa di {0} msec prima di ulteriori tentativi di riconnessione", utils.CRI("waitRecMSec")));
+ }
+ }
+ else
+ {
+ // loggo no risposta ping ...
+ connectionOk = false;
+ needRefresh = true;
+ if (verboseLog || periodicLog)
+ {
+ lgInfo(string.Format("Attenzione: KAWASAKI controllo PING fallito per IP {0}", cIobConf.cncIpAddr));
+ }
+ }
+ }
+ }
+ // se non è ancora connesso faccio processing memoria caso disconnesso...
+ if (!connectionOk)
+ {
+ // processo semafori ed invio...
+ processMemoryDiscon();
+ }
+ }
- ///
- /// Recupero programma in lavorazione
- ///
- ///
- public override string getPrgName()
- {
- // valore non presente in vers default... se gestito fare override
- string prgName = "";
- return prgName;
- }
- ///
- /// Recupero info sistema generiche
- ///
- public override Dictionary getSysInfo()
- {
- // valore non presente in vers default... se gestito fare override
- Dictionary outVal = new Dictionary();
- outVal.Add("MACHINE", machineName);
- return outVal;
- }
- ///
- /// Recupero dati dinamici...
- ///
- public override Dictionary getDynData()
- {
- // valore non presente in vers default... se gestito fare override
- Dictionary outVal = new Dictionary();
- outVal.Add("LAST_MISS", lastMissRobot);
- outVal.Add("LAST_TC", lastTC.ToString());
- outVal.Add("NUM_PZ_PREL", pzPrelevati.ToString());
- outVal.Add("NUM_PZ_LAV", pzCounter.ToString());
- outVal.Add("CURR_SIGNALS", currBitmapSignals.ToString());
- return outVal;
- }
+ ///
+ /// Override disconnessione
+ ///
+ public override void tryDisconnect()
+ {
+ if (connectionOk)
+ {
+ connectionOk = false;
+ string szStatusConnection = "";
+ try
+ {
+ KAWASAKI_ref.disconnect();
+ lgInfo(szStatusConnection);
+ lgInfo("Effettuata disconnessione adapter KAWASAKI!");
+ }
+ catch (Exception exc)
+ {
+ lgFatal(exc, "Errore nella disconnessione dall'adapter KAWASAKI");
+ }
+ }
+ else
+ {
+ lgError("IMPOSSIBILE effettuare disconnessione KAWASAKI: Connessione non disponibile...");
+ }
+ needRefresh = true;
+ }
- #endregion
- }
-}
+ #endregion Public Methods
+ }
+}
\ No newline at end of file