riportate modifice x FANUC (gestione UT "unificata")

This commit is contained in:
Samuele E. Locatelli
2017-04-26 12:33:40 +02:00
parent f7ddda9fc8
commit 5c3665f5ec
+74 -134
View File
@@ -851,7 +851,7 @@ 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);
}
/// <summary>
@@ -1408,147 +1408,87 @@ namespace MTC_Adapter
parentForm.dataMonitor_1 += sb.ToString();
}
/// <summary>
/// procedura di lettura (Multipla) dati da memoria x caricare dati utensile
/// Procedura di processing lettura memoria x DatiUt - Step 4
/// </summary>
/// <param name="maxNumOp">num max di teste da recuperare</param>
private void getDatiUt_Fanuc(int maxNumOp)
/// <param name="int32Mem"></param>
/// <param name="j"></param>
/// <returns></returns>
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;
}
/// <summary>
/// Procedura di processing lettura memoria x DatiUt - Step 3b
/// </summary>
/// <param name="int8Mem"></param>
/// <param name="j"></param>
/// <returns></returns>
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;
}
/// <summary>
/// Procedura di processing lettura memoria x DatiUt - Step 3a
/// </summary>
/// <param name="tabFam_FamUt"></param>
/// <returns></returns>
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;
}
/// <summary>
/// Procedura di processing lettura memoria x DatiUt - Step 2b
/// </summary>
/// <param name="int16Mem"></param>
/// <param name="j"></param>
/// <returns></returns>
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;
}
/// <summary>
/// Procedura di processing lettura memoria x DatiUt - Step 2a
/// </summary>
/// <param name="tabUt_UT"></param>
/// <returns></returns>
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;
}
/// <summary>
/// Procedura di processing lettura memoria x DatiUt - Step 1
/// </summary>
/// <param name="elencoUtMem"></param>
/// <returns></returns>
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()
{
base.getPath();