continuo fixing SIEMENS e porting tra osai/siemens a generic metodi comuni...
This commit is contained in:
@@ -2181,8 +2181,39 @@ namespace MTC_Adapter
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gestione STROBE --> ACK per codici M/S/T
|
||||
/// </summary>
|
||||
/// <param name="currStrobe">byte di strobe corrente</param>
|
||||
/// <param name="bitNum">0/1/2</param>
|
||||
/// <param name="retACK_DW1">vettore da restituire di ACK</param>
|
||||
/// <param name="memShift">shift memoria x buffer dati da leggere</param>
|
||||
/// <param name="MemBlock">Vettore completo dei valori + buffer code M/S/T</param>
|
||||
/// <param name="Coda">Quale coda: M/S/T</param>
|
||||
/// <param name="idxPath">Path (0,1,...)</param>
|
||||
public void gestStrobeCodMST(StFlag8 currStrobe, int bitNum, ref byte[] retACK_DW1, int memShift, byte[] MemBlock, string Coda, int idxPath)
|
||||
{
|
||||
int numEv = 0;
|
||||
int codEv = 0;
|
||||
if (currStrobe.HasFlag((StFlag8)Math.Pow(2, bitNum)))
|
||||
{
|
||||
// verifico sia > 0 il numero di valori da leggere - indice 0 sull'area...
|
||||
numEv = BitConverter.ToUInt16(MemBlock, 2 * memShift);
|
||||
if (numEv > 0)
|
||||
{
|
||||
// il num ev rappresenta quanti slot 16bit (da 2 byte) sono stati valorizzati, VA FATTO CICLO E LETTI TUTTI
|
||||
for (int i = 0; i < numEv; i++)
|
||||
{
|
||||
// leggo valore Codice
|
||||
codEv = BitConverter.ToUInt16(MemBlock, 2 * (i + 2 + memShift));
|
||||
// accodo evento Codice
|
||||
appendCodeMST(Coda, codEv.ToString(), idxPath);
|
||||
}
|
||||
}
|
||||
// memorizzo allarme nel vettore ack....
|
||||
retACK_DW1 = utils.setBitOnStFlag(retACK_DW1, true, bitNum);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// verifica gli status attivi
|
||||
/// </summary>
|
||||
|
||||
@@ -560,39 +560,6 @@ namespace MTC_Adapter
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// Gestione STROBE --> ACK per codici M/S/T
|
||||
/// </summary>
|
||||
/// <param name="currStrobe">byte di strobe corrente</param>
|
||||
/// <param name="bitNum">0/1/2</param>
|
||||
/// <param name="retACK_DW1">vettore da restituire di ACK</param>
|
||||
/// <param name="memShift">shift memoria x buffer dati da leggere</param>
|
||||
/// <param name="MemBlock">Vettore completo dei valori + buffer code M/S/T</param>
|
||||
/// <param name="Coda">Quale coda: M/S/T</param>
|
||||
/// <param name="idxPath">Path (0,1,...)</param>
|
||||
private void gestStrobeCodMST(StFlag8 currStrobe, int bitNum, ref byte[] retACK_DW1, int memShift, byte[] MemBlock, string Coda, int idxPath)
|
||||
{
|
||||
int numEv = 0;
|
||||
int codEv = 0;
|
||||
if (currStrobe.HasFlag((StFlag8)Math.Pow(2, bitNum)))
|
||||
{
|
||||
// verifico sia > 0 il numero di valori da leggere - indice 0 sull'area...
|
||||
numEv = BitConverter.ToUInt16(MemBlock, 2 * memShift);
|
||||
if (numEv > 0)
|
||||
{
|
||||
// il num ev rappresenta quanti slot 16bit (da 2 byte) sono stati valorizzati, VA FATTO CICLO E LETTI TUTTI
|
||||
for (int i = 0; i < numEv; i++)
|
||||
{
|
||||
// leggo valore Codice
|
||||
codEv = BitConverter.ToUInt16(MemBlock, 2 * (i + 2 + memShift));
|
||||
// accodo evento Codice
|
||||
appendCodeMST(Coda, codEv.ToString(), idxPath);
|
||||
}
|
||||
}
|
||||
// memorizzo allarme nel vettore ack....
|
||||
retACK_DW1 = utils.setBitOnStFlag(retACK_DW1, true, bitNum);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Ricarica dati da file di scambio con CMSConnect
|
||||
/// </summary>
|
||||
private void reloadDataFromFile()
|
||||
|
||||
@@ -16,15 +16,15 @@ namespace MTC_Adapter
|
||||
protected SIEMENS SIEMENS_ref;
|
||||
|
||||
/// <summary>
|
||||
/// Area di memoria base x MTConnect con SIEMENS
|
||||
/// Area di memoria base x MTConnect con SIEMENS (DB1499)
|
||||
/// </summary>
|
||||
protected int baseMemDb = 1499;
|
||||
/// <summary>
|
||||
/// Area di memoria base x dati UTENSILE
|
||||
/// Area di memoria base x dati UTENSILE (DB253)
|
||||
/// </summary>
|
||||
protected int baseMemUT = 253;
|
||||
/// <summary>
|
||||
/// Area di memoria base x dati TESTE
|
||||
/// Area di memoria base x dati TESTE (DB254)
|
||||
/// </summary>
|
||||
protected int baseMemUO = 254;
|
||||
|
||||
@@ -36,15 +36,15 @@ namespace MTC_Adapter
|
||||
/// <param name="memIndex"></param>
|
||||
/// <param name="Value"></param>
|
||||
/// <returns></returns>
|
||||
public bool SIEMENSMemRW(bool bWrite, int MemType, Int32 memIndex, ref byte Value)
|
||||
public bool SIEMENSMemRW_Byte(bool bWrite, int MemType, Int32 memIndex, ref byte Value)
|
||||
{
|
||||
bool answ = false;
|
||||
// chiamo la versione multibyte...
|
||||
byte[] ValArray = new byte[1];
|
||||
SIEMENSMemRW(bWrite, MemType, memIndex, ref ValArray);
|
||||
SIEMENSMemRW_Byte(bWrite, MemType, memIndex, ref ValArray);
|
||||
Value = ValArray[0];
|
||||
return answ;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// wrapper chiamata lettura/scrittura MULTI BYTE...
|
||||
/// </summary>
|
||||
@@ -53,7 +53,7 @@ namespace MTC_Adapter
|
||||
/// <param name="memIndex"></param>
|
||||
/// <param name="MATRICE Value"></param>
|
||||
/// <returns></returns>
|
||||
public bool SIEMENSMemRW(bool bWrite, int MemType, Int32 memIndex, ref byte[] Value)
|
||||
public bool SIEMENSMemRW_Byte(bool bWrite, int MemType, Int32 memIndex, ref byte[] Value)
|
||||
{
|
||||
bool answ = false;
|
||||
if (SIEMENS_ref.Connected)
|
||||
@@ -67,6 +67,50 @@ namespace MTC_Adapter
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// wrapper chiamata lettura/scrittura MULTI Word...
|
||||
/// </summary>
|
||||
/// <param name="bWrite"></param>
|
||||
/// <param name="MemType">main address (1499/1500)</param>
|
||||
/// <param name="memIndex"></param>
|
||||
/// <param name="MATRICE Value"></param>
|
||||
/// <returns></returns>
|
||||
public bool SIEMENSMemRW_Word(bool bWrite, int MemType, Int32 memIndex, ref ushort[] Value)
|
||||
{
|
||||
bool answ = false;
|
||||
if (SIEMENS_ref.Connected)
|
||||
{
|
||||
try
|
||||
{
|
||||
answ = SIEMENS_ref.S_RW_Word(bWrite, MemType, memIndex, ref Value);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
/// <summary>
|
||||
/// wrapper chiamata lettura/scrittura MULTI DWord...
|
||||
/// </summary>
|
||||
/// <param name="bWrite"></param>
|
||||
/// <param name="MemType">main address (1499/1500)</param>
|
||||
/// <param name="memIndex"></param>
|
||||
/// <param name="MATRICE Value"></param>
|
||||
/// <returns></returns>
|
||||
public bool SIEMENSMemRW_DWord(bool bWrite, int MemType, Int32 memIndex, ref uint[] Value)
|
||||
{
|
||||
bool answ = false;
|
||||
if (SIEMENS_ref.Connected)
|
||||
{
|
||||
try
|
||||
{
|
||||
answ = SIEMENS_ref.S_RW_DWord(bWrite, MemType, memIndex, ref Value);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// struttura dati SIEMENS x ALL DYN DATA
|
||||
@@ -193,53 +237,17 @@ namespace MTC_Adapter
|
||||
base.getStrobeAndAckStatus();
|
||||
if (connectionOk)
|
||||
{
|
||||
// come OSAI
|
||||
if (false)
|
||||
{
|
||||
#if false
|
||||
// leggo TUTTO ack e strobe... in blocco di 16 WORD (32 byte) + altre 2 in coda...
|
||||
ushort[] MemBlock_A = new ushort[16];
|
||||
ushort[] MemBlock_B = new ushort[2];
|
||||
// leggo TUTTO ack e strobe,
|
||||
byte[] MemBlock = new byte[Strobes.Length + Acknowl.Length];
|
||||
int memIndex = 0;
|
||||
|
||||
int memIndexA = 19018;
|
||||
int memIndexB = 19698;
|
||||
inizio = DateTime.Now;
|
||||
SIEMENSMemRW_Byte(R, baseMemDb, memIndex, ref MemBlock);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-STROBES", MemBlock.Length), DateTime.Now.Subtract(inizio).Ticks);
|
||||
|
||||
// NB: LEGGO SEMPRE a WORD 16bit (+ veloce...)
|
||||
|
||||
// leggo blocco dati + grande...
|
||||
inizio = DateTime.Now;
|
||||
OsaiMemRW_Word(R, OSAI.MemTypeWord.MW_CODE, memIndexA, ref MemBlock_A);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R-{0}-W4", MemBlock_A.Length * 2), DateTime.Now.Subtract(inizio).Ticks);
|
||||
|
||||
// leggo blocco dati + piccolo
|
||||
inizio = DateTime.Now;
|
||||
OsaiMemRW_Word(R, OSAI.MemTypeWord.MW_CODE, memIndexB, ref MemBlock_B);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R-{0}-W1", MemBlock_B.Length * 2), DateTime.Now.Subtract(inizio).Ticks);
|
||||
|
||||
// suddivido blocco a blocco... da file di conf x OSAI!!!
|
||||
// primi 12 byte ad ACK
|
||||
Buffer.BlockCopy(MemBlock_A, 0, Acknowl, 0, Acknowl.Length - 4);
|
||||
// altri 4 byte ad ACK blocco secondario
|
||||
Buffer.BlockCopy(MemBlock_B, 0, Acknowl, Acknowl.Length - 4, 4);
|
||||
// tutti i 16+4 byte a strobe/status
|
||||
Buffer.BlockCopy(MemBlock_A, Acknowl.Length - 4, Strobes, 0, Strobes.Length);
|
||||
#endif
|
||||
}
|
||||
// come FANUC
|
||||
else
|
||||
{
|
||||
// leggo TUTTO ack e strobe,
|
||||
byte[] MemBlock = new byte[Strobes.Length + Acknowl.Length];
|
||||
int memIndex = 0;
|
||||
|
||||
inizio = DateTime.Now;
|
||||
SIEMENSMemRW(R, baseMemDb, memIndex, ref MemBlock);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-STROBES", MemBlock.Length), DateTime.Now.Subtract(inizio).Ticks);
|
||||
|
||||
// suddivido!
|
||||
Buffer.BlockCopy(MemBlock, 0, Acknowl, 0, Acknowl.Length);
|
||||
Buffer.BlockCopy(MemBlock, Acknowl.Length, Strobes, 0, Strobes.Length);
|
||||
}
|
||||
// suddivido!
|
||||
Buffer.BlockCopy(MemBlock, 0, Acknowl, 0, Acknowl.Length);
|
||||
Buffer.BlockCopy(MemBlock, Acknowl.Length, Strobes, 0, Strobes.Length);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -255,42 +263,89 @@ namespace MTC_Adapter
|
||||
|
||||
// inizializzo userAction
|
||||
string UserAction = "";
|
||||
string TestingData = "";
|
||||
string UnkStrobe = "";
|
||||
// !!!FARE!!! multipath...
|
||||
// verifico i vari strobe x recuperare i dati... PER ORA SOLO DW1 per path1 (indice 0)...
|
||||
//int idxPath = 0;
|
||||
int memIndex = 0;
|
||||
// oggetti "accessori" x processing (1 byte di strobe x ogni path)
|
||||
StFlag8 currStrobe;
|
||||
StFlag8 currAck;
|
||||
|
||||
// processo ora i dati dei path... di sicuro il primo
|
||||
currStrobe = (StFlag8)(Strobes[4]); // 5° byte
|
||||
currAck = (StFlag8)(Acknowl[4]); // 5° byte
|
||||
procPathStrobes(0, currStrobe, currAck, 246, 24, ref UserAction);
|
||||
|
||||
//...e se c'è pure il secondo...
|
||||
if (currAdpConf.nPath > 1)
|
||||
{
|
||||
currStrobe = (StFlag8)(Strobes[6]); // 7° byte
|
||||
currAck = (StFlag8)(Acknowl[6]); // 7° byte
|
||||
procPathStrobes(1, currStrobe, currAck, 292, 26, ref UserAction);
|
||||
}
|
||||
|
||||
// 2017.01.16 INVIO vettore azioni (1 o +)... SE CE NE SONO!
|
||||
if (UserAction.Trim() != "")
|
||||
{
|
||||
mUserAction.ForceChanged();
|
||||
mUserAction.Value = UserAction.Trim();
|
||||
}
|
||||
|
||||
// verifico strobe dell'auto-test
|
||||
currStrobe = (StFlag8)(Strobes[7]); // 8° byte
|
||||
currAck = (StFlag8)(Acknowl[7]); // 8° byte
|
||||
processTestStrobe(currStrobe, currAck, 26, 1);
|
||||
|
||||
// gestione bit di watchdog... sulal DWord successiva
|
||||
sendWatchDog();
|
||||
}
|
||||
/// <summary>
|
||||
/// Processa strobe x un dato path
|
||||
/// </summary>
|
||||
/// <param name="idxPath">path corrente</param>
|
||||
/// <param name="currStrobe">Byte di strobe del path corrente</param>
|
||||
/// <param name="currAck">Byte di strobe del path corrente</param>
|
||||
/// <param name="memIndexMST">indice x lettura memoria MST del path</param>
|
||||
/// <param name="memIndexAck">indice x scrittura ACK x path</param>
|
||||
/// <param name="UserAction">stringa COMPLESSIVA azioni utente</param>
|
||||
private void procPathStrobes(int idxPath, StFlag8 currStrobe, StFlag8 currAck, int memIndexMST, int memIndexAck, ref string UserAction)
|
||||
{
|
||||
// byte di strobe e di acknowledge... inizializzo!!!
|
||||
byte[] currACK_DW = new byte[1];
|
||||
// altre variabili
|
||||
int bitNum = 0;
|
||||
inizio = DateTime.Now;
|
||||
// byte di acknowledge...
|
||||
byte[] retACK_DW1 = new byte[4];
|
||||
// incomincio vera e propria gestione...
|
||||
try
|
||||
{
|
||||
// controllo TUTTI i flag: se ce ne sono di alzati DEVO processare...
|
||||
if (STRB_DW1 != StFlag32.NONE)
|
||||
if (currStrobe != StFlag8.NONE)
|
||||
{
|
||||
// blocco memoria x lettura TUTTI i dati di buffer M/S/T: 46 byte: 2byte (16bit) x (11+6+6) aree
|
||||
byte[] MemBlock = new byte[46];
|
||||
// se ho un M/S/T leggo area...
|
||||
if (currStrobe.HasFlag(StFlag8.B0) || currStrobe.HasFlag(StFlag8.B1) || currStrobe.HasFlag(StFlag8.B2))
|
||||
{
|
||||
|
||||
// leggo tutto!!!
|
||||
memIndex = 10660;
|
||||
inizio = DateTime.Now;
|
||||
SIEMENSMemRW(R, baseMemDb, memIndex, ref MemBlock);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-STRB_DW1", MemBlock.Length), DateTime.Now.Subtract(inizio).Ticks);
|
||||
// blocco memoria x lettura TUTTI i dati di buffer M/S/T: 26 short(16bit) x (12+7+7) aree (attenzione: secondo set di 2 bit è VUOTO...)
|
||||
ushort[] MemBlock_W = new ushort[26];
|
||||
|
||||
// check COD_M
|
||||
bitNum = 0;
|
||||
gestStrobeCodMST(bitNum, ref retACK_DW1, 0, MemBlock, "M");
|
||||
// leggo tutto!!!
|
||||
inizio = DateTime.Now;
|
||||
SIEMENSMemRW_Word(R, baseMemDb, memIndexMST, ref MemBlock_W);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-STRB_DW1-P{1:00}", MemBlock_W.Length, idxPath), DateTime.Now.Subtract(inizio).Ticks);
|
||||
|
||||
// check COD_S
|
||||
bitNum = 1;
|
||||
gestStrobeCodMST(bitNum, ref retACK_DW1, 11, MemBlock, "S");
|
||||
// converto a byte x compatibilità...
|
||||
byte[] MemBlock = new byte[MemBlock_W.Length * 2];
|
||||
Buffer.BlockCopy(MemBlock_W, 0, MemBlock, 0, MemBlock.Length);
|
||||
|
||||
// check COD_T
|
||||
bitNum = 2;
|
||||
gestStrobeCodMST(bitNum, ref retACK_DW1, 17, MemBlock, "T");
|
||||
// check COD_M
|
||||
bitNum = 0;
|
||||
gestStrobeCodMST(currStrobe, bitNum, ref currACK_DW, 0, MemBlock, "M", idxPath);
|
||||
|
||||
// check COD_S
|
||||
bitNum = 1;
|
||||
gestStrobeCodMST(currStrobe, bitNum, ref currACK_DW, 12, MemBlock, "S", idxPath);
|
||||
|
||||
// check COD_T
|
||||
bitNum = 2;
|
||||
gestStrobeCodMST(currStrobe, bitNum, ref currACK_DW, 19, MemBlock, "T", idxPath);
|
||||
|
||||
}
|
||||
|
||||
// check FILE DATI MODIFICATO: ricaricare...
|
||||
bitNum = 3;
|
||||
@@ -303,7 +358,7 @@ namespace MTC_Adapter
|
||||
reloadDataFromFile();
|
||||
|
||||
// memorizzo allarme nel vettore ack....
|
||||
retACK_DW1 = utils.setBitOnStFlag(retACK_DW1, true, bitNum);
|
||||
currACK_DW = utils.setBitOnStFlag(currACK_DW, true, bitNum);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -314,83 +369,79 @@ namespace MTC_Adapter
|
||||
// AREA strobe USER ACTION
|
||||
// chiamato Start...
|
||||
bitNum = 4;
|
||||
gestStrobeUserAction(bitNum, ref retACK_DW1, ref UserAction, " (START) ");
|
||||
gestStrobeUserAction(bitNum, ref currACK_DW, ref UserAction, string.Format(" (P{0:00} START) ", idxPath));
|
||||
// chiamato Stop...
|
||||
bitNum = 5;
|
||||
gestStrobeUserAction(bitNum, ref retACK_DW1, ref UserAction, " (STOP) ");
|
||||
gestStrobeUserAction(bitNum, ref currACK_DW, ref UserAction, string.Format(" (P{0:00} STOP) ", idxPath));
|
||||
// chiamato Reset...
|
||||
bitNum = 6;
|
||||
gestStrobeUserAction(bitNum, ref retACK_DW1, ref UserAction, " (RESET) ");
|
||||
gestStrobeUserAction(bitNum, ref currACK_DW, ref UserAction, string.Format(" (P{0:00} RESET) ", idxPath));
|
||||
|
||||
// processo tutti gli strobe x i BIT 7-29 NON gestiti in modo da dare comunque ACK e event...
|
||||
for (int i = 7; i < 30; i++)
|
||||
{
|
||||
gestStrobeUserAction(i, ref retACK_DW1, ref UnkStrobe, string.Format(" [STROBE_{0:00}] ", i));
|
||||
}
|
||||
|
||||
// AREA strobe x TEST
|
||||
// INIZIO TEST...
|
||||
bitNum = 30;
|
||||
if (STRB_DW1.HasFlag((StFlag32)Math.Pow(2, bitNum)))
|
||||
{
|
||||
// formatto stringa risultato
|
||||
TestingData = string.Format("START TEST{0}", getTestData(utils.CRS("testCharSep")));
|
||||
|
||||
// memorizzo allarme nel vettore ack....
|
||||
retACK_DW1 = utils.setBitOnStFlag(retACK_DW1, true, bitNum);
|
||||
}
|
||||
// FINE TEST...
|
||||
bitNum = 31;
|
||||
if (STRB_DW1.HasFlag((StFlag32)Math.Pow(2, bitNum)))
|
||||
{
|
||||
// formatto stringa risultato
|
||||
TestingData = string.Format("STOP TEST{0}", getTestData(utils.CRS("testCharSep")));
|
||||
|
||||
// memorizzo allarme nel vettore ack....
|
||||
retACK_DW1 = utils.setBitOnStFlag(retACK_DW1, true, bitNum);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// se mi sono rimasti degli strobe di lettura allarmi alzati li abbasso
|
||||
if (ACK_DW1 != StFlag32.NONE)
|
||||
{
|
||||
// inizializzo 4 byte a zero!!!
|
||||
retACK_DW1 = new byte[4];
|
||||
}
|
||||
// inizializzo 4 byte a zero!!!
|
||||
currACK_DW = new byte[1];
|
||||
}
|
||||
}
|
||||
catch
|
||||
catch (Exception exc)
|
||||
{
|
||||
lg.Info("Errore in strobe");
|
||||
lg.Error(string.Format("Errore in strobe:{0}{1}", Environment.NewLine, exc));
|
||||
}
|
||||
|
||||
// 2017.01.16 INVIO vettore azioni (1 o +)... SE CE NE SONO!
|
||||
if (UserAction.Trim() != "")
|
||||
{
|
||||
mUserAction.ForceChanged();
|
||||
mUserAction.Value = UserAction.Trim();
|
||||
}
|
||||
|
||||
// Invio comunque strobe non riconosciuti
|
||||
if (mUnkStrobe.Value.ToString() != UnkStrobe.Trim())
|
||||
{
|
||||
mUnkStrobe.Value = UnkStrobe.Trim();
|
||||
}
|
||||
|
||||
// INVIO COMUNQUE stato test...
|
||||
mTestingData.Value = TestingData.Trim();
|
||||
|
||||
memIndex = 10504;
|
||||
// scrivo update ad ack SE VARIATO!!!
|
||||
if (ACK_DW1 != (StFlag32)BitConverter.ToUInt32(retACK_DW1, 0))
|
||||
if (currAck != (StFlag8)currACK_DW[0])
|
||||
{
|
||||
inizio = DateTime.Now;
|
||||
SIEMENSMemRW(W, baseMemDb, memIndex, ref retACK_DW1);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("W{0}-DW1", retACK_DW1.Length), DateTime.Now.Subtract(inizio).Ticks);
|
||||
SIEMENSMemRW_Byte(W, baseMemDb, memIndexAck, ref currACK_DW);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("W{0}-ACK_DW0", currACK_DW.Length), DateTime.Now.Subtract(inizio).Ticks);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Verifica strobe autotest
|
||||
/// </summary>
|
||||
/// <param name="currStrobe"></param>
|
||||
/// <param name="currAck"></param>
|
||||
/// <param name="memIndexAck"></param>
|
||||
private void processTestStrobe(StFlag8 currStrobe, StFlag8 currAck, int memIndexAck, int memOrderStart)
|
||||
{
|
||||
// byte di strobe e di acknowledge... inizializzo!!!
|
||||
byte[] currACK_DW = new byte[1];
|
||||
string TestingData = "";
|
||||
// INIZIO TEST...
|
||||
int bitNum = 6;
|
||||
if (currStrobe.HasFlag((StFlag8)Math.Pow(2, bitNum)))
|
||||
{
|
||||
// formatto stringa risultato
|
||||
TestingData = string.Format("START TEST{0}", getTestData(utils.CRS("testCharSep")));
|
||||
|
||||
// memorizzo allarme nel vettore ack....
|
||||
currACK_DW = utils.setBitOnStFlag(currACK_DW, true, bitNum);
|
||||
}
|
||||
// FINE TEST...
|
||||
bitNum = 7;
|
||||
if (currStrobe.HasFlag((StFlag8)Math.Pow(2, bitNum)))
|
||||
{
|
||||
// formatto stringa risultato
|
||||
TestingData = string.Format("STOP TEST{0}", getTestData(utils.CRS("testCharSep")));
|
||||
|
||||
// memorizzo allarme nel vettore ack....
|
||||
currACK_DW = utils.setBitOnStFlag(currACK_DW, true, bitNum);
|
||||
}
|
||||
|
||||
sendWatchDog();
|
||||
// INVIO stato test...
|
||||
if (mTestingData.Value.ToString() != TestingData.Trim())
|
||||
{
|
||||
mTestingData.Value = TestingData.Trim();
|
||||
}
|
||||
|
||||
// scrivo update ad ack SE VARIATO!!!
|
||||
if (currAck != (StFlag8)currACK_DW[0])
|
||||
{
|
||||
inizio = DateTime.Now;
|
||||
SIEMENSMemRW_Byte(W, baseMemDb, memIndexAck, ref currACK_DW);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("W{0}-ACK_DW0", currACK_DW.Length), DateTime.Now.Subtract(inizio).Ticks);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Invia (se necessario) il watchdog di stato in vita... blink 0/1 ogni secondo
|
||||
@@ -399,7 +450,7 @@ namespace MTC_Adapter
|
||||
{
|
||||
int memIndex = 0;
|
||||
bool setFlag = false;
|
||||
byte[] retACK_DW = new byte[4];
|
||||
byte[] retACK_DW = new byte[1];
|
||||
// 2016.10.18 aggiungo scrittura del bit di "watchdog" al primo bit della DW2... come resto tra secondi / 2
|
||||
if (utils.CRB("sendWatchDog"))
|
||||
{
|
||||
@@ -412,14 +463,13 @@ namespace MTC_Adapter
|
||||
lastWatchDog = setFlag;
|
||||
retACK_DW = utils.setBitOnStFlag(retACK_DW, setFlag, 0); // imposto primo bit!!!
|
||||
// scrivo su area PLC
|
||||
memIndex = 10508;
|
||||
memIndex = 38;
|
||||
inizio = DateTime.Now;
|
||||
SIEMENSMemRW(W, baseMemDb, memIndex, ref retACK_DW);
|
||||
SIEMENSMemRW_Byte(W, baseMemDb, memIndex, ref retACK_DW);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("W{0}-WatchDog", retACK_DW.Length), DateTime.Now.Subtract(inizio).Ticks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recupero info su test: numero + elenco parametri IN/OUT
|
||||
/// </summary>
|
||||
@@ -428,8 +478,8 @@ namespace MTC_Adapter
|
||||
private string getTestData(string charSep)
|
||||
{
|
||||
string answ = "";
|
||||
// Area di memoria x test... 64 byte
|
||||
byte[] MemBlockTestData = new byte[64];
|
||||
// Area di memoria x test... (64 DWord) (la prima va splittata)
|
||||
UInt32[] MemBlockTestData = new UInt32[64];
|
||||
// variabili numero test e num parametri impiegati
|
||||
int testNum = 0;
|
||||
int numPar = 0;
|
||||
@@ -437,14 +487,14 @@ namespace MTC_Adapter
|
||||
UInt32 testParam = 0;
|
||||
|
||||
// leggo tutto!!!
|
||||
int memIndex = 11000;
|
||||
int memIndex = 522;
|
||||
inizio = DateTime.Now;
|
||||
SIEMENSMemRW(R, baseMemDb, memIndex, ref MemBlockTestData);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TEST_DATA_DW1", MemBlockTestData.Length), DateTime.Now.Subtract(inizio).Ticks);
|
||||
SIEMENSMemRW_DWord(R, baseMemDb, memIndex, ref MemBlockTestData);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TEST_DATA", MemBlockTestData.Length), DateTime.Now.Subtract(inizio).Ticks);
|
||||
|
||||
// recupero cod univoco test e numero parametri impiegati
|
||||
testNum = BitConverter.ToUInt16(MemBlockTestData, 0);
|
||||
numPar = BitConverter.ToUInt16(MemBlockTestData, 2);
|
||||
testNum = BitConverter.ToUInt16(BitConverter.GetBytes(MemBlockTestData[0]), 0);
|
||||
numPar = BitConverter.ToUInt16(BitConverter.GetBytes(MemBlockTestData[0]), 2);
|
||||
|
||||
|
||||
// riporto separatore + numero test + num parametri
|
||||
@@ -454,46 +504,13 @@ namespace MTC_Adapter
|
||||
{
|
||||
for (int i = 0; i < numPar; i++)
|
||||
{
|
||||
testParam = BitConverter.ToUInt32(MemBlockTestData, 4 * (1 + i));
|
||||
testParam = MemBlockTestData[1 + i];
|
||||
answ += string.Format("{0}{1}", charSep, testParam);
|
||||
}
|
||||
}
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gestione STROBE --> ACK per codici M/S/T
|
||||
/// </summary>
|
||||
/// <param name="bitNum">0/1/2</param>
|
||||
/// <param name="retACK_DW1">vettore da restituire di ACK</param>
|
||||
/// <param name="memShift">shift memoria x buffer dati da leggere</param>
|
||||
/// <param name="MemBlock">Vettore completo dei valori + buffer code M/S/T</param>
|
||||
/// <param name="Coda">Quale coda: M/S/T</param>
|
||||
private void gestStrobeCodMST(int bitNum, ref byte[] retACK_DW1, int memShift, byte[] MemBlock, string Coda)
|
||||
{
|
||||
int numEv = 0;
|
||||
int codEv = 0;
|
||||
int idxPath = 0; // Hard coded path 0 soltanto...
|
||||
if (STRB_DW1.HasFlag((StFlag32)Math.Pow(2, bitNum)))
|
||||
{
|
||||
// verifico sia > 0 il numero di valori da leggere indice 0 sull'area...
|
||||
numEv = BitConverter.ToUInt16(MemBlock, 2 * memShift);
|
||||
if (numEv > 0)
|
||||
{
|
||||
// il num ev rappresenta quanti slot 16bit (da 2 byte) sono stati valorizzati, VA FATTO CICLO E LETTI TUTTI
|
||||
for (int i = 0; i < numEv; i++)
|
||||
{
|
||||
// leggo valore Codice
|
||||
codEv = BitConverter.ToUInt16(MemBlock, 2 * (i + 1 + memShift));
|
||||
// accodo evento Codice
|
||||
appendCodeMST(Coda, codEv.ToString(), idxPath);
|
||||
}
|
||||
}
|
||||
// memorizzo allarme nel vettore ack....
|
||||
retACK_DW1 = utils.setBitOnStFlag(retACK_DW1, true, bitNum);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Ricarica dati da file di scambio con CMSConnect
|
||||
/// </summary>
|
||||
@@ -651,7 +668,7 @@ namespace MTC_Adapter
|
||||
MemBlock = new byte[128];
|
||||
// recupero tutti i 32 bit del blocco
|
||||
inizio = DateTime.Now;
|
||||
SIEMENSMemRW(R, baseMemDb, memIndex, ref MemBlock);
|
||||
SIEMENSMemRW_Byte(R, baseMemDb, memIndex, ref MemBlock);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-STRB_DW0", MemBlock.Length), DateTime.Now.Subtract(inizio).Ticks);
|
||||
if (AlarmFlags != null)
|
||||
{
|
||||
@@ -679,7 +696,7 @@ namespace MTC_Adapter
|
||||
{
|
||||
// recupero tutti i 32 bit del blocco
|
||||
inizio = DateTime.Now;
|
||||
SIEMENSMemRW(R, baseMemDb, memIndex + i * 4, ref MemBlock);
|
||||
SIEMENSMemRW_Byte(R, baseMemDb, memIndex + i * 4, ref MemBlock);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-STRB_DW0", MemBlock.Length), DateTime.Now.Subtract(inizio).Ticks);
|
||||
|
||||
// da testare metodo copia alternativo, condizionato a web.config
|
||||
@@ -708,7 +725,7 @@ namespace MTC_Adapter
|
||||
memIndex = 10500;
|
||||
// scrivo update ad ack!!!
|
||||
inizio = DateTime.Now;
|
||||
SIEMENSMemRW(W, baseMemDb, memIndex, ref retACK_DW0);
|
||||
SIEMENSMemRW_Byte(W, baseMemDb, memIndex, ref retACK_DW0);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("W{0}-ACK_DW0", retACK_DW0.Length), DateTime.Now.Subtract(inizio).Ticks);
|
||||
ackReturned = true;
|
||||
}
|
||||
@@ -725,7 +742,7 @@ namespace MTC_Adapter
|
||||
// invio INTERO set ACK_DW0 con bit abbassati...
|
||||
retACK_DW0 = BitConverter.GetBytes(Convert.ToUInt32(STRB_DW0 & ACK_DW0));
|
||||
inizio = DateTime.Now;
|
||||
SIEMENSMemRW(W, baseMemDb, memIndex, ref retACK_DW0);
|
||||
SIEMENSMemRW_Byte(W, baseMemDb, memIndex, ref retACK_DW0);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("W{0}-ACK_DW0", retACK_DW0.Length), DateTime.Now.Subtract(inizio).Ticks);
|
||||
}
|
||||
}
|
||||
@@ -916,7 +933,7 @@ namespace MTC_Adapter
|
||||
byte[] tabDatiMtzByte = new byte[4 * maintData.Length];
|
||||
uint[] tabDatiMtz = new uint[maintData.Length];
|
||||
inizio = DateTime.Now;
|
||||
SIEMENSMemRW(R, baseMemDb, memIndex, ref tabDatiMtzByte);
|
||||
SIEMENSMemRW_Byte(R, baseMemDb, memIndex, ref tabDatiMtzByte);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-DatiMtz", tabDatiMtzByte.Length), DateTime.Now.Subtract(inizio).Ticks);
|
||||
// copio byte --> word!
|
||||
Buffer.BlockCopy(tabDatiMtzByte, 0, tabDatiMtz, 0, tabDatiMtzByte.Length);
|
||||
@@ -935,7 +952,7 @@ namespace MTC_Adapter
|
||||
byte[] tabDatiAnalogByte = new byte[4 * analogData.Length];
|
||||
uint[] tabDatiAnalog = new uint[analogData.Length];
|
||||
inizio = DateTime.Now;
|
||||
SIEMENSMemRW(R, baseMemDb, memIndex, ref tabDatiAnalogByte);
|
||||
SIEMENSMemRW_Byte(R, baseMemDb, memIndex, ref tabDatiAnalogByte);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-DatiAnalog", tabDatiAnalogByte.Length * 4), DateTime.Now.Subtract(inizio).Ticks);
|
||||
// copio byte --> word!
|
||||
Buffer.BlockCopy(tabDatiAnalogByte, 0, tabDatiAnalog, 0, tabDatiAnalogByte.Length);
|
||||
@@ -953,7 +970,7 @@ namespace MTC_Adapter
|
||||
int numByte = 1 + (statusData.Length / 8);
|
||||
byte[] tabDatiStatus = new byte[numByte];
|
||||
inizio = DateTime.Now;
|
||||
SIEMENSMemRW(R, baseMemDb, memIndex, ref tabDatiStatus);
|
||||
SIEMENSMemRW_Byte(R, baseMemDb, memIndex, ref tabDatiStatus);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-DatiStatus", tabDatiStatus.Length), DateTime.Now.Subtract(inizio).Ticks);
|
||||
|
||||
// decodifico aree memoria secondo tab configurazione
|
||||
@@ -1120,7 +1137,7 @@ namespace MTC_Adapter
|
||||
byte[] unOpSpeedMem = new byte[60];
|
||||
|
||||
inizio = DateTime.Now;
|
||||
SIEMENSMemRW(R, baseMemUO, memIndex, ref unOpSpeedMem);
|
||||
SIEMENSMemRW_Byte(R, baseMemUO, memIndex, ref unOpSpeedMem);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-SPEED_UNOP", unOpSpeedMem.Length), DateTime.Now.Subtract(inizio).Ticks);
|
||||
|
||||
procUnOp(unOpSpeedMem);
|
||||
@@ -1135,7 +1152,7 @@ namespace MTC_Adapter
|
||||
{
|
||||
int memIndex = 13100 + 4 * j;
|
||||
inizio = DateTime.Now;
|
||||
SIEMENSMemRW(R, baseMemUT, memIndex, ref int32Mem);
|
||||
SIEMENSMemRW_Byte(R, baseMemUT, memIndex, ref int32Mem);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TabUT-VitaRes", int32Mem.Length), DateTime.Now.Subtract(inizio).Ticks);
|
||||
return memIndex;
|
||||
}
|
||||
@@ -1149,9 +1166,9 @@ namespace MTC_Adapter
|
||||
{
|
||||
int memIndex = 10700 + 1 * j;
|
||||
inizio = DateTime.Now;
|
||||
SIEMENSMemRW(R, baseMemUT, memIndex, ref int8Mem);
|
||||
SIEMENSMemRW_Byte(R, baseMemUT, memIndex, ref int8Mem);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TabUT-FamUT", 8), DateTime.Now.Subtract(inizio).Ticks);
|
||||
return memIndex;
|
||||
return memIndex;
|
||||
}
|
||||
/// <summary>
|
||||
/// Procedura di processing lettura memoria x DatiUt - Step 3a
|
||||
@@ -1162,7 +1179,7 @@ namespace MTC_Adapter
|
||||
{
|
||||
int memIndex = 8900;
|
||||
inizio = DateTime.Now;
|
||||
SIEMENSMemRW(R, baseMemUT, memIndex, ref tabFam_FamUt);
|
||||
SIEMENSMemRW_Byte(R, baseMemUT, memIndex, ref tabFam_FamUt);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TabFamUT-FamUT", tabFam_FamUt.Length), DateTime.Now.Subtract(inizio).Ticks);
|
||||
return memIndex;
|
||||
}
|
||||
@@ -1176,7 +1193,7 @@ namespace MTC_Adapter
|
||||
{
|
||||
int memIndex = 11700 + 2 * j;
|
||||
inizio = DateTime.Now;
|
||||
SIEMENSMemRW(R, baseMemUT, memIndex, ref int16Mem);
|
||||
SIEMENSMemRW_Byte(R, baseMemUT, memIndex, ref int16Mem);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-TabUT-FamUT", int16Mem.Length), DateTime.Now.Subtract(inizio).Ticks);
|
||||
return memIndex;
|
||||
}
|
||||
@@ -1189,7 +1206,7 @@ namespace MTC_Adapter
|
||||
{
|
||||
int memIndex = 11300;
|
||||
inizio = DateTime.Now;
|
||||
SIEMENSMemRW(R, baseMemUT, memIndex, ref tabUt_UT);
|
||||
SIEMENSMemRW_Byte(R, baseMemUT, 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;
|
||||
}
|
||||
@@ -1202,7 +1219,7 @@ namespace MTC_Adapter
|
||||
{
|
||||
int memIndex = 2960;
|
||||
inizio = DateTime.Now;
|
||||
SIEMENSMemRW(R, baseMemUT, memIndex, ref elencoUtMem);
|
||||
SIEMENSMemRW_Byte(R, baseMemUT, memIndex, ref elencoUtMem);
|
||||
if (utils.CRB("recTime")) TimingData.addResult(string.Format("R{0}-NUMUT", elencoUtMem.Length), DateTime.Now.Subtract(inizio).Ticks);
|
||||
return memIndex;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user