Modifica Citizen x evitare disconnessione immediata in caso di problemi di rete/lettura
This commit is contained in:
@@ -738,6 +738,16 @@ namespace IOB_UT_NEXT
|
||||
/// </summary>
|
||||
public string apiUrl { get; set; } = "";
|
||||
|
||||
/// <summary>
|
||||
/// Periodo minimo di campionamento in ms x lettura dati frequenti stato/semafori...
|
||||
/// </summary>
|
||||
public int samplePeriod { get; set; } = 1000;
|
||||
|
||||
/// <summary>
|
||||
/// Numero di errori dopo cui fare una vera disconnesisone con report poweroff della macchina
|
||||
/// </summary>
|
||||
public int connErrorMax { get; set; } = 5;
|
||||
|
||||
/// <summary>
|
||||
/// Elenco delle chiamate x ID / struttura
|
||||
/// </summary>
|
||||
|
||||
@@ -173,6 +173,8 @@
|
||||
},
|
||||
"timeOutSec": 60,
|
||||
"apiUrl": "http://192.168.80.61:8733/DRIVER_MES/rest/",
|
||||
"samplePeriod": 1000,
|
||||
"numErrDisconnect": 5,
|
||||
"CallList": {
|
||||
"GetConnection": {
|
||||
"Method": "Get",
|
||||
|
||||
@@ -192,7 +192,7 @@ namespace IOB_WIN_NEXT.IobRest
|
||||
// chiamo metodo connect
|
||||
var checkResp = ExecuteCallGet(GetUrlResource("GetConnection"), true);
|
||||
// forse va eliminato...
|
||||
lgInfo($"GetConnection | {checkResp}");
|
||||
lgInfo($"GetConnection | {checkResp} (Base.tryConnect)");
|
||||
if (checkResp != null && checkResp.ToLower().Contains("true"))
|
||||
{
|
||||
connectionOk = true;
|
||||
@@ -255,11 +255,23 @@ namespace IOB_WIN_NEXT.IobRest
|
||||
/// </summary>
|
||||
protected string apiUrl = "http://localhost:8733";
|
||||
|
||||
/// <summary>
|
||||
/// Num err connessioni corrente
|
||||
/// </summary>
|
||||
protected int connErrCur = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Max num err connesisone prima di disconnettere
|
||||
/// </summary>
|
||||
protected int connErrMax = 5;
|
||||
|
||||
/// <summary>
|
||||
/// LookUpTable informazioni raccolte
|
||||
/// </summary>
|
||||
protected Dictionary<string, string> RestDataLUT = new Dictionary<string, string>();
|
||||
|
||||
protected int samplePeriod = 1000;
|
||||
|
||||
/// <summary>
|
||||
/// Timeout chiamate REST
|
||||
/// </summary>
|
||||
@@ -593,6 +605,9 @@ namespace IOB_WIN_NEXT.IobRest
|
||||
// inizializzo dal file di conf le variabili necessarie...
|
||||
tOutSec = restParams.timeOutSec;
|
||||
apiUrl = restParams.apiUrl ?? "http://localhost:8733";
|
||||
// sistemo parametri specali come samplePeriod ed errori conn...
|
||||
samplePeriod = restParams.samplePeriod;
|
||||
connErrMax = restParams.connErrorMax;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+109
-97
@@ -36,6 +36,8 @@ namespace IOB_WIN_NEXT.IobRest
|
||||
{
|
||||
setupRestConf(getOptPar("REST_CONF"));
|
||||
}
|
||||
// sistemo conf errori e samplePeriod...
|
||||
|
||||
lgInfo("Rest - 02");
|
||||
// fixme todo levare forzatura test iniziale...
|
||||
if (EnableTest)
|
||||
@@ -48,67 +50,6 @@ namespace IOB_WIN_NEXT.IobRest
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Effettua scrittura set di parametri del job e restitusice task eseguito...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private bool SetJobDataCitizen()
|
||||
{
|
||||
bool answ = false;
|
||||
string varValue = "";
|
||||
CitizenJobData jobReq = new CitizenJobData();
|
||||
QtyData qtyReq = new QtyData();
|
||||
|
||||
// Token!
|
||||
varValue = RestLutGet("token");
|
||||
jobReq.token = varValue;
|
||||
qtyReq.token = varValue;
|
||||
|
||||
// Commessa
|
||||
varValue = getCurrProdData("setComm", "");
|
||||
jobReq.ordercode = varValue;
|
||||
|
||||
// Articolo
|
||||
varValue = getCurrProdData("setArt", "");
|
||||
jobReq.itemcode = varValue;
|
||||
jobReq.itemdescription = $"ART: {varValue}";
|
||||
|
||||
// Qty
|
||||
varValue = getCurrProdData("setPzComm", "");
|
||||
int pzReq = 0;
|
||||
int.TryParse(varValue, out pzReq);
|
||||
jobReq.piecestodo = pzReq;
|
||||
qtyReq.value = pzReq;
|
||||
|
||||
try
|
||||
{
|
||||
// preparo payload
|
||||
string jobPayload = JsonConvert.SerializeObject(jobReq);
|
||||
// faccio chiamata POST x invio
|
||||
var rawResp = ExecuteCallPost(GetUrlResource("SetJobData"), jobPayload);
|
||||
bool.TryParse(rawResp, out answ);
|
||||
// se andatae se ho la chaive x invio abilitata invio anche la qty richiesta...
|
||||
if (answ)
|
||||
{
|
||||
string urlNeedQty = GetUrlResource("SetNeededQuantity");
|
||||
if (string.IsNullOrEmpty(urlNeedQty))
|
||||
{
|
||||
lgInfo($"Set NeedQty NON abilitato, non invio");
|
||||
}
|
||||
else
|
||||
{
|
||||
jobPayload = JsonConvert.SerializeObject(qtyReq);
|
||||
var rawRespQty = ExecuteCallPost(GetUrlResource("SetNeededQuantity"), jobPayload);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
lgError($"Eccezione in SetJobDataCitizen{Environment.NewLine}{exc}");
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implementazione custom esecuzione task specifici
|
||||
/// </summary>
|
||||
@@ -250,7 +191,7 @@ namespace IOB_WIN_NEXT.IobRest
|
||||
LadderIO ladderResp = new LadderIO();
|
||||
// in primis testo che sia connessa...
|
||||
var checkResp = ExecuteCallGet(GetUrlResource("GetConnection"), true);
|
||||
lgInfo($"GetConnection | {checkResp}");
|
||||
lgInfo($"GetConnection | {checkResp} | Citizen.processContapezzi");
|
||||
bool.TryParse(checkResp, out checkMachine);
|
||||
|
||||
// proseguo SOLO SE macchina OK, altrimenti disconnetto...
|
||||
@@ -310,7 +251,7 @@ namespace IOB_WIN_NEXT.IobRest
|
||||
|
||||
// chiamo metodo connect
|
||||
var checkResp = ExecuteCallGet(GetUrlResource("GetConnection"), true);
|
||||
lgInfo($"GetConnection | {checkResp}");
|
||||
lgInfo($"GetConnection | {checkResp} | Citizen.tryConnect");
|
||||
bool.TryParse(checkResp, out checkMachine);
|
||||
if (checkMachine)
|
||||
{
|
||||
@@ -318,12 +259,12 @@ namespace IOB_WIN_NEXT.IobRest
|
||||
queueInEnabCurr = true;
|
||||
if (adpRunning)
|
||||
{
|
||||
lgInfo("Connessione OK");
|
||||
lgInfo("Connessione Citizen OK");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lgError($"Errore check connessione | checkResp: {checkResp}");
|
||||
lgError($"Errore check connessione Citizen | checkResp: {checkResp}");
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
@@ -377,6 +318,22 @@ namespace IOB_WIN_NEXT.IobRest
|
||||
#endregion Public Properties
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Struttura info JobData da inviare x setup
|
||||
/// </summary>
|
||||
internal class CitizenJobData
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
public string itemcode { get; set; } = "";
|
||||
public string itemdescription { get; set; } = "";
|
||||
public string ordercode { get; set; } = "";
|
||||
public int piecestodo { get; set; } = 0;
|
||||
public string token { get; set; } = "";
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Struttura info restituiti x lettura Ladder
|
||||
/// </summary>
|
||||
@@ -393,6 +350,19 @@ namespace IOB_WIN_NEXT.IobRest
|
||||
#endregion Public Properties
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Struttura info QtyData da inviare x impostazioni quantità
|
||||
/// </summary>
|
||||
internal class QtyData
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
public string token { get; set; } = "";
|
||||
public int value { get; set; } = 0;
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Struttura dato AlarmState (singolo, corrente)
|
||||
/// </summary>
|
||||
@@ -408,34 +378,6 @@ namespace IOB_WIN_NEXT.IobRest
|
||||
#endregion Public Properties
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Struttura info JobData da inviare x setup
|
||||
/// </summary>
|
||||
internal class CitizenJobData
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
public string token { get; set; } = "";
|
||||
public string ordercode { get; set; } = "";
|
||||
public string itemcode { get; set; } = "";
|
||||
public string itemdescription { get; set; } = "";
|
||||
public int piecestodo { get; set; } = 0;
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
/// <summary>
|
||||
/// Struttura info QtyData da inviare x impostazioni quantità
|
||||
/// </summary>
|
||||
internal class QtyData
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
public string token { get; set; } = "";
|
||||
public int value { get; set; } = 0;
|
||||
|
||||
#endregion Public Properties
|
||||
}
|
||||
/// <summary>
|
||||
/// Struttura risposta x scrittura parametri numerici (es qty)
|
||||
/// </summary>
|
||||
@@ -546,12 +488,14 @@ namespace IOB_WIN_NEXT.IobRest
|
||||
LadderIO ladderResp = new LadderIO();
|
||||
// in primis testo che sia connessa...
|
||||
var checkResp = ExecuteCallGet(GetUrlResource("GetConnection"), true);
|
||||
lgInfo($"GetConnection | {checkResp}");
|
||||
lgInfo($"GetConnection | {checkResp} | Citizen.refreshData");
|
||||
bool.TryParse(checkResp, out checkMachine);
|
||||
|
||||
// proseguo SOLO SE macchina OK, altrimenti disconnetto...
|
||||
if (checkMachine)
|
||||
{
|
||||
//riporto err conn a zero
|
||||
connErrCur = 0;
|
||||
// faccio refresh token comunque...
|
||||
string token = ExecuteCallGet(GetUrlResource("GetToken"));
|
||||
token = token.Replace("\"", "");
|
||||
@@ -597,7 +541,16 @@ namespace IOB_WIN_NEXT.IobRest
|
||||
}
|
||||
else
|
||||
{
|
||||
tryDisconnect();
|
||||
// verifico se devo disconnettere
|
||||
if (connErrCur >= connErrMax)
|
||||
{
|
||||
connErrCur = 0;
|
||||
tryDisconnect();
|
||||
}
|
||||
else
|
||||
{
|
||||
connErrCur++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -612,8 +565,6 @@ namespace IOB_WIN_NEXT.IobRest
|
||||
|
||||
private DateTime lastRestRefreshData = DateTime.Now;
|
||||
|
||||
private int samplePeriod = 1000;
|
||||
|
||||
#endregion Private Fields
|
||||
|
||||
#region Private Properties
|
||||
@@ -700,6 +651,67 @@ namespace IOB_WIN_NEXT.IobRest
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Effettua scrittura set di parametri del job e restitusice task eseguito...
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private bool SetJobDataCitizen()
|
||||
{
|
||||
bool answ = false;
|
||||
string varValue = "";
|
||||
CitizenJobData jobReq = new CitizenJobData();
|
||||
QtyData qtyReq = new QtyData();
|
||||
|
||||
// Token!
|
||||
varValue = RestLutGet("token");
|
||||
jobReq.token = varValue;
|
||||
qtyReq.token = varValue;
|
||||
|
||||
// Commessa
|
||||
varValue = getCurrProdData("setComm", "");
|
||||
jobReq.ordercode = varValue;
|
||||
|
||||
// Articolo
|
||||
varValue = getCurrProdData("setArt", "");
|
||||
jobReq.itemcode = varValue;
|
||||
jobReq.itemdescription = $"ART: {varValue}";
|
||||
|
||||
// Qty
|
||||
varValue = getCurrProdData("setPzComm", "");
|
||||
int pzReq = 0;
|
||||
int.TryParse(varValue, out pzReq);
|
||||
jobReq.piecestodo = pzReq;
|
||||
qtyReq.value = pzReq;
|
||||
|
||||
try
|
||||
{
|
||||
// preparo payload
|
||||
string jobPayload = JsonConvert.SerializeObject(jobReq);
|
||||
// faccio chiamata POST x invio
|
||||
var rawResp = ExecuteCallPost(GetUrlResource("SetJobData"), jobPayload);
|
||||
bool.TryParse(rawResp, out answ);
|
||||
// se andatae se ho la chaive x invio abilitata invio anche la qty richiesta...
|
||||
if (answ)
|
||||
{
|
||||
string urlNeedQty = GetUrlResource("SetNeededQuantity");
|
||||
if (string.IsNullOrEmpty(urlNeedQty))
|
||||
{
|
||||
lgInfo($"Set NeedQty NON abilitato, non invio");
|
||||
}
|
||||
else
|
||||
{
|
||||
jobPayload = JsonConvert.SerializeObject(qtyReq);
|
||||
var rawRespQty = ExecuteCallPost(GetUrlResource("SetNeededQuantity"), jobPayload);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
lgError($"Eccezione in SetJobDataCitizen{Environment.NewLine}{exc}");
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test Chiamata Citizen
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user