MOdifica altro comportamento lato acquisitore x controllo connesione e periodo sospensione tentativi...

This commit is contained in:
Samuele E. Locatelli
2019-01-10 17:30:57 +01:00
parent 1e3eb78e20
commit 22fd471bbe
7 changed files with 103 additions and 128 deletions
+45 -6
View File
@@ -14,9 +14,18 @@ namespace IOB_UT
public class baseUtils
{
/// <summary>
/// classe logger
/// Indicazione VETO invio a server sino alla data-ora indicata
/// </summary>
public static Logger lg;
public static DateTime dtVetoSend = DateTime.Now;
/// <summary>
/// oggetto static x gestione baseUtils
/// </summary>
public static baseUtils mgr = new baseUtils();
/// <summary>
/// Fattore di riduzione dei log
/// </summary>
public static int logReduxFactor = 10;
/// <summary>
/// legge conf in formato char
@@ -302,6 +311,7 @@ namespace IOB_UT
}
catch (Exception exc)
{
Logger lg = LogManager.GetCurrentClassLogger();
lg.Info(exc, string.Format("Errore in scrittura file {0}", file));
}
}
@@ -380,6 +390,7 @@ namespace IOB_UT
}
catch (Exception exc)
{
Logger lg = LogManager.GetCurrentClassLogger();
lg.Error(exc);
}
return sIpAddr;
@@ -411,10 +422,38 @@ namespace IOB_UT
public static string callUrl(string URL)
{
string answ = "";
var client = new WebClient();
client.Headers.Add("user-agent", CRS("appName"));
answ = client.DownloadString(URL);
// restituisco valore!
// controllo se ho un VETO all'invio...
if (dtVetoSend < DateTime.Now)
{
var client = new WebClient();
client.Headers.Add("user-agent", CRS("appName"));
try
{
answ = client.DownloadString(URL);
}
catch (Exception exc)
{
// imposto un veto per pauseSendMSec
int pauseSendMSec = CRI("pauseSendMSec");
// aggiungo NOISE... +/- 20%
Random rnd = new Random();
int noise = rnd.Next(1, pauseSendMSec / 5);
pauseSendMSec += noise - (pauseSendMSec / 10);
// imposto veto
dtVetoSend = DateTime.Now.AddMilliseconds(pauseSendMSec);
// log ogni
Logger lg = LogManager.GetCurrentClassLogger();
lg.Info("Errore in callURL: impostato attesa di {0} ms prima della prossima chiamata", pauseSendMSec);
logReduxFactor--;
if (logReduxFactor <= 0)
{
lg.Error("Eccezione in esecuzione callURL: {0}{1}{2}", URL, Environment.NewLine, exc);
logReduxFactor = 10;
}
}
// restituisco valore!
}
return answ;
}
}
+6 -6
View File
@@ -124,8 +124,8 @@
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 60F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 55F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 25F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 50F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 45F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 45F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 35F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 35F));
this.tableLayoutPanel1.Controls.Add(this.restart, 0, 0);
@@ -166,7 +166,7 @@
this.label6.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(985, 0);
this.label6.Location = new System.Drawing.Point(970, 0);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(48, 37);
this.label6.TabIndex = 76;
@@ -282,9 +282,9 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.lQueueLen.AutoSize = true;
this.lQueueLen.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lQueueLen.Location = new System.Drawing.Point(1039, 0);
this.lQueueLen.Location = new System.Drawing.Point(1024, 0);
this.lQueueLen.Name = "lQueueLen";
this.lQueueLen.Size = new System.Drawing.Size(19, 37);
this.lQueueLen.Size = new System.Drawing.Size(39, 37);
this.lQueueLen.TabIndex = 77;
this.lQueueLen.Text = "#";
this.lQueueLen.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
@@ -432,7 +432,7 @@
this.lblDataProc.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.lblDataProc.AutoSize = true;
this.lblDataProc.Location = new System.Drawing.Point(965, 0);
this.lblDataProc.Location = new System.Drawing.Point(950, 0);
this.lblDataProc.Name = "lblDataProc";
this.lblDataProc.Size = new System.Drawing.Size(13, 37);
this.lblDataProc.TabIndex = 79;
+20 -5
View File
@@ -221,7 +221,7 @@ namespace IOB_WIN
// verifico server online...
if (iobObj.checkServerAlive)
{
// segnalo reboot (programma)...
// segnalo reboot (programma)...
iobObj.callUrl(iobObj.urlReboot);
}
else
@@ -689,14 +689,29 @@ namespace IOB_WIN
}
}
/// <summary>
/// Visualizzazione stato di comunicazione attiva con PLC
/// Visualizzazione stato di comunicazione attiva con PLC:
/// 0 = NO PING
/// 1 = PING OK
/// 2 = MP/IO OK
/// </summary>
public bool commSrvActive
public int commSrvActive
{
set
{
// se true --> comunica/verde, altrimenti grigio
lblSrvUrl.ForeColor = value ? Color.SeaGreen : Color.Red;
switch (value)
{
case 0:
lblSrvUrl.ForeColor = Color.Red;
break;
case 1:
lblSrvUrl.ForeColor = Color.OrangeRed;
break;
case 2:
lblSrvUrl.ForeColor = Color.SeaGreen;
break;
default:
break;
}
statusStrip1.Refresh();
}
}
+1
View File
@@ -31,6 +31,7 @@
<add key="watchdogMaxSec" value="90"/>
<add key="disconMaxSec" value="60"/>
<add key="defIOB" value="2999"/>
<add key="pauseSendMSec" value="1000"/>
<!--Modalità DEMO: DemoOUT indica che NON invia davvero al server e DemoIN che simula e NON legge da PLC-->
<add key="DemoIn" value="false"/>
<add key="DemoInSample" value="false"/>
+18 -102
View File
@@ -328,6 +328,10 @@ namespace IOB_WIN
/// </summary>
protected bool needRefresh = true;
/// <summary>
/// Indicazione VETO invio a server sino alla data-ora indicata
/// </summary>
public DateTime dtVetoSend = DateTime.Now;
/// <summary>
/// inizializzo l'oggetto sulla form SULLA BASE DEL FILE DI CONFIGURAZIONE letto
/// </summary>
/// <param name="caller"></param>
@@ -1147,97 +1151,6 @@ namespace IOB_WIN
{
}
#if false
#region area simulazione
/// <summary>
/// lettura memoria in SIMULAZIONE
/// </summary>
public void simReadMem()
{
if (lastSim == null)
{
lastSim = DateTime.Now;
}
// simulazione complessa (basata su samples dei parametri effettivi...)
if (utils.CRB("DemoInSample"))
{
if (numSim >= 0)
{
// verifico se la coda di simulazione sia piena altrimenti la RICARICO...
if (QueueSIM.Count == 0)
{
leggiSimFile();
numSim--;
}
// processo la coda di simulazione (stacco ed accodo 1 valore...)
B_input = QueueSIM.Dequeue();
countSim++;
// ogni 5 loggo...
if (countSim % 5 == 0)
{
lgInfo("Read {0} sim data", countSim);
}
}
else
{
// fermo tutto!
parentForm.sIN = Semaforo.SR;
parentForm.fermaAdapter(false);
}
}
// simulazione semplice (counter crescente)
else
{
// se passato 1 sec genero NUOV num casuale e lo metto nel bit strobe... ogni 2 sec...
if (DateTime.Now.Subtract(lastSim).TotalMilliseconds > 100)
{
countSim++;
if (countSim > 255)
{
countSim = 0;
}
B_input = countSim;
}
}
lastSim = DateTime.Now;
}
/// <summary>
/// legge ed accoda file Sim in QueueSIM
/// </summary>
private void leggiSimFile()
{
int totRighe = 0;
string fileName = utils.simDataFile;
string linea;
totRighe = File.ReadLines(fileName).Count();
lgInfo("File SIM: TROVATE {0} righe", totRighe);
// ora conto righe effettive...
totRighe = 0;
// carica da file...
StreamReader file = new StreamReader(fileName);
// leggo 1 linea alla volta...
int valore = 0;
while ((linea = file.ReadLine()) != null)
{
// SE non è un commento...
if (linea.Substring(0, 1) != ";")
{
//elencoAllarmi[rumRiga] = decodeAlarmLine(linea, ':');
Int32.TryParse(linea, out valore);
QueueSIM.Enqueue(valore);
totRighe++;
}
}
// chiudo file
file.Close();
lgInfo("File SIM: LETTE {0} righe", totRighe);
}
#endregion
#endif
#region IOB METHODS
/// <summary>
@@ -1436,6 +1349,7 @@ namespace IOB_WIN
answ += string.Format(@"&&dtEve={0}&&dtCurr={1:yyyyMMddHHmmssfff}&&cnt={2}", valori[0], DateTime.Now, valori[3]);
return answ;
}
/// <summary>
/// Effettua chiamata URL e restituisce risultato
/// </summary>
@@ -1443,12 +1357,7 @@ namespace IOB_WIN
/// <returns></returns>
public string callUrl(string URL)
{
string answ = "";
var client = new WebClient();
client.Headers.Add("user-agent", utils.CRS("appName"));
answ = client.DownloadString(URL);
// restituisco valore!
return answ;
return utils.callUrl(URL);
}
/// <summary>
/// test ping all'indirizzo impostato nei parametri
@@ -1469,7 +1378,7 @@ namespace IOB_WIN
return answ;
}
/// <summary>
/// Verifica se il server sia ALIVE
/// Verifica se il server sia ALIVE (tramite PING)
/// </summary>
public bool checkServerAlive
{
@@ -1502,12 +1411,12 @@ namespace IOB_WIN
if (answ)
{
lgInfo("SERVER ONLINE");
parentForm.commSrvActive = true;
parentForm.commSrvActive = 1;
}
else
{
lgInfo("SERVER OFFLINE");
parentForm.commSrvActive = false;
parentForm.commSrvActive = 0;
}
// salvo nuovo status...
MPOnline = answ;
@@ -1558,6 +1467,15 @@ namespace IOB_WIN
// salvo nuovo status...
IobOnline = answ;
}
// fix colore
if (answ)
{
parentForm.commSrvActive = 2;
}
else
{
parentForm.commSrvActive = 1;
}
return answ;
}
}
@@ -1625,10 +1543,8 @@ namespace IOB_WIN
//controllo se è passato oltre watchdog e non ho inviato nulla --> RE-INVIO (ultimo inviato)!!!!
if (DateTime.Now.Subtract(lastWatchDog).TotalSeconds > utils.CRI("watchdogMaxSec"))
{
string wdStatus = "elapsed";
string sVal = string.Format("[WDST]{0}", wdStatus);
// chiamo accodamento...
accodaFLog(sVal, qEncodeFLog("WDST", wdStatus));
lastWatchDog = DateTime.Now;
+12 -8
View File
@@ -206,16 +206,20 @@ namespace IOB_WIN
}
if (sendContapezzi)
{
// invio a server contapezzi (aggiornato)
string retVal = utils.callUrl(urlSetPzCount + contapezzi.ToString());
// verifica se tutto OK
if (retVal != "OK")
// controllo se ALMENO sia pingabile il server
if (checkServerAlive)
{
// errore salvataggio contapezzi
lgInfo(string.Format("Errore salvataggio Contapezzi SIMULAZIONE {0} | Errore salvataggio: {1}", contapezzi, retVal));
// 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 SIMULAZIONE {0} | Errore salvataggio: {1}", contapezzi, retVal));
}
// resetto timer...
lastPzCountSend = DateTime.Now;
}
// resetto timer...
lastPzCountSend = DateTime.Now;
}
}
}
Vendored
+1 -1
View File
@@ -16,7 +16,7 @@ pipeline {
/* calcolo numero versione... diverso x branch MASTER/DEVELOP */
script {
withEnv(['NEXT_BUILD_NUMBER=332']) {
withEnv(['NEXT_BUILD_NUMBER=333']) {
// env.versionNumber = VersionNumber(versionNumberString : '2.1.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true)
env.versionNumber = VersionNumber(versionNumberString : '2.1.${BUILD_DATE_FORMATTED, "yyMM"}.${BUILDS_ALL_TIME}', projectStartDate : '2006-01-01', skipFailedBuilds: true, overrideBuildsAllTime: '${NEXT_BUILD_NUMBER}')
env.APP_NAME = 'MAPO-IOB-WIN'