Continuo fix letture KAWASAKI

This commit is contained in:
Samuele E. Locatelli
2018-11-28 13:00:23 +01:00
parent ef6fd2e974
commit b481b39a48
3 changed files with 198 additions and 55 deletions
+11
View File
@@ -150,6 +150,17 @@ namespace IOB_UT
return Convert.ToString(theNumber, 2).PadLeft(minimumDigits, '0');
}
/// <summary>
/// Effettua reverse delal stringa
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static string reverseStr(string s)
{
char[] arr = s.ToCharArray();
Array.Reverse(arr);
return new string(arr);
}
/// <summary>
/// imposta un bit al valore richiesto duplicando il valore IN come OUT
/// </summary>
/// <param name="original">valore originale da aggiornare</param>
+186 -54
View File
@@ -35,11 +35,11 @@ namespace IOB_WIN
/// <summary>
/// Variabile STATUS corrente (8bit INT)
/// </summary>
protected int cStatus;
protected string cStatus;
/// <summary>
/// Variabile SIGNALS corrente (8bit INT)
/// </summary>
protected int cSignals;
protected string cSignals;
/// <summary>
/// Num pezzi prelevati
/// </summary>
@@ -87,23 +87,23 @@ namespace IOB_WIN
{
// connect ok
resDataArray = KAWASAKI_ref.command("where", 3000); // WHERE [RET]
Console.WriteLine(resDataArray[0]);
// [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
// 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;
threadOk = commThreadOk;
#if true
#if false
if (KAWASAKI_ref.IsConnected)
{
resDataArray = KAWASAKI_ref.command("TYPE TASK (1004)", 3000); // thread 4 ok --> " 1\r\n"
}
#endif
macName = machineName;
macName = machineName;
#if false
if (KAWASAKI_ref.IsConnected)
{
@@ -111,8 +111,8 @@ namespace IOB_WIN
}
#endif
cStatus = currBitmapStatus;
cSignals = currBitmapSignals;
cStatus = currBitmapStatus;
cSignals = currBitmapSignals;
#if false
if (KAWASAKI_ref.IsConnected)
{
@@ -121,9 +121,9 @@ namespace IOB_WIN
}
#endif
lastCountCNC = pzCounter;
numPzPrel = pzPrelevati;
lastRecTC = lastTC;
lastCountCNC = pzCounter;
numPzPrel = pzPrelevati;
lastRecTC = lastTC;
#if false
if (KAWASAKI_ref.IsConnected)
{
@@ -133,7 +133,7 @@ namespace IOB_WIN
}
#endif
lastMissRobot = lastMission;
lastMissRobot = lastMission;
#if false
if (KAWASAKI_ref.IsConnected)
{
@@ -751,7 +751,7 @@ namespace IOB_WIN
if (KAWASAKI_ref.IsConnected)
{
resDataArray = KAWASAKI_ref.command("TYPE i_prelevati", 3000); // num pz prelevati --> "0\r\n"
int.TryParse(resDataArray[0].ToString().Replace("/n", "").Replace("/r", ""), out answ);
int.TryParse(resDataArray[1].ToString().Replace("\n", "").Replace("\r", ""), out answ);
}
return answ;
}
@@ -767,7 +767,7 @@ namespace IOB_WIN
if (KAWASAKI_ref.IsConnected)
{
resDataArray = KAWASAKI_ref.command("TYPE r_tempo", 3000); // ultimo TCiclo rilevato --> " 349.19\r\n"
decimal.TryParse(resDataArray[0].ToString().Replace("/n", "").Replace("/r", ""), out answ);
decimal.TryParse(resDataArray[1].ToString().Replace("\n", "").Replace("\r", ""), out answ);
}
return answ;
}
@@ -783,7 +783,7 @@ namespace IOB_WIN
if (KAWASAKI_ref.IsConnected)
{
resDataArray = KAWASAKI_ref.command("TYPE i_cicli", 3000); // num cicli depositati/fatti --> " 0\r\n"
int.TryParse(resDataArray[0].ToString().Replace("/n", "").Replace("/r", ""), out answ);
int.TryParse(resDataArray[1].ToString().Replace("\n", "").Replace("\r", ""), out answ);
}
return answ;
}
@@ -809,7 +809,7 @@ namespace IOB_WIN
{
int retVal = 0;
resDataArray = KAWASAKI_ref.command("TYPE TASK (1004)", 3000); // thread 4 ok --> " 1\r\n"
int.TryParse(resDataArray[0].ToString().Replace("/n", "").Replace("/r", ""), out retVal);
int.TryParse(resDataArray[1].ToString().Replace("\n", "").Replace("\r", ""), out retVal);
answ = (retVal == 1);
}
return answ;
@@ -826,7 +826,7 @@ namespace IOB_WIN
if (KAWASAKI_ref.IsConnected)
{
resDataArray = KAWASAKI_ref.command("TYPE $id_true", 3000); // id macchina --> "BX100N-B001 Sn. 2366\r\n"
answ = resDataArray[0].ToString().Replace("/n", "").Replace("/r", "");
answ = resDataArray[1].ToString().Replace("\n", "").Replace("\r", "");
}
return answ;
}
@@ -842,66 +842,72 @@ namespace IOB_WIN
if (KAWASAKI_ref.IsConnected)
{
resDataArray = KAWASAKI_ref.command("TYPE $exe", 3000); // missione --> "\r\n" (vuoto, no missione)
answ = resDataArray[0].ToString().Replace("/n", "").Replace("/r", "");
answ = resDataArray[1].ToString().Replace("\n", "").Replace("\r", "");
}
return answ;
}
}
/// <summary>
/// Restituisce stato macchina nel formato IOB:
/// Restituisce stato macchina nel formato (da sx a dx):
/// B0: POWER_ON
/// B1: RUN
/// B2: pzCount
/// B3: allarme
/// B4: manuale
/// B5: emergenza
/// B6: ???
/// B7: ???
/// B1: AUTO
/// B2: RUN
/// B3: ERROR
/// B4: ALLARME
/// B5: EMERGENZA OK
/// B6: PORTA CHIUSA
/// B7: PRONTO AL LOAD
/// </summary>
protected int currBitmapStatus
protected string currBitmapStatus
{
get
{
int answ = 0;
string answ = "";
if (KAWASAKI_ref.IsConnected)
{
resDataArray = KAWASAKI_ref.command("TYPE $status", 3000); // status --> "0|0|1|0|0|1|0|0\r\n"
string szBitmap = resDataArray[0].ToString().Replace("/n", "").Replace("/r", "").Replace("|", "");
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);
answ = Convert.ToInt32(szBitmap, 2);
#endif
}
return answ;
}
}
/// <summary>
/// Restituisce SEGNALI macchina nel formato:
/// B0: ???
/// B1: ???
/// B2: ???
/// B3: ???
/// B4: ???
/// B5: ???
/// B6: ???
/// B7: ???
/// B0: Transfer in auto
/// B1: Punzonatrice in AUTO
/// B2: Barriera tavola
/// B3:
/// B4:
/// B5:
/// B6:
/// B7:
/// </summary>
protected int currBitmapSignals
protected string currBitmapSignals
{
get
{
int answ = 0;
string answ = "";
if (KAWASAKI_ref.IsConnected)
{
resDataArray = KAWASAKI_ref.command("TYPE $signal", 3000); // segnali --> "1|0|1|1|1|0|0|0\r\n"
string szBitmap = resDataArray[0].ToString().Replace("/n", "").Replace("/r", "").Replace("|", "");
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);
answ = Convert.ToInt32(szBitmap, 2);
#endif
}
return answ;
}
}
/// <summary>
/// Effettua salvataggio del programma corrente
/// </summary>
@@ -1054,12 +1060,138 @@ namespace IOB_WIN
// effettuo TUTTE le letture
threadOk = commThreadOk;
// imposto valore status bitmap...
B_input = currBitmapStatus;
lastCountCNC = pzCounter;
cStatus = currBitmapStatus;
cSignals = currBitmapSignals;
lastCountCNC = pzCounter;
// decodifica e gestione
decodeToBaseBitmap();
decodeOtherData();
}
/// <summary>
/// Effettua decodifica aree memoria alla bitmap usata x MAPO
/// </summary>
private void decodeToBaseBitmap()
{
#if false
// init a zero...
B_input = 0;
// FAPE: leggo i primi 2 WORD x decodifica stato e posizione...
ushort valStatus = S7.Net.Types.Word.FromByteArray(RawInput.Skip(0).Take(2).ToArray());
ushort valPosit = S7.Net.Types.Word.FromByteArray(RawInput.Skip(2).Take(2).ToArray());
statoMacchina _stMacch = ((statoMacchina)valStatus);
posizioneSequenza _posSeq = ((posizioneSequenza)valPosit);
/* -----------------------------------------------------
* bitmap MAPO
* B0: POWER_ON
* B1: RUN
* B2: pzCount
* B3: allarme
* B4: manuale
* B5: emergenza
----------------------------------------------------- */
// bit 0 (poweron) imposto a 1 SE connected...
B_input = currPLC.IsConnected ? 1 : 0;
// controllo stato macchina x impostare altri bit...
switch (_stMacch)
{
case statoMacchina.EMERGENZA_INSERITA:
B_input &= (1 << 5);
break;
case statoMacchina.COMUNICAZIONE_ASSENTE:
case statoMacchina.AVARIA_ARIA:
case statoMacchina.AVARIA_PRESSIONE_OLIO:
case statoMacchina.AVARIA_LIVELLO_OLIO:
case statoMacchina.AVARIA_TEMPERATURA_OLIO:
case statoMacchina.AVARIA_MOTORE_POMPA_IDRAULICA:
case statoMacchina.AVARIA_MOTORE_RAFFREDDO_IDRAULICA:
case statoMacchina.AVARIA_SINCRONISMO_PORTE:
case statoMacchina.AVARIA_LIBERA:
case statoMacchina.ATTIVAZIONE_IN_CORSO:
B_input &= (1 << 3);
break;
case statoMacchina.MODO_MANUALE_ATTREZZAGGIO:
B_input &= (1 << 4);
break;
case statoMacchina.CICLO_IN_CORSO:
B_input &= (1 << 1);
break;
case statoMacchina.MODO_AUTOMATICO_LOCALE:
case statoMacchina.MODO_AUTOMATICO_ROBOT:
B_input &= ~(1 << 5);
break;
case statoMacchina.LIBERO:
default:
break;
}
string currODL = "";
try
{
currODL = utils.callUrl(urlGetCurrODL);
lgInfo(string.Format("Lettura ODL, {0} --> {1}", currIdxODL, currODL));
// 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 (currODL != null && currODL != "" && 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))
{
// verifico se variato contapezzi... e se passato ritardo minimo...
if (lastCountCNC > contapezzi)
{
// salvo nuovo contapezzi (incremento di 1...)
contapezzi++;
// salvo in semaforo!
B_input &= (1 << 2);
// !!!FARE!!! verifica metodo
//B_input += 1 << 2;
}
// registro contapezzi
lgInfo(string.Format("Contapezzi SIEMENS: {0} | Contapezzi interno {1}", lastCountCNC, contapezzi));
// invio a server contapezzi (aggiornato)
string retVal = utils.callUrl(urlSetPzCount + contapezzi.ToString());
// verifica se tutto OK
if (retVal != "OK")
{
// errore salvataggio contapezzi
lgInfo(string.Format("Errore salvataggio Contapezzi SIEMENS {0} | Contapezzi interno {1} | Errore salvataggio: {2}", lastCountCNC, contapezzi, retVal));
}
// resetto timer...
lastPzCountSend = DateTime.Now;
}
}
else
{
if (DateTime.Now >= lastPzCountSend.AddMilliseconds(pzCountDelay))
{
lgInfo(string.Format("Attenzione: mancanza ODL non procedo con gestione contapezzi. Contapezzi SIEMENS {0} | Contapezzi interno {1}", lastCountCNC, contapezzi));
// resetto timer...
lastPzCountSend = DateTime.Now;
}
}
// log opzionale!
if (verboseLog)
{
lgInfo(string.Format("Trasformazione B_input: {0}", B_input));
}
#endif
}
/// <summary>
/// Decodifica il resto dell'area x i dati accessori (allarmi, ...)
/// </summary>
Vendored
+1 -1
View File
@@ -16,7 +16,7 @@ pipeline {
/* calcolo numero versione... diverso x branch MASTER/DEVELOP */
script {
withEnv(['NEXT_BUILD_NUMBER=310']) {
withEnv(['NEXT_BUILD_NUMBER=311']) {
// env.versionNumber = VersionNumber(versionNumberString : '1.18.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true)
env.versionNumber = VersionNumber(versionNumberString : '1.18.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true, overrideBuildsAllTime: '${NEXT_BUILD_NUMBER}')
env.APP_NAME = 'MAPO-IOB-WIN'