ok byte (quasi tutti), NON riporta le WORD...

This commit is contained in:
Samuele E. Locatelli
2017-03-08 15:59:04 +01:00
parent 1cae0ab961
commit aebb2a812f
+273 -117
View File
@@ -132,11 +132,12 @@ namespace MTC_Adapter
byteNum = 0;
bitNum = 0;
}
vettoreConf[numRiga] = decodeBitData(linea, utils.CRC("testCharSep"), "0", byteNum, 1, bitNum);
vettoreConf[numRiga] = decodeBitData(linea, utils.CRC("testCharSep"), "", byteNum, 1, bitNum);
}
else
{
vettoreConf[numRiga] = decodeOtherData(linea, utils.CRC("testCharSep"), "", 0, memSize);
//int.TryParse(linea.Split(utils.CRC("testCharSep"))[0], out byteNum);
vettoreConf[numRiga] = decodeOtherData(linea, utils.CRC("testCharSep"), "", 1, memSize);
}
numRiga++;
}
@@ -230,14 +231,6 @@ namespace MTC_Adapter
}
}
/// <summary>
/// Effettuo lettura memorie strobe/status
/// </summary>
public override void getStrobeAndAckStatus()
{
base.getStrobeAndAckStatus();
}
public override void getGlobalData()
{
base.getGlobalData();
@@ -246,112 +239,276 @@ namespace MTC_Adapter
StringBuilder sb = new StringBuilder();
//2017.03.07 RIVEDERE DA QUI x lettura globale
if (connectionOk)
// 2017.03.07 IN BLOCCO processo TUTTI i valori della memoria WORD/DWORD...
if (useIotMem)
{
// leggo TUTTO il blocco di memoria
inizio = DateTime.Now;
ncDevice.ReadBuffer();
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R-PLC_FullMemoryRead", ncDevice.PLC_MemoryRead.Length), DateTime.Now.Subtract(inizio).Ticks);
if (connectionOk)
{
// leggo TUTTO il blocco di memoria
inizio = DateTime.Now;
ncDevice.ReadBufferWord();
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-PLC_IOT-Word", ncDevice.PLC_MemoryAreaIOT_Word.Length), DateTime.Now.Subtract(inizio).Ticks);
inizio = DateTime.Now;
ncDevice.ReadBufferDWord();
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-PLC_IOT-DWord", ncDevice.PLC_MemoryAreaIOT_DWord.Length), DateTime.Now.Subtract(inizio).Ticks);
}
else
{
lg.Error("Errore connessione mancante in getGlobalData");
}
int numero = 0;
int byteNum = 0;
// Processing area WORD
for (int i = 0; i < mapIOT_Word.Length; i++)
{
int.TryParse(mapIOT_Word[i].memAddr, out byteNum);
if (mapIOT_Word[i].varName.StartsWith("IOT_S_MD_"))
{
// recupero NUMERO
try
{
numero = Convert.ToInt32(mapIOT_Word[i].varName.Replace("IOT_S_MD_", ""));
vettUnOp[numero - 1].mUnOpSpeed.Value = ncDevice.PLC_MemoryAreaIOT_Word[i];
}
catch
{
// se non trovo --> 1!
numero = 1;
}
}
else if (mapIOT_Word[i].varName.StartsWith("IOT_T_MD_"))
{
// recupero NUMERO
try
{
numero = Convert.ToInt32(mapIOT_Word[i].varName.Replace("IOT_T_MD_", ""));
vettUnOp[numero - 1].mUnOpToolId.Value = ncDevice.PLC_MemoryAreaIOT_Word[i];
}
catch
{
// se non trovo --> 1!
numero = 1;
}
}
else if (mapIOT_Word[i].varName.StartsWith("IOT_C_H_MD_"))
{
// recupero NUMERO
try
{
numero = Convert.ToInt32(mapIOT_Word[i].varName.Replace("IOT_C_H_MD_", ""));
vettUnOp[numero - 1].mUnOpAccTime.Value = ncDevice.PLC_MemoryAreaIOT_Word[i];
}
catch
{
// se non trovo --> 1!
numero = 1;
}
}
}
#if false
// dati override feed/speed...
Byte v82 = ncDevice.PLC_MemoryAreaV[14];
Byte v83 = ncDevice.PLC_MemoryAreaV[15];
// 2 byte x speed da copiare...
byte[] tmpByte = new byte[2];
Buffer.BlockCopy(ncDevice.PLC_MemoryAreaV, 16, tmpByte, 0, 2);
short v84 = BitConverter.ToInt16(tmpByte, 0);
// lista allarmi PLC/CNC
Byte v87 = ncDevice.PLC_MemoryAreaV[19]; // Allarme CN (almeno 1?!?)
// -------------------------------------------
// recupero dati Feed/Speed/override
// FeedOver: 100% = 213 (il pannello è 0-120 --> 0-255, quindi 100% è 100/120*255=213)
FeedRateOver = Convert.ToInt16((decimal)(v82 * 100) / 213);
sb.AppendLine(string.Format("FeedRateOver: {0} %", FeedRateOver));
// SpeedOver: 50% = 128
SpeedRateOver = Convert.ToInt16((decimal)(v83 * 100) / 255);
sb.AppendLine(string.Format("SpeedRateOver: {0} %", SpeedRateOver));
// Speed S5000 OK!!!
SpeedRate = v84;
sb.AppendLine(string.Format("SpeedRate: {0} rpm", SpeedRate));
// -------------------------------------------
// da recuperare da qualche parte?!?
UnOpLoad = 0;
sb.AppendLine(string.Format("Load: {0}", UnOpLoad));
// -------------------------------------------
// recupero dati dai contatori EOK
bool needSave = false;
// ore totali accensione
int MinMaccOn = (int)ncDevice.PLC_MemoryAreaEOK[0];
int OreMaccOn = (int)ncDevice.PLC_MemoryAreaEOK[1];
istOreMaccOn = OreMaccOn + (double)MinMaccOn / 60;
needSave = procOreMaccOn(needSave);
// ore totali lavoro
int MinMaccLav = (int)ncDevice.PLC_MemoryAreaEOK[2];
int OreMaccLav = (int)ncDevice.PLC_MemoryAreaEOK[3];
istOreMaccLav = OreMaccLav + (double)MinMaccLav / 60;
needSave = procOreMaccLav(needSave);
// giri totali degli elettromandrini!
for (int i = 0; i < currAdpConf.nUnOp; i++)
{
istGiriElettrom[i] = (uint)ncDevice.PLC_MemoryAreaEOK[4 + i];
}
needSave = procGiriTotUnOp(needSave);
needSave = procNumCU(needSave);
// per ESA calcolo a mano se ci sia stato impiego assi... salvo le istantanee mov precedenti...
double precVal = 0;
DateTime adesso = DateTime.Now;
TimeSpan accumTime = adesso.Subtract(lastChekAccumTimeAxis);
// spostamento totale assi!
for (int i = 0; i < 3; i++)
{
precVal = istDistMovAssi[i];
// primo è metri, secondo km (moltiplico x 1000)
istDistMovAssi[i] = ncDevice.PLC_MemoryAreaEOK[8 + 2 * i] + ncDevice.PLC_MemoryAreaEOK[9 + 2 * i] * 1000;
// verifico SE devo aggiungere tempo lavoro sui singoli assi (se si sono spostati...) -- è a maglie LARGHE poiché leggiamo lo "scatto ogni metro" x cui se campiono velocemente ma assi muovono lenti prendo MENO tempo di movimento del reale...
if (precVal != istDistMovAssi[i])
{
istAccTimeAssi[i] += accumTime.TotalHours;
}
}
// salvo valore lastChekAccumTimeAxis
lastChekAccumTimeAxis = adesso;
needSave = procMovTotAssi(needSave);
needSave = procAccTimeAssi(needSave);
needSave = procProgrName(needSave);
needSave = procPartId(needSave);
needSave = procPzProd(needSave);
needSave = procNumInvAssi(needSave);
needSave = procVacPump(needSave);
needSave = procVacAct(needSave);
needSave = procLubro(needSave);
// salvo se necessario!
if (needSave) parentForm.persistData();
// -------------------------------------------
// copio allarmi in vettore generale AlarFlags (dove lo gestisce)...
Buffer.BlockCopy(ncDevice.PLC_MemoryAreaAllarmi, 0, AlarmFlags, 0, ncDevice.PLC_MemoryAreaAllarmi.Length);
//Buffer.BlockCopy(ncDevice.PLC_MemAreaAlarm_tmp, 0, AlarmFlags, 0, ncDevice.PLC_MemAreaAlarm_tmp.Length);
parentForm.dataMonitor = sb.ToString();
#endif
}
else
{
lg.Error("Errore connessione mancante in getStrobeAndAckStatus");
}
// dati override feed/speed...
Byte v82 = ncDevice.PLC_MemoryAreaV[14];
Byte v83 = ncDevice.PLC_MemoryAreaV[15];
// 2 byte x speed da copiare...
byte[] tmpByte = new byte[2];
Buffer.BlockCopy(ncDevice.PLC_MemoryAreaV, 16, tmpByte, 0, 2);
short v84 = BitConverter.ToInt16(tmpByte, 0);
// lista allarmi PLC/CNC
Byte v87 = ncDevice.PLC_MemoryAreaV[19]; // Allarme CN (almeno 1?!?)
// -------------------------------------------
// recupero dati Feed/Speed/override
// FeedOver: 100% = 213 (il pannello è 0-120 --> 0-255, quindi 100% è 100/120*255=213)
FeedRateOver = Convert.ToInt16((decimal)(v82 * 100) / 213);
sb.AppendLine(string.Format("FeedRateOver: {0} %", FeedRateOver));
// SpeedOver: 50% = 128
SpeedRateOver = Convert.ToInt16((decimal)(v83 * 100) / 255);
sb.AppendLine(string.Format("SpeedRateOver: {0} %", SpeedRateOver));
// Speed S5000 OK!!!
SpeedRate = v84;
sb.AppendLine(string.Format("SpeedRate: {0} rpm", SpeedRate));
// -------------------------------------------
// da recuperare da qualche parte?!?
UnOpLoad = 0;
sb.AppendLine(string.Format("Load: {0}", UnOpLoad));
// -------------------------------------------
// recupero dati dai contatori EOK
bool needSave = false;
// ore totali accensione
int MinMaccOn = (int)ncDevice.PLC_MemoryAreaEOK[0];
int OreMaccOn = (int)ncDevice.PLC_MemoryAreaEOK[1];
istOreMaccOn = OreMaccOn + (double)MinMaccOn / 60;
needSave = procOreMaccOn(needSave);
// ore totali lavoro
int MinMaccLav = (int)ncDevice.PLC_MemoryAreaEOK[2];
int OreMaccLav = (int)ncDevice.PLC_MemoryAreaEOK[3];
istOreMaccLav = OreMaccLav + (double)MinMaccLav / 60;
needSave = procOreMaccLav(needSave);
// giri totali degli elettromandrini!
for (int i = 0; i < currAdpConf.nUnOp; i++)
{
istGiriElettrom[i] = (uint)ncDevice.PLC_MemoryAreaEOK[4 + i];
}
needSave = procGiriTotUnOp(needSave);
needSave = procNumCU(needSave);
// per ESA calcolo a mano se ci sia stato impiego assi... salvo le istantanee mov precedenti...
double precVal = 0;
DateTime adesso = DateTime.Now;
TimeSpan accumTime = adesso.Subtract(lastChekAccumTimeAxis);
// spostamento totale assi!
for (int i = 0; i < 3; i++)
{
precVal = istDistMovAssi[i];
// primo è metri, secondo km (moltiplico x 1000)
istDistMovAssi[i] = ncDevice.PLC_MemoryAreaEOK[8 + 2 * i] + ncDevice.PLC_MemoryAreaEOK[9 + 2 * i] * 1000;
// verifico SE devo aggiungere tempo lavoro sui singoli assi (se si sono spostati...) -- è a maglie LARGHE poiché leggiamo lo "scatto ogni metro" x cui se campiono velocemente ma assi muovono lenti prendo MENO tempo di movimento del reale...
if (precVal != istDistMovAssi[i])
if (connectionOk)
{
istAccTimeAssi[i] += accumTime.TotalHours;
// leggo TUTTO il blocco di memoria
inizio = DateTime.Now;
ncDevice.ReadBuffer();
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R-PLC_FullMemoryRead", ncDevice.PLC_MemoryRead.Length), DateTime.Now.Subtract(inizio).Ticks);
}
else
{
lg.Error("Errore connessione mancante in getGlobalData");
}
// dati override feed/speed...
Byte v82 = ncDevice.PLC_MemoryAreaV[14];
Byte v83 = ncDevice.PLC_MemoryAreaV[15];
// 2 byte x speed da copiare...
byte[] tmpByte = new byte[2];
Buffer.BlockCopy(ncDevice.PLC_MemoryAreaV, 16, tmpByte, 0, 2);
short v84 = BitConverter.ToInt16(tmpByte, 0);
// lista allarmi PLC/CNC
Byte v87 = ncDevice.PLC_MemoryAreaV[19]; // Allarme CN (almeno 1?!?)
// -------------------------------------------
// recupero dati Feed/Speed/override
// FeedOver: 100% = 213 (il pannello è 0-120 --> 0-255, quindi 100% è 100/120*255=213)
FeedRateOver = Convert.ToInt16((decimal)(v82 * 100) / 213);
sb.AppendLine(string.Format("FeedRateOver: {0} %", FeedRateOver));
// SpeedOver: 50% = 128
SpeedRateOver = Convert.ToInt16((decimal)(v83 * 100) / 255);
sb.AppendLine(string.Format("SpeedRateOver: {0} %", SpeedRateOver));
// Speed S5000 OK!!!
SpeedRate = v84;
sb.AppendLine(string.Format("SpeedRate: {0} rpm", SpeedRate));
// -------------------------------------------
// da recuperare da qualche parte?!?
UnOpLoad = 0;
sb.AppendLine(string.Format("Load: {0}", UnOpLoad));
// -------------------------------------------
// recupero dati dai contatori EOK
bool needSave = false;
// ore totali accensione
int MinMaccOn = (int)ncDevice.PLC_MemoryAreaEOK[0];
int OreMaccOn = (int)ncDevice.PLC_MemoryAreaEOK[1];
istOreMaccOn = OreMaccOn + (double)MinMaccOn / 60;
needSave = procOreMaccOn(needSave);
// ore totali lavoro
int MinMaccLav = (int)ncDevice.PLC_MemoryAreaEOK[2];
int OreMaccLav = (int)ncDevice.PLC_MemoryAreaEOK[3];
istOreMaccLav = OreMaccLav + (double)MinMaccLav / 60;
needSave = procOreMaccLav(needSave);
// giri totali degli elettromandrini!
for (int i = 0; i < currAdpConf.nUnOp; i++)
{
istGiriElettrom[i] = (uint)ncDevice.PLC_MemoryAreaEOK[4 + i];
}
needSave = procGiriTotUnOp(needSave);
needSave = procNumCU(needSave);
// per ESA calcolo a mano se ci sia stato impiego assi... salvo le istantanee mov precedenti...
double precVal = 0;
DateTime adesso = DateTime.Now;
TimeSpan accumTime = adesso.Subtract(lastChekAccumTimeAxis);
// spostamento totale assi!
for (int i = 0; i < 3; i++)
{
precVal = istDistMovAssi[i];
// primo è metri, secondo km (moltiplico x 1000)
istDistMovAssi[i] = ncDevice.PLC_MemoryAreaEOK[8 + 2 * i] + ncDevice.PLC_MemoryAreaEOK[9 + 2 * i] * 1000;
// verifico SE devo aggiungere tempo lavoro sui singoli assi (se si sono spostati...) -- è a maglie LARGHE poiché leggiamo lo "scatto ogni metro" x cui se campiono velocemente ma assi muovono lenti prendo MENO tempo di movimento del reale...
if (precVal != istDistMovAssi[i])
{
istAccTimeAssi[i] += accumTime.TotalHours;
}
}
// salvo valore lastChekAccumTimeAxis
lastChekAccumTimeAxis = adesso;
needSave = procMovTotAssi(needSave);
needSave = procAccTimeAssi(needSave);
needSave = procProgrName(needSave);
needSave = procPartId(needSave);
needSave = procPzProd(needSave);
needSave = procNumInvAssi(needSave);
needSave = procVacPump(needSave);
needSave = procVacAct(needSave);
needSave = procLubro(needSave);
// salvo se necessario!
if (needSave) parentForm.persistData();
// -------------------------------------------
// copio allarmi in vettore generale AlarFlags (dove lo gestisce)...
Buffer.BlockCopy(ncDevice.PLC_MemoryAreaAllarmi, 0, AlarmFlags, 0, ncDevice.PLC_MemoryAreaAllarmi.Length);
//Buffer.BlockCopy(ncDevice.PLC_MemAreaAlarm_tmp, 0, AlarmFlags, 0, ncDevice.PLC_MemAreaAlarm_tmp.Length);
parentForm.dataMonitor = sb.ToString();
}
// salvo valore lastChekAccumTimeAxis
lastChekAccumTimeAxis = adesso;
needSave = procMovTotAssi(needSave);
needSave = procAccTimeAssi(needSave);
needSave = procProgrName(needSave);
needSave = procPartId(needSave);
needSave = procPzProd(needSave);
needSave = procNumInvAssi(needSave);
needSave = procVacPump(needSave);
needSave = procVacAct(needSave);
needSave = procLubro(needSave);
// salvo se necessario!
if (needSave) parentForm.persistData();
// -------------------------------------------
// copio allarmi in vettore generale AlarFlags (dove lo gestisce)...
Buffer.BlockCopy(ncDevice.PLC_MemoryAreaAllarmi, 0, AlarmFlags, 0, ncDevice.PLC_MemoryAreaAllarmi.Length);
//Buffer.BlockCopy(ncDevice.PLC_MemAreaAlarm_tmp, 0, AlarmFlags, 0, ncDevice.PLC_MemAreaAlarm_tmp.Length);
parentForm.dataMonitor = sb.ToString();
}
/// <summary>
/// Path percorso file prod
@@ -510,8 +667,9 @@ namespace MTC_Adapter
// 2017.03.07 IN BLOCCO processo TUTTI i valori della memoria BYTE...
if (useIotMem)
{
inizio = DateTime.Now;
ncDevice.ReadBufferByte();
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-PLC_IOT-Byte", ncDevice.PLC_MemoryAreaIOT_Byte.Length), DateTime.Now.Subtract(inizio).Ticks);
// accodo dati path in DataMonitor......
StringBuilder sb = new StringBuilder();
// uno ad uno vado a inserirli nella mappa dei dati dell'adapter...
@@ -580,13 +738,13 @@ namespace MTC_Adapter
// vado poi a gestire le variabili BYTE
else if (mapIOT_Byte[i].dataType == "BYTE")
{
int.TryParse(mapIOT_Byte[i].memAddr, out bitNum);
int.TryParse(mapIOT_Byte[i].memAddr, out byteNum);
if (mapIOT_Byte[i].varName == "IOT_OVRF")
{
// -------------------------------------------
// recupero dati FeedOverride
// FeedOver: 100% = 213 (il pannello è 0-120 --> 0-255, quindi 100% è 100/120*255=213)
FeedRateOver = Convert.ToInt16((decimal)(ncDevice.PLC_MemoryAreaIOT_Byte[bitNum] * 100) / 213);
FeedRateOver = Convert.ToInt16((decimal)(ncDevice.PLC_MemoryAreaIOT_Byte[byteNum] * 100) / 213);
sb.AppendLine(string.Format("FeedRateOver: {0} %", FeedRateOver));
}
else if (mapIOT_Byte[i].varName == "IOT_OVRS")
@@ -594,7 +752,7 @@ namespace MTC_Adapter
// -------------------------------------------
// recupero dati SpeedOverride
// SpeedOver: 50% = 128
SpeedRateOver = Convert.ToInt16((decimal)(ncDevice.PLC_MemoryAreaIOT_Byte[bitNum] * 100) / 255);
SpeedRateOver = Convert.ToInt16((decimal)(ncDevice.PLC_MemoryAreaIOT_Byte[byteNum] * 100) / 255);
sb.AppendLine(string.Format("SpeedRateOver: {0} %", SpeedRateOver));
}
else if (mapIOT_Byte[i].varName.StartsWith("IOT_LUB_"))
@@ -611,7 +769,7 @@ namespace MTC_Adapter
}
if (mapIOT_Byte[i].varName.EndsWith("_STA"))
{
if (ncDevice.PLC_MemoryAreaIOT_Byte[bitNum] != 0)
if (ncDevice.PLC_MemoryAreaIOT_Byte[byteNum] != 0)
{
status = "EMPTY";
}
@@ -760,12 +918,10 @@ namespace MTC_Adapter
public override void getUnOp()
{
base.getUnOp();
// cicl su UnOp
for (int i = 0; i < currAdpConf.nUnOp; i++)
{
vettUnOp[i].mUnOpToolId.Value = (int)ncDevice.PLC_MemoryAreaEOK[31];
vettUnOp[i].mUnOpSpeedOverr.Value = SpeedRateOver;
}
}