diff --git a/IOB-WIN/IobSiemens.cs b/IOB-WIN/IobSiemens.cs
index 3a07f542..64756e0c 100644
--- a/IOB-WIN/IobSiemens.cs
+++ b/IOB-WIN/IobSiemens.cs
@@ -12,13 +12,13 @@ namespace IOB_WIN
{
public class IobSiemens : IobGeneric, IDisposable
{
- /* --------------------------------------------------------------------------------
+ /* --------------------------------------------------------------------------------
* Controlli SIEMENS tramite libreria S7.net
* - basasto su SIEMENS
* - S7 testato vers 300 e 1200
* - attenzione conf rack/slot x varie serie controlli
* - necessità apertura metodi pu/get
- *
+ *
* -------------------------------------------------------------------------------- */
#region area componenti base
@@ -27,28 +27,33 @@ namespace IOB_WIN
/// Byte dimensione buffer dati memoria (da file map)
///
public int numByte = 0;
- ///
- /// Lungh massima stringhe
- ///
- protected int maxStrChar = 20;
- ///
- /// indica se scrivere i primi byte x string siemens x indicare lung max e corrente
- ///
- protected bool writePre = true;
+
///
/// Oggetto PLC da ri-utilizzare...
///
protected Plc currPLC;
+
///
- /// Oggetto cronometro x test vari...
+ /// Lungh massima stringhe
///
- protected Stopwatch sw = new Stopwatch();
+ protected int maxStrChar = 20;
+
///
/// parametri di connessione
///
protected connParamS7 parametri;
- #endregion
+ ///
+ /// Oggetto cronometro x test vari...
+ ///
+ protected Stopwatch sw = new Stopwatch();
+
+ ///
+ /// indica se scrivere i primi byte x string siemens x indicare lung max e corrente
+ ///
+ protected bool writePre = true;
+
+ #endregion area componenti base
#region area metodi lettura/Scrittura
@@ -57,67 +62,6 @@ namespace IOB_WIN
///
protected Dictionary lastMemWrite { get; set; } = new Dictionary();
- ///
- /// Inserimento/aggiornamento chiavi/valore in currProdData
- ///
- ///
- ///
- public void upsertKey(string chiave, string valore)
- {
- if (currProdData.ContainsKey(chiave))
- {
- currProdData[chiave] = valore;
- }
- else
- {
- currProdData.Add(chiave, valore);
- }
- }
- ///
- /// Converte direttamente un valore stringa su un oggetto byte[] (senza limitazioni di dimensione)
- ///
- ///
- /// Dimensione massima ammessa per la stringa
- ///
- public byte[] stringToByte(string valore, int maxLenght)
- {
- byte[] answ = new byte[1];
- byte[] stringPar = new byte[2];
- byte[] strByte = S7.Net.Types.String.ToByteArray(valore);
- int shiftStrByte = writePre ? 2 : 0;
- int byteLen = strByte.Length <= maxLenght ? strByte.Length : maxLenght;
- if (writePre)
- {
- // MAX LUN
- stringPar[1] = (byte)maxLenght;
- // LUNGH STRING
- stringPar[0] = (byte)byteLen;
- Buffer.BlockCopy(stringPar, 0, answ, 0, shiftStrByte);
- }
- Buffer.BlockCopy(strByte, 0, answ, shiftStrByte, byteLen);
- return answ;
- }
- ///
- /// Converte direttamente un valore Short su un oggetto byte[2]
- ///
- /// valore da scrivere
- public byte[] intToByte(string valore)
- {
- byte[] answ = new byte[2];
- try
- {
- short valInt = 0;
- short.TryParse(valore, out valInt);
- byte[] strByte = S7.Net.Types.Int.ToByteArray(valInt);
- int byteLen = 2;
- Buffer.BlockCopy(strByte, 0, answ, 0, byteLen);
- }
- catch (Exception exc)
- {
- lgError($"Errore in gestione scrittura INT {valore} in byte{Environment.NewLine}{exc}");
- }
- return answ;
- }
///
/// Converte direttamente un valore Int su un oggetto byte[4]
///
@@ -139,27 +83,7 @@ namespace IOB_WIN
}
return answ;
}
- ///
- /// Converte direttamente un valore UInt16 su un oggetto byte[2]
- ///
- /// valore da scrivere
- public byte[] wordToByte(string valore)
- {
- byte[] answ = new byte[2];
- try
- {
- ushort valInt = 0;
- ushort.TryParse(valore, out valInt);
- byte[] strByte = S7.Net.Types.Word.ToByteArray(valInt);
- int byteLen = 2;
- Buffer.BlockCopy(strByte, 0, answ, 0, byteLen);
- }
- catch (Exception exc)
- {
- lgError($"Errore in gestione scrittura INT {valore} in byte{Environment.NewLine}{exc}");
- }
- return answ;
- }
+
///
/// Converte direttamente un valore UInt32 su un oggetto byte[4]
///
@@ -183,285 +107,25 @@ namespace IOB_WIN
}
///
- /// Salvo in memblock il valore stringa indicato con formattazione siemens
+ /// Converte direttamente un valore Short su un oggetto byte[2]
///
- /// Blocco memoria come byte[] dove scrivere
- /// Posizione inizio scrittura
- /// Lunghezza max stringa (se ci sono 2 byte iniziali verrà ridotta di 2)
/// valore da scrivere
- public void saveStringOnMemBlock(ref byte[] MemBlock, int startPos, int totLen, string valore)
- {
- if (MemBlock != null)
- {
- // loggare valore? fornire un output con memBlock e NON ref?
- try
- {
- lgInfo($"saveStringOnMemBlock: MemBlock size: {MemBlock.Length} | startPos: {startPos} | totLen: {totLen} | valore: {valore}");
- byte[] stringPar = new byte[2];
- byte[] strByte = S7.Net.Types.String.ToByteArray(valore);
- int byteLen = strByte.Length <= totLen ? strByte.Length : totLen;
- int shiftStrByte = writePre ? 2 : 0;
- if (writePre)
- {
- // MAX LUN
- stringPar[1] = (byte)totLen;
- // LUNGH STRING
- stringPar[0] = (byte)byteLen;
- Buffer.BlockCopy(stringPar, 0, MemBlock, startPos, shiftStrByte);
- }
- Buffer.BlockCopy(strByte, 0, MemBlock, startPos + shiftStrByte, byteLen);
- }
- catch (Exception exc)
- {
- lgError($"Errore in gestione scrittura {valore} alla posizione {startPos} per {totLen} byte{Environment.NewLine}{exc}");
- }
- }
- else
- {
- lgError("Errore: MemBlock nullo");
- }
- }
- ///
- /// Salvo in memblock il valore stringa indicato con formattazione siemens
- ///
- /// Blocco memoria come byte[] dove scrivere
- /// Nome del parametro da recuperare da prodData x scrivere
- /// Posizione inizio scrittura
- /// Lunghezza max stringa (se ci sono 2 byte iniziali verrà ridotta di 2)
- public void saveStringOnMemBlock(ref byte[] MemBlock, string stringKey, int startPos, int totLen)
- {
- if (currProdData.ContainsKey(stringKey))
- {
- try
- {
- string valore = currProdData[stringKey];
- saveStringOnMemBlock(ref MemBlock, startPos, totLen, valore);
- }
- catch (Exception exc)
- {
- lgError($"Errore in gestione scrittura x key {stringKey}{Environment.NewLine}{exc}");
- }
- }
- }
-
- ///
- /// Salvo in memblock il valore Int indicato con formattazione siemens
- ///
- /// Blocco memoria come byte[] dove scrivere
- /// Posizione inizio scrittura
- /// valore da scrivere
- public void saveIntOnMemBlock(ref byte[] MemBlock, int startPos, string valore)
+ public byte[] intToByte(string valore)
{
+ byte[] answ = new byte[2];
try
{
short valInt = 0;
short.TryParse(valore, out valInt);
byte[] strByte = S7.Net.Types.Int.ToByteArray(valInt);
int byteLen = 2;
- Buffer.BlockCopy(strByte, 0, MemBlock, startPos, byteLen);
- //var verifica = S7.Net.Types.String.FromByteArray(MemBlock);
+ Buffer.BlockCopy(strByte, 0, answ, 0, byteLen);
}
catch (Exception exc)
{
- lgError($"Errore in gestione scrittura INT {valore} alla posizione {startPos} byte{Environment.NewLine}{exc}");
- }
- }
- ///
- /// Salvo in memblock il valore Int indicato con formattazione siemens
- ///
- /// Blocco memoria come byte[] dove scrivere
- /// Nome del parametro da recuperare da prodData x scrivere
- /// Posizione inizio scrittura
- public void saveIntOnMemBlock(ref byte[] MemBlock, string stringKey, int startPos)
- {
- if (currProdData.ContainsKey(stringKey))
- {
- try
- {
- string valore = currProdData[stringKey];
- saveIntOnMemBlock(ref MemBlock, startPos, valore);
- }
- catch (Exception exc)
- {
- lgError($"Errore in gestione scrittura INT {stringKey}{Environment.NewLine}{exc}");
- }
- }
- }
- ///
- /// Salvo in memblock il valore DInt indicato con formattazione siemens
- ///
- /// Blocco memoria come byte[] dove scrivere
- /// Posizione inizio scrittura
- /// Valore da scrivere
- public void saveDIntOnMemBlock(ref byte[] MemBlock, int startPos, string valore)
- {
- try
- {
- int valInt = 0;
- int.TryParse(valore, out valInt);
- byte[] strByte = S7.Net.Types.DInt.ToByteArray(valInt);
- int byteLen = 4;
- Buffer.BlockCopy(strByte, 0, MemBlock, startPos, byteLen);
- //var verifica = S7.Net.Types.String.FromByteArray(MemBlock);
- }
- catch (Exception exc)
- {
- lgError($"Errore in gestione scrittura DINT {valore} alla posizione {startPos} byte{Environment.NewLine}{exc}");
- }
- }
- ///
- /// Salvo in memblock il valore DInt indicato con formattazione siemens
- ///
- /// Blocco memoria come byte[] dove scrivere
- /// Valore da scrivere
- /// Posizione inizio scrittura
- public void saveDIntOnMemBlock(ref byte[] MemBlock, string stringKey, int startPos)
- {
- if (currProdData.ContainsKey(stringKey))
- {
- try
- {
- string valore = currProdData[stringKey];
- saveDIntOnMemBlock(ref MemBlock, startPos, valore);
- }
- catch (Exception exc)
- {
- lgError($"Errore in gestione scrittura DINT {stringKey}{Environment.NewLine}{exc}");
- }
- }
- }
- ///
- /// Salvo in memblock il valore DInt indicato con formattazione siemens
- ///
- /// Blocco memoria come byte[] dove scrivere
- /// Posizione inizio scrittura
- /// Valore da scrivere
- public void saveWordOnMemBlock(ref byte[] MemBlock, int startPos, string valore)
- {
- try
- {
- byte[] stringPar = new byte[4];
- int valInt = 0;
- int.TryParse(valore, out valInt);
- byte[] strByte = S7.Net.Types.DInt.ToByteArray(valInt);
- int byteLen = 4;
- Buffer.BlockCopy(strByte, 0, MemBlock, startPos, byteLen);
- //var verifica = S7.Net.Types.String.FromByteArray(MemBlock);
- }
- catch (Exception exc)
- {
- lgError($"Errore in gestione scrittura Word {valore} alla posizione {startPos} byte{Environment.NewLine}{exc}");
- }
- }
- ///
- /// Salvo in memblock il valore DInt indicato con formattazione siemens
- ///
- /// Blocco memoria come byte[] dove scrivere
- /// Valore da scrivere
- /// Posizione inizio scrittura
- public void saveWordOnMemBlock(ref byte[] MemBlock, string stringKey, int startPos)
- {
- if (currProdData.ContainsKey(stringKey))
- {
- try
- {
- string valore = currProdData[stringKey];
- saveDIntOnMemBlock(ref MemBlock, startPos, valore);
- }
- catch (Exception exc)
- {
- lgError($"Errore in gestione scrittura DINT {stringKey}{Environment.NewLine}{exc}");
- }
- }
- }
- ///
- /// Salvo in memblock il valore DInt indicato con formattazione siemens
- ///
- /// Blocco memoria come byte[] dove scrivere
- /// Posizione inizio scrittura
- /// Valore da scrivere
- public void saveDWordOnMemBlock(ref byte[] MemBlock, int startPos, string valore)
- {
- try
- {
- byte[] stringPar = new byte[4];
- int valInt = 0;
- int.TryParse(valore, out valInt);
- byte[] strByte = S7.Net.Types.DInt.ToByteArray(valInt);
- int byteLen = 4;
- Buffer.BlockCopy(strByte, 0, MemBlock, startPos, byteLen);
- //var verifica = S7.Net.Types.String.FromByteArray(MemBlock);
- }
- catch (Exception exc)
- {
- lgError($"Errore in gestione scrittura DWord {valore} alla posizione {startPos} byte{Environment.NewLine}{exc}");
- }
- }
- ///
- /// Salvo in memblock il valore DInt indicato con formattazione siemens
- ///
- /// Blocco memoria come byte[] dove scrivere
- /// Valore da scrivere
- /// Posizione inizio scrittura
- public void saveDWordOnMemBlock(ref byte[] MemBlock, string stringKey, int startPos)
- {
- if (currProdData.ContainsKey(stringKey))
- {
- try
- {
- string valore = currProdData[stringKey];
- saveDIntOnMemBlock(ref MemBlock, startPos, valore);
- }
- catch (Exception exc)
- {
- lgError($"Errore in gestione scrittura DINT {stringKey}{Environment.NewLine}{exc}");
- }
- }
- }
- ///
- /// Salvo in memblock il valore stringa indicato con formattazione siemens
- ///
- /// Blocco memoria come byte[] dove scrivere
- /// Posizione inizio scrittura
- /// Valore scrivere
- public void saveRealOnMemBlock(ref byte[] MemBlock, int startPos, string valore)
- {
- try
- {
- byte[] stringPar = new byte[2];
-
- double valReal = 0;
- double.TryParse(valore, out valReal);
- byte[] strByte = S7.Net.Types.Double.ToByteArray(valReal);
- int byteLen = 4;
- Buffer.BlockCopy(strByte, 0, MemBlock, startPos, byteLen);
- //var verifica = S7.Net.Types.String.FromByteArray(MemBlock);
- }
- catch (Exception exc)
- {
- lgError($"Errore in gestione scrittura REAL {valore} alla posizione {startPos} byte{Environment.NewLine}{exc}");
- }
- }
- ///
- /// Salvo in memblock il valore stringa indicato con formattazione siemens
- ///
- /// Blocco memoria come byte[] dove scrivere
- /// Valore scrivere
- /// Posizione inizio scrittura
- public void saveRealOnMemBlock(ref byte[] MemBlock, string stringKey, int startPos)
- {
- if (currProdData.ContainsKey(stringKey))
- {
- try
- {
- string valore = currProdData[stringKey];
- saveRealOnMemBlock(ref MemBlock, startPos, valore);
- }
- catch (Exception exc)
- {
- lgError($"Errore in gestione scrittura REAL {stringKey}{Environment.NewLine}{exc}");
- }
+ lgError($"Errore in gestione scrittura INT {valore} in byte{Environment.NewLine}{exc}");
}
+ return answ;
}
///
@@ -473,6 +137,7 @@ namespace IOB_WIN
{
return S7ReadBB(ref Value, parametri.memAddrRead, parametri.memSizeRead);
}
+
///
/// wrapper chiamata LETTURA in blocco MULTI BYTE...
///
@@ -532,18 +197,21 @@ namespace IOB_WIN
}
}
return answ;
- }///
- /// wrapper chiamata LETTURA in blocco MULTI BYTE... default size a parametri.memSizeRead
- ///
- ///
- /// Area memoria da leggere...
- ///
+ }
+
+ ///
+ /// wrapper chiamata LETTURA in blocco MULTI BYTE... default size a parametri.memSizeRead
+ ///
+ ///
+ /// Area memoria da leggere...
+ ///
public bool S7ReadBB(ref byte[] Value, string memAddrRead)
{
bool answ = false;
answ = S7ReadBB(ref Value, memAddrRead, parametri.memSizeRead);
return answ;
}
+
///
/// wrapper chiamata SCRITTURA in blocco MULTI BYTE, DI DEFAUTL su area configurata x scrittura CONTINUA...
///
@@ -553,6 +221,7 @@ namespace IOB_WIN
{
return S7WriteBB(ref Value, parametri.memAddrWrite);
}
+
///
/// Override scrittura in area DBB
///
@@ -579,7 +248,7 @@ namespace IOB_WIN
{
try
{
- // decodifico memoria...
+ // decodifico memoria...
memAreaSiemens memoria = new memAreaSiemens(memAddrWrite);
int numByte = Value.Length;
ErrorCode errorCode = currPLC.WriteBytes(DataType.DataBlock, memoria.DbNum, memoria.indiceMem, Value);
@@ -589,6 +258,7 @@ namespace IOB_WIN
maybeLogWrite(memAddrWrite, $"Effettuata correttamente scrittura su PLC: MEMORIA {memAddrWrite} | numByte: {Value.Length} | BIN: {Value.ValToBinString()}");
answ = true;
break;
+
case ErrorCode.WrongCPU_Type:
case ErrorCode.ConnectionError:
case ErrorCode.IPAddressNotAvailable:
@@ -600,6 +270,7 @@ namespace IOB_WIN
lgError($"Errore in S7WriteBB su {memAddrWrite}: {errorCode.ToString()} | numByte: {Value.Length}| {Value.ValToBinString()}");
answ = false;
break;
+
default:
break;
}
@@ -614,35 +285,6 @@ namespace IOB_WIN
}
return answ;
}
- ///
- /// Verifica SE sia il caso di fare il log della memoria indicata
- ///
- ///
- ///
- private void maybeLogWrite(string memAddrWrite, string logValue)
- {
- bool doWrite = true;
- DateTime adesso = DateTime.Now;
- if (!lastMemWrite.ContainsKey(memAddrWrite))
- {
- lastMemWrite.Add(memAddrWrite, adesso.AddMinutes(-1));
- }
- // ora mi leggo valore ultimas crittura e confronto con adesso
- try
- {
- doWrite = (lastMemWrite[memAddrWrite].AddSeconds(vetoSeconds) < adesso);
- }
- catch (Exception exc)
- {
- lgError($"Eccezione in maybeLogWrite{Environment.NewLine}{exc}");
- }
- // se encessario --> LOG!
- if (doWrite)
- {
- lgInfo(logValue);
- lastMemWrite[memAddrWrite] = adesso;
- }
- }
///
/// Override scrittura in area DBB
@@ -678,6 +320,7 @@ namespace IOB_WIN
case ErrorCode.NoError:
lgInfo($"Effettuata correttamente scrittura su PLC: DB {DbNum}.{IndiceMem} | numByte: {Value.Length}| {Value.ValToBinString()}");
break;
+
case ErrorCode.WrongCPU_Type:
case ErrorCode.ConnectionError:
case ErrorCode.IPAddressNotAvailable:
@@ -688,6 +331,7 @@ namespace IOB_WIN
case ErrorCode.WriteData:
lgError($"Errore in S7WriteBB su DB {DbNum}.{IndiceMem}: {errorCode.ToString()} | numByte: {Value.Length}| {Value.ValToBinString()}");
break;
+
default:
break;
}
@@ -704,9 +348,393 @@ namespace IOB_WIN
return answ;
}
+ ///
+ /// Salvo in memblock il valore DInt indicato con formattazione siemens
+ ///
+ /// Blocco memoria come byte[] dove scrivere
+ /// Posizione inizio scrittura
+ /// Valore da scrivere
+ public void saveDIntOnMemBlock(ref byte[] MemBlock, int startPos, string valore)
+ {
+ try
+ {
+ int valInt = 0;
+ int.TryParse(valore, out valInt);
+ byte[] strByte = S7.Net.Types.DInt.ToByteArray(valInt);
+ int byteLen = 4;
+ Buffer.BlockCopy(strByte, 0, MemBlock, startPos, byteLen);
+ //var verifica = S7.Net.Types.String.FromByteArray(MemBlock);
+ }
+ catch (Exception exc)
+ {
+ lgError($"Errore in gestione scrittura DINT {valore} alla posizione {startPos} byte{Environment.NewLine}{exc}");
+ }
+ }
+ ///
+ /// Salvo in memblock il valore DInt indicato con formattazione siemens
+ ///
+ /// Blocco memoria come byte[] dove scrivere
+ /// Valore da scrivere
+ /// Posizione inizio scrittura
+ public void saveDIntOnMemBlock(ref byte[] MemBlock, string stringKey, int startPos)
+ {
+ if (currProdData.ContainsKey(stringKey))
+ {
+ try
+ {
+ string valore = currProdData[stringKey];
+ saveDIntOnMemBlock(ref MemBlock, startPos, valore);
+ }
+ catch (Exception exc)
+ {
+ lgError($"Errore in gestione scrittura DINT {stringKey}{Environment.NewLine}{exc}");
+ }
+ }
+ }
- #endregion
+ ///
+ /// Salvo in memblock il valore DInt indicato con formattazione siemens
+ ///
+ /// Blocco memoria come byte[] dove scrivere
+ /// Posizione inizio scrittura
+ /// Valore da scrivere
+ public void saveDWordOnMemBlock(ref byte[] MemBlock, int startPos, string valore)
+ {
+ try
+ {
+ byte[] stringPar = new byte[4];
+ int valInt = 0;
+ int.TryParse(valore, out valInt);
+ byte[] strByte = S7.Net.Types.DInt.ToByteArray(valInt);
+ int byteLen = 4;
+ Buffer.BlockCopy(strByte, 0, MemBlock, startPos, byteLen);
+ //var verifica = S7.Net.Types.String.FromByteArray(MemBlock);
+ }
+ catch (Exception exc)
+ {
+ lgError($"Errore in gestione scrittura DWord {valore} alla posizione {startPos} byte{Environment.NewLine}{exc}");
+ }
+ }
+
+ ///
+ /// Salvo in memblock il valore DInt indicato con formattazione siemens
+ ///
+ /// Blocco memoria come byte[] dove scrivere
+ /// Valore da scrivere
+ /// Posizione inizio scrittura
+ public void saveDWordOnMemBlock(ref byte[] MemBlock, string stringKey, int startPos)
+ {
+ if (currProdData.ContainsKey(stringKey))
+ {
+ try
+ {
+ string valore = currProdData[stringKey];
+ saveDIntOnMemBlock(ref MemBlock, startPos, valore);
+ }
+ catch (Exception exc)
+ {
+ lgError($"Errore in gestione scrittura DINT {stringKey}{Environment.NewLine}{exc}");
+ }
+ }
+ }
+
+ ///
+ /// Salvo in memblock il valore Int indicato con formattazione siemens
+ ///
+ /// Blocco memoria come byte[] dove scrivere
+ /// Posizione inizio scrittura
+ /// valore da scrivere
+ public void saveIntOnMemBlock(ref byte[] MemBlock, int startPos, string valore)
+ {
+ try
+ {
+ short valInt = 0;
+ short.TryParse(valore, out valInt);
+ byte[] strByte = S7.Net.Types.Int.ToByteArray(valInt);
+ int byteLen = 2;
+ Buffer.BlockCopy(strByte, 0, MemBlock, startPos, byteLen);
+ //var verifica = S7.Net.Types.String.FromByteArray(MemBlock);
+ }
+ catch (Exception exc)
+ {
+ lgError($"Errore in gestione scrittura INT {valore} alla posizione {startPos} byte{Environment.NewLine}{exc}");
+ }
+ }
+
+ ///
+ /// Salvo in memblock il valore Int indicato con formattazione siemens
+ ///
+ /// Blocco memoria come byte[] dove scrivere
+ /// Nome del parametro da recuperare da prodData x scrivere
+ /// Posizione inizio scrittura
+ public void saveIntOnMemBlock(ref byte[] MemBlock, string stringKey, int startPos)
+ {
+ if (currProdData.ContainsKey(stringKey))
+ {
+ try
+ {
+ string valore = currProdData[stringKey];
+ saveIntOnMemBlock(ref MemBlock, startPos, valore);
+ }
+ catch (Exception exc)
+ {
+ lgError($"Errore in gestione scrittura INT {stringKey}{Environment.NewLine}{exc}");
+ }
+ }
+ }
+
+ ///
+ /// Salvo in memblock il valore stringa indicato con formattazione siemens
+ ///
+ /// Blocco memoria come byte[] dove scrivere
+ /// Posizione inizio scrittura
+ /// Valore scrivere
+ public void saveRealOnMemBlock(ref byte[] MemBlock, int startPos, string valore)
+ {
+ try
+ {
+ byte[] stringPar = new byte[2];
+
+ double valReal = 0;
+ double.TryParse(valore, out valReal);
+ byte[] strByte = S7.Net.Types.Double.ToByteArray(valReal);
+ int byteLen = 4;
+ Buffer.BlockCopy(strByte, 0, MemBlock, startPos, byteLen);
+ //var verifica = S7.Net.Types.String.FromByteArray(MemBlock);
+ }
+ catch (Exception exc)
+ {
+ lgError($"Errore in gestione scrittura REAL {valore} alla posizione {startPos} byte{Environment.NewLine}{exc}");
+ }
+ }
+
+ ///
+ /// Salvo in memblock il valore stringa indicato con formattazione siemens
+ ///
+ /// Blocco memoria come byte[] dove scrivere
+ /// Valore scrivere
+ /// Posizione inizio scrittura
+ public void saveRealOnMemBlock(ref byte[] MemBlock, string stringKey, int startPos)
+ {
+ if (currProdData.ContainsKey(stringKey))
+ {
+ try
+ {
+ string valore = currProdData[stringKey];
+ saveRealOnMemBlock(ref MemBlock, startPos, valore);
+ }
+ catch (Exception exc)
+ {
+ lgError($"Errore in gestione scrittura REAL {stringKey}{Environment.NewLine}{exc}");
+ }
+ }
+ }
+
+ ///
+ /// Salvo in memblock il valore stringa indicato con formattazione siemens
+ ///
+ /// Blocco memoria come byte[] dove scrivere
+ /// Posizione inizio scrittura
+ /// Lunghezza max stringa (se ci sono 2 byte iniziali verrà ridotta di 2)
+ /// valore da scrivere
+ public void saveStringOnMemBlock(ref byte[] MemBlock, int startPos, int totLen, string valore)
+ {
+ if (MemBlock != null)
+ {
+ // loggare valore? fornire un output con memBlock e NON ref?
+ try
+ {
+ lgInfo($"saveStringOnMemBlock: MemBlock size: {MemBlock.Length} | startPos: {startPos} | totLen: {totLen} | valore: {valore}");
+ byte[] stringPar = new byte[2];
+ byte[] strByte = S7.Net.Types.String.ToByteArray(valore);
+ int byteLen = strByte.Length <= totLen ? strByte.Length : totLen;
+ int shiftStrByte = writePre ? 2 : 0;
+ if (writePre)
+ {
+ // MAX LUN
+ stringPar[1] = (byte)totLen;
+ // LUNGH STRING
+ stringPar[0] = (byte)byteLen;
+ Buffer.BlockCopy(stringPar, 0, MemBlock, startPos, shiftStrByte);
+ }
+ Buffer.BlockCopy(strByte, 0, MemBlock, startPos + shiftStrByte, byteLen);
+ }
+ catch (Exception exc)
+ {
+ lgError($"Errore in gestione scrittura {valore} alla posizione {startPos} per {totLen} byte{Environment.NewLine}{exc}");
+ }
+ }
+ else
+ {
+ lgError("Errore: MemBlock nullo");
+ }
+ }
+
+ ///
+ /// Salvo in memblock il valore stringa indicato con formattazione siemens
+ ///
+ /// Blocco memoria come byte[] dove scrivere
+ /// Nome del parametro da recuperare da prodData x scrivere
+ /// Posizione inizio scrittura
+ /// Lunghezza max stringa (se ci sono 2 byte iniziali verrà ridotta di 2)
+ public void saveStringOnMemBlock(ref byte[] MemBlock, string stringKey, int startPos, int totLen)
+ {
+ if (currProdData.ContainsKey(stringKey))
+ {
+ try
+ {
+ string valore = currProdData[stringKey];
+ saveStringOnMemBlock(ref MemBlock, startPos, totLen, valore);
+ }
+ catch (Exception exc)
+ {
+ lgError($"Errore in gestione scrittura x key {stringKey}{Environment.NewLine}{exc}");
+ }
+ }
+ }
+
+ ///
+ /// Salvo in memblock il valore DInt indicato con formattazione siemens
+ ///
+ /// Blocco memoria come byte[] dove scrivere
+ /// Posizione inizio scrittura
+ /// Valore da scrivere
+ public void saveWordOnMemBlock(ref byte[] MemBlock, int startPos, string valore)
+ {
+ try
+ {
+ byte[] stringPar = new byte[4];
+ int valInt = 0;
+ int.TryParse(valore, out valInt);
+ byte[] strByte = S7.Net.Types.DInt.ToByteArray(valInt);
+ int byteLen = 4;
+ Buffer.BlockCopy(strByte, 0, MemBlock, startPos, byteLen);
+ //var verifica = S7.Net.Types.String.FromByteArray(MemBlock);
+ }
+ catch (Exception exc)
+ {
+ lgError($"Errore in gestione scrittura Word {valore} alla posizione {startPos} byte{Environment.NewLine}{exc}");
+ }
+ }
+
+ ///
+ /// Salvo in memblock il valore DInt indicato con formattazione siemens
+ ///
+ /// Blocco memoria come byte[] dove scrivere
+ /// Valore da scrivere
+ /// Posizione inizio scrittura
+ public void saveWordOnMemBlock(ref byte[] MemBlock, string stringKey, int startPos)
+ {
+ if (currProdData.ContainsKey(stringKey))
+ {
+ try
+ {
+ string valore = currProdData[stringKey];
+ saveDIntOnMemBlock(ref MemBlock, startPos, valore);
+ }
+ catch (Exception exc)
+ {
+ lgError($"Errore in gestione scrittura DINT {stringKey}{Environment.NewLine}{exc}");
+ }
+ }
+ }
+
+ ///
+ /// Converte direttamente un valore stringa su un oggetto byte[] (senza limitazioni di dimensione)
+ ///
+ ///
+ /// Dimensione massima ammessa per la stringa
+ ///
+ public byte[] stringToByte(string valore, int maxLenght)
+ {
+ byte[] answ = new byte[1];
+ byte[] stringPar = new byte[2];
+ byte[] strByte = S7.Net.Types.String.ToByteArray(valore);
+ int shiftStrByte = writePre ? 2 : 0;
+ int byteLen = strByte.Length <= maxLenght ? strByte.Length : maxLenght;
+ if (writePre)
+ {
+ // MAX LUN
+ stringPar[1] = (byte)maxLenght;
+ // LUNGH STRING
+ stringPar[0] = (byte)byteLen;
+ Buffer.BlockCopy(stringPar, 0, answ, 0, shiftStrByte);
+ }
+ Buffer.BlockCopy(strByte, 0, answ, shiftStrByte, byteLen);
+ return answ;
+ }
+
+ ///
+ /// Inserimento/aggiornamento chiavi/valore in currProdData
+ ///
+ ///
+ ///
+ public void upsertKey(string chiave, string valore)
+ {
+ if (currProdData.ContainsKey(chiave))
+ {
+ currProdData[chiave] = valore;
+ }
+ else
+ {
+ currProdData.Add(chiave, valore);
+ }
+ }
+
+ ///
+ /// Converte direttamente un valore UInt16 su un oggetto byte[2]
+ ///
+ /// valore da scrivere
+ public byte[] wordToByte(string valore)
+ {
+ byte[] answ = new byte[2];
+ try
+ {
+ ushort valInt = 0;
+ ushort.TryParse(valore, out valInt);
+ byte[] strByte = S7.Net.Types.Word.ToByteArray(valInt);
+ int byteLen = 2;
+ Buffer.BlockCopy(strByte, 0, answ, 0, byteLen);
+ }
+ catch (Exception exc)
+ {
+ lgError($"Errore in gestione scrittura INT {valore} in byte{Environment.NewLine}{exc}");
+ }
+ return answ;
+ }
+
+ ///
+ /// Verifica SE sia il caso di fare il log della memoria indicata
+ ///
+ ///
+ ///
+ private void maybeLogWrite(string memAddrWrite, string logValue)
+ {
+ bool doWrite = true;
+ DateTime adesso = DateTime.Now;
+ if (!lastMemWrite.ContainsKey(memAddrWrite))
+ {
+ lastMemWrite.Add(memAddrWrite, adesso.AddMinutes(-1));
+ }
+ // ora mi leggo valore ultimas crittura e confronto con adesso
+ try
+ {
+ doWrite = (lastMemWrite[memAddrWrite].AddSeconds(vetoSeconds) < adesso);
+ }
+ catch (Exception exc)
+ {
+ lgError($"Eccezione in maybeLogWrite{Environment.NewLine}{exc}");
+ }
+ // se encessario --> LOG!
+ if (doWrite)
+ {
+ lgInfo(logValue);
+ lastMemWrite[memAddrWrite] = adesso;
+ }
+ }
+
+ #endregion area metodi lettura/Scrittura
#region area principale adapter
@@ -758,49 +786,131 @@ namespace IOB_WIN
}
///
- /// Test connessione CNC
+ /// Override connessione
///
- ///
- protected bool testCncConn()
+ public override void tryConnect()
{
- bool answ = false;
-
- IPStatus pingStatus = testPingMachine;
- // se passa il ping faccio il resto...
- if (pingStatus != IPStatus.Success)
+ bool doLog = (verboseLog || periodicLog);
+ lgInfo("SIEMENS: tryConnect step 01");
+ if (!connectionOk)
{
- lgError(string.Format("Errore in testCncConn: reply Status per {0}: {1}", parametri.ipAdrr, pingStatus));
- }
- else
- {
- if (!currPLC.IsConnected)
+ // SE è necessario refresh...
+ if (needRefresh)
{
- currPLC.Open();
- }
+ lgInfo("SIEMENS: tryConnect step 02");
- if (!currPLC.IsAvailable)
- {
- lgError(string.Format("PLC Siemens NON disponibile:{0} | {1}", currPLC.LastErrorCode, currPLC.LastErrorString));
- currPLC.ClearLastError();
+ // reimporto parametri PLC se necessario...
+ setParamPlc();
}
- else
+ lgInfo("SIEMENS: tryConnect step 03");
+
+ // controllo che il ping sia stato tentato almeno pingTestSec fa...
+ if (DateTime.Now.Subtract(lastPING).TotalSeconds > utils.CRI("pingTestSec"))
{
- if (!currPLC.IsConnected && !pingDisabled)
+ if (doLog)
{
- lgError(string.Format("PLC Siemens NON connesso:{0} | {1}", currPLC.LastErrorCode, currPLC.LastErrorString));
- currPLC.ClearLastError();
- parentForm.updateComStats("NO connection");
+ lgInfo("SIEMENS: ConnKO - tryConnect");
+ }
+ lgInfo("SIEMENS: tryConnect step 04");
+
+ // in primis salvo data ping...
+ lastPING = DateTime.Now;
+ // se passa il ping faccio il resto...
+ if (testPingMachine == IPStatus.Success)
+ {
+ string szStatusConnection = "";
+ try
+ {
+ // ora provo connessione...
+ parentForm.commPlcActive = true;
+ currPLC.Open();
+ parentForm.commPlcActive = false;
+ lgInfo("szStatusConnection: " + szStatusConnection);
+ connectionOk = true;
+ // refresh stato allarmi!!!
+ if (connectionOk)
+ {
+ if (adpRunning)
+ {
+ lgInfo("Connessione OK");
+ }
+ }
+ else
+ {
+ lgError("Impossibile procedere, connessione mancante...");
+ }
+ }
+ catch (Exception exc)
+ {
+ lgFatal(string.Format("Errore in TryConnect adapter SIEMENS: {0}{1}{2}", szStatusConnection, Environment.NewLine, exc));
+ connectionOk = false;
+ needRefresh = true;
+ }
}
else
{
- parentForm.updateComStats("Connection OK");
- answ = true;
+ // loggo no risposta ping ...
+ connectionOk = false;
+ if (doLog)
+ {
+ lgInfo(string.Format("Attenzione: SIEMENS controllo PING fallito per IP {0}", cIobConf.cncIpAddr));
+ }
}
}
}
+ // se non è ancora connesso faccio procesisng memoria caso disconnesso...
+ if (!connectionOk)
+ {
+ // processo semafori ed invio...
+ processMemoryDiscon();
+ }
+ }
+ ///
+ /// Override disconnessione
+ ///
+ public override void tryDisconnect()
+ {
+ if (connectionOk)
+ {
+ string szStatusConnection = "";
+ try
+ {
+ currPLC.Close();
+ connectionOk = false;
+ lgInfo(szStatusConnection);
+ lgInfo("Effettuata disconnessione adapter SIEMENS!");
+ }
+ catch (Exception exc)
+ {
+ lgFatal(exc, "Errore nella disconnessione dall'adapter SIEMENS");
+ }
+ }
+ else
+ {
+ lgError("IMPOSSIBILE effettuare disconnessione SIEMENS: Connessione non disponibile...");
+ }
+ }
+
+ ///
+ /// Restituisce path completo file da chiave configurazione
+ ///
+ /// chiave conf x file richiesto
+ ///
+ protected string filePath(string keyFile)
+ {
+ string answ = "";
+ try
+ {
+ answ = $"{utils.confDir}\\{utils.CRS(keyFile)}";
+ }
+ catch (Exception exc)
+ {
+ lgError(exc, "Eccezione in recupero filePath");
+ }
return answ;
}
+
///
/// Imposto parametri PLC
///
@@ -922,133 +1032,179 @@ namespace IOB_WIN
}
}
}
+
///
- /// Override disconnessione
+ /// Test connessione CNC
///
- public override void tryDisconnect()
+ ///
+ protected bool testCncConn()
{
- if (connectionOk)
+ bool answ = false;
+
+ IPStatus pingStatus = testPingMachine;
+ // se passa il ping faccio il resto...
+ if (pingStatus != IPStatus.Success)
{
- string szStatusConnection = "";
- try
+ lgError(string.Format("Errore in testCncConn: reply Status per {0}: {1}", parametri.ipAdrr, pingStatus));
+ }
+ else
+ {
+ if (!currPLC.IsConnected)
{
- currPLC.Close();
- connectionOk = false;
- lgInfo(szStatusConnection);
- lgInfo("Effettuata disconnessione adapter SIEMENS!");
+ currPLC.Open();
}
- catch (Exception exc)
+
+ if (!currPLC.IsAvailable)
{
- lgFatal(exc, "Errore nella disconnessione dall'adapter SIEMENS");
+ lgError(string.Format("PLC Siemens NON disponibile:{0} | {1}", currPLC.LastErrorCode, currPLC.LastErrorString));
+ currPLC.ClearLastError();
+ }
+ else
+ {
+ if (!currPLC.IsConnected && !pingDisabled)
+ {
+ lgError(string.Format("PLC Siemens NON connesso:{0} | {1}", currPLC.LastErrorCode, currPLC.LastErrorString));
+ currPLC.ClearLastError();
+ parentForm.updateComStats("NO connection");
+ }
+ else
+ {
+ parentForm.updateComStats("Connection OK");
+ answ = true;
+ }
+ }
+ }
+
+ return answ;
+ }
+
+ #endregion area principale adapter
+
+ #region Metodi specifici (da verificare/completare in implementazione)
+
+ ///
+ /// Metodo dispose x il currPLC contenuto
+ ///
+ public void Dispose()
+ {
+ currPLC.Dispose();
+ }
+
+ ///
+ /// Recupero dati dinamici...
+ ///
+ public override Dictionary getDynData()
+ {
+ // valore non presente in vers default... se gestito fare override
+ Dictionary outVal = new Dictionary();
+ if (utils.CRB("enableTSVC"))
+ {
+ // processing SOLO SE ho in memoria abbastanza dati...
+ if (RawInput.Length < parametri.memSizeRead)
+ {
+ lgError($"Impossibile processare getDynData x Siemens PLC, vettore memoria troppo piccolo: {RawInput.Length} byte / {parametri.memSizeRead} byte presenti/richiesti)");
+ }
+ else
+ {
+ try
+ {
+ // processo x ogni valore configurato...
+ if (memMap.mMapRead.Count > 0)
+ {
+ // inizializzo i valori
+ bool valBool = false;
+ double valore = 0;
+ string valString = "";
+ lgInfo("Ciclo recupero dati getDynData");
+ // procedo x ogni valore configurato......
+ foreach (var item in memMap.mMapRead)
+ {
+ // in primis DEVO determinare di quale TIPO di valore ho bisogno...
+ switch (item.Value.tipoMem)
+ {
+ case plcDataType.Boolean:
+ valBool = S7.Net.Types.Boolean.GetValue(RawInput[item.Value.index], item.Value.size);
+ break;
+
+ case plcDataType.Int:
+ valore = ((double)S7.Net.Types.Int.FromByteArray(RawInput.Skip(item.Value.index).Take(item.Value.size).ToArray())) / item.Value.factor;
+ saveValue(ref outVal, valore, item.Key);
+ break;
+
+ case plcDataType.DInt:
+ valore = ((double)S7.Net.Types.DInt.FromByteArray(RawInput.Skip(item.Value.index).Take(item.Value.size).ToArray())) / item.Value.factor;
+ saveValue(ref outVal, valore, item.Key);
+ break;
+
+ case plcDataType.Word:
+ valore = ((double)S7.Net.Types.Word.FromByteArray(RawInput.Skip(item.Value.index).Take(item.Value.size).ToArray())) / item.Value.factor;
+ saveValue(ref outVal, valore, item.Key);
+ break;
+
+ case plcDataType.DWord:
+ valore = ((double)S7.Net.Types.DWord.FromByteArray(RawInput.Skip(item.Value.index).Take(item.Value.size).ToArray())) / item.Value.factor;
+ saveValue(ref outVal, valore, item.Key);
+ break;
+
+ case plcDataType.Real:
+ valore = S7.Net.Types.Double.FromByteArray(RawInput.Skip(item.Value.index).Take(item.Value.size).ToArray()) / item.Value.factor;
+ saveValue(ref outVal, valore, item.Key);
+ break;
+
+ case plcDataType.String:
+ valString = S7.Net.Types.String.FromByteArray(RawInput.Skip(item.Value.index).Take(item.Value.size).ToArray());
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+ else
+ {
+ lgInfo($"getDynData: {memMap.mMapRead.Count} record in mMapRead");
+ }
+ }
+ catch (Exception exc)
+ {
+ lgError(exc, "Errore in getDynData x Siemens PLC");
+ }
}
}
else
{
- lgError("IMPOSSIBILE effettuare disconnessione SIEMENS: Connessione non disponibile...");
+ lgInfo($"Non processo getDynData: enableTSVC = false");
}
- }
- ///
- /// Override connessione
- ///
- public override void tryConnect()
- {
- bool doLog = (verboseLog || periodicLog);
- lgInfo("SIEMENS: tryConnect step 01");
- if (!connectionOk)
+ if (periodicLog || outVal.Count > 0)
{
- // SE è necessario refresh...
- if (needRefresh)
- {
- lgInfo("SIEMENS: tryConnect step 02");
-
- // reimporto parametri PLC se necessario...
- setParamPlc();
- }
- lgInfo("SIEMENS: tryConnect step 03");
-
- // controllo che il ping sia stato tentato almeno pingTestSec fa...
- if (DateTime.Now.Subtract(lastPING).TotalSeconds > utils.CRI("pingTestSec"))
- {
- if (doLog)
- {
- lgInfo("SIEMENS: ConnKO - tryConnect");
- }
- lgInfo("SIEMENS: tryConnect step 04");
-
- // in primis salvo data ping...
- lastPING = DateTime.Now;
- // se passa il ping faccio il resto...
- if (testPingMachine == IPStatus.Success)
- {
- string szStatusConnection = "";
- try
- {
- // ora provo connessione...
- parentForm.commPlcActive = true;
- currPLC.Open();
- parentForm.commPlcActive = false;
- lgInfo("szStatusConnection: " + szStatusConnection);
- connectionOk = true;
- // refresh stato allarmi!!!
- if (connectionOk)
- {
- if (adpRunning)
- {
- lgInfo("Connessione OK");
- }
- }
- else
- {
- lgError("Impossibile procedere, connessione mancante...");
- }
- }
- catch (Exception exc)
- {
- lgFatal(string.Format("Errore in TryConnect adapter SIEMENS: {0}{1}{2}", szStatusConnection, Environment.NewLine, exc));
- connectionOk = false;
- needRefresh = true;
- }
- }
- else
- {
- // loggo no risposta ping ...
- connectionOk = false;
- if (doLog)
- {
- lgInfo(string.Format("Attenzione: SIEMENS controllo PING fallito per IP {0}", cIobConf.cncIpAddr));
- }
- }
- }
- }
- // se non è ancora connesso faccio procesisng memoria caso disconnesso...
- if (!connectionOk)
- {
- // processo semafori ed invio...
- processMemoryDiscon();
+ lgInfo($"Esito getDynData: {outVal.Count} valori VALIDI in outVal");
}
+ return outVal;
}
+
///
- /// Restituisce path completo file da chiave configurazione
+ /// Recupero programma in lavorazione
///
- /// chiave conf x file richiesto
///
- protected string filePath(string keyFile)
+ public override string getPrgName()
{
- string answ = "";
- try
- {
- answ = $"{utils.confDir}\\{utils.CRS(keyFile)}";
- }
- catch (Exception exc)
- {
- lgError(exc, "Eccezione in recupero filePath");
- }
- return answ;
+ // valore non presente in vers default... se gestito fare override
+ string prgName = "";
+ return prgName;
}
- #endregion
-
- #region Metodi specifici (da verificare/completare in implementazione)
+ ///
+ /// Recupero programma in lavorazione come Dictionary FANUC...
+ /// - SYSINFO: (prima KEY globale) TUTTI i valori separati da # (x fare check modifica)
+ /// - altre stringhe: ogni singolo parametro / valore
+ ///
+ ///
+ public override Dictionary getSysInfo()
+ {
+ // valore non presente in vers default... se gestito fare override
+ Dictionary outVal = new Dictionary();
+ return outVal;
+ }
///
/// Effettua vero processing contapezzi
@@ -1084,18 +1240,22 @@ namespace IOB_WIN
byte valB = RawInput[areaCounter.indiceMem];
outputVal = valB;
break;
+
case "W":
ushort valW = S7.Net.Types.Word.FromByteArray(RawInput.Skip(areaCounter.indiceMem).Take(2).ToArray());
outputVal = valW;
break;
+
case "DW":
- uint valDW = S7.Net.Types.Word.FromByteArray(RawInput.Skip(areaCounter.indiceMem).Take(4).ToArray());
+ uint valDW = S7.Net.Types.DWord.FromByteArray(RawInput.Skip(areaCounter.indiceMem).Take(4).ToArray());
outputVal = valDW;
break;
+
case "RE":
double valRe = S7.Net.Types.Double.FromByteArray(RawInput.Skip(areaCounter.indiceMem).Take(4).ToArray());
outputVal = valRe;
break;
+
default:
break;
}
@@ -1133,27 +1293,31 @@ namespace IOB_WIN
{
case "B":
MemBlockPZ = new byte[1];
- fatto = S7ReadBB(ref MemBlockPZ,memAddr,1);
+ fatto = S7ReadBB(ref MemBlockPZ, memAddr, 1);
outputVal = MemBlockPZ[0];
break;
+
case "W":
MemBlockPZ = new byte[2];
fatto = S7ReadBB(ref MemBlockPZ, memAddr, 2);
ushort valW = S7.Net.Types.Word.FromByteArray(MemBlockPZ.ToArray());
outputVal = valW;
break;
+
case "DW":
MemBlockPZ = new byte[4];
fatto = S7ReadBB(ref MemBlockPZ, memAddr, 4);
uint valDW = S7.Net.Types.DWord.FromByteArray(MemBlockPZ.ToArray());
outputVal = valDW;
break;
+
case "RE":
MemBlockPZ = new byte[4];
fatto = S7ReadBB(ref MemBlockPZ, memAddr, 4);
double valRe = S7.Net.Types.Double.FromByteArray(MemBlockPZ.ToArray());
outputVal = valRe;
break;
+
default:
break;
}
@@ -1177,6 +1341,18 @@ namespace IOB_WIN
}
}
}
+
+ ///
+ /// Esegue processing MODE (e nel contempo recupera altri dati dell'area G)
+ ///
+ public override void processMode()
+ {
+ // valore non presente in vers default... se gestito fare override
+ if (utils.CRB("enableMode"))
+ {
+ }
+ }
+
///
/// Effettua lettura semafori principale
/// Parametri da aggiornare x display in form
@@ -1200,7 +1376,7 @@ namespace IOB_WIN
{
lgInfo(string.Format("RawInput[0]: {0}", utils.binaryForm(RawInput[0])));
}
- // salvo il solo BYTE dell'input decifrando il semaforo...
+ // salvo il solo BYTE dell'input decifrando il semaforo...
decodeToBaseBitmap();
decodeOtherData();
// riporto bitmap...
@@ -1211,6 +1387,7 @@ namespace IOB_WIN
currDispData.semIn = Semaforo.SR;
}
}
+
///
/// decodifica da bitmap il CURRENT MODE del controllo
///
@@ -1230,7 +1407,7 @@ namespace IOB_WIN
* B1 (02) = MDI
* B2 (04) = JOG
* B3 (08) = TeachIN (associato a MDI --> 10)
- * B4 (16) = Repos (associato a JOG --> 20)
+ * B4 (16) = Repos (associato a JOG --> 20)
* B5 (32) = RefPoint (associato a Jog --> 36)
* B6 (64) = Incr1 (associato a Jog --> 68)
* B7 (128) = Incr10 (associato a Jog --> -124 / 132 se UInt)
@@ -1272,6 +1449,7 @@ namespace IOB_WIN
}
return answ;
}
+
///
/// Decodifica il resto dell'area x i dati accessori (allarmi, ...)
///
@@ -1279,9 +1457,9 @@ namespace IOB_WIN
{
if (verboseLog)
{
-
}
}
+
///
/// Effettua decodifica aree memoria alla bitmap usata x MAPO
///
@@ -1290,122 +1468,7 @@ namespace IOB_WIN
// init a zero...
B_input = 0;
}
- ///
- /// Recupero programma in lavorazione
- ///
- ///
- public override string getPrgName()
- {
- // valore non presente in vers default... se gestito fare override
- string prgName = "";
- return prgName;
- }
- ///
- /// Recupero programma in lavorazione come Dictionary FANUC...
- /// - SYSINFO: (prima KEY globale) TUTTI i valori separati da # (x fare check modifica)
- /// - altre stringhe: ogni singolo parametro / valore
- ///
- ///
- public override Dictionary getSysInfo()
- {
- // valore non presente in vers default... se gestito fare override
- Dictionary outVal = new Dictionary();
- return outVal;
- }
- ///
- /// Esegue processing MODE (e nel contempo recupera altri dati dell'area G)
- ///
- public override void processMode()
- {
- // valore non presente in vers default... se gestito fare override
- if (utils.CRB("enableMode"))
- {
- }
- }
- ///
- /// Recupero dati dinamici...
- ///
- public override Dictionary getDynData()
- {
- // valore non presente in vers default... se gestito fare override
- Dictionary outVal = new Dictionary();
- if (utils.CRB("enableTSVC"))
- {
- // processing SOLO SE ho in memoria abbastanza dati...
- if (RawInput.Length < parametri.memSizeRead)
- {
- lgError($"Impossibile processare getDynData x Siemens PLC, vettore memoria troppo piccolo: {RawInput.Length} byte / {parametri.memSizeRead} byte presenti/richiesti)");
- }
- else
- {
- try
- {
- // processo x ogni valore configurato...
- if (memMap.mMapRead.Count > 0)
- {
- // inizializzo i valori
- bool valBool = false;
- double valore = 0;
- string valString = "";
- lgInfo("Ciclo recupero dati getDynData");
- // procedo x ogni valore configurato......
- foreach (var item in memMap.mMapRead)
- {
- // in primis DEVO determinare di quale TIPO di valore ho bisogno...
- switch (item.Value.tipoMem)
- {
- case plcDataType.Boolean:
- valBool = S7.Net.Types.Boolean.GetValue(RawInput[item.Value.index], item.Value.size);
- break;
- case plcDataType.Int:
- valore = ((double)S7.Net.Types.Int.FromByteArray(RawInput.Skip(item.Value.index).Take(item.Value.size).ToArray())) / item.Value.factor;
- saveValue(ref outVal, valore, item.Key);
- break;
- case plcDataType.DInt:
- valore = ((double)S7.Net.Types.DInt.FromByteArray(RawInput.Skip(item.Value.index).Take(item.Value.size).ToArray())) / item.Value.factor;
- saveValue(ref outVal, valore, item.Key);
- break;
- case plcDataType.Word:
- valore = ((double)S7.Net.Types.Word.FromByteArray(RawInput.Skip(item.Value.index).Take(item.Value.size).ToArray())) / item.Value.factor;
- saveValue(ref outVal, valore, item.Key);
- break;
- case plcDataType.DWord:
- valore = ((double)S7.Net.Types.DWord.FromByteArray(RawInput.Skip(item.Value.index).Take(item.Value.size).ToArray())) / item.Value.factor;
- saveValue(ref outVal, valore, item.Key);
- break;
- case plcDataType.Real:
- valore = S7.Net.Types.Double.FromByteArray(RawInput.Skip(item.Value.index).Take(item.Value.size).ToArray()) / item.Value.factor;
- saveValue(ref outVal, valore, item.Key);
- break;
- case plcDataType.String:
- valString = S7.Net.Types.String.FromByteArray(RawInput.Skip(item.Value.index).Take(item.Value.size).ToArray());
- break;
- default:
- break;
- }
- }
- }
- else
- {
- lgInfo($"getDynData: {memMap.mMapRead.Count} record in mMapRead");
- }
- }
- catch (Exception exc)
- {
- lgError(exc, "Errore in getDynData x Siemens PLC");
- }
- }
- }
- else
- {
- lgInfo($"Non processo getDynData: enableTSVC = false");
- }
- if (periodicLog || outVal.Count > 0)
- {
- lgInfo($"Esito getDynData: {outVal.Count} valori VALIDI in outVal");
- }
- return outVal;
- }
+
///
/// OVerride metodo x scrittura parametri su PLC
///
@@ -1447,25 +1510,31 @@ namespace IOB_WIN
{
case plcDataType.Boolean:
break;
+
case plcDataType.Int:
valInt = getScaledInt(currMem);
saveIntOnMemBlock(ref MemBlock, 0, valInt.ToString());
break;
+
case plcDataType.DInt:
valInt = getScaledInt(currMem);
saveDIntOnMemBlock(ref MemBlock, 0, valInt.ToString());
break;
+
case plcDataType.Word:
valUInt = getScaledUInt(currMem);
saveWordOnMemBlock(ref MemBlock, 0, valInt.ToString());
break;
+
case plcDataType.DWord:
valUInt = getScaledUInt(currMem);
saveDWordOnMemBlock(ref MemBlock, 0, valInt.ToString());
break;
+
case plcDataType.Real:
saveRealOnMemBlock(ref MemBlock, 0, currMem.value);
break;
+
case plcDataType.String:
// se ho writePre --> "allungo" di 2 la dimensione della stringa x MemBlock...
if (writePre)
@@ -1474,6 +1543,7 @@ namespace IOB_WIN
}
saveStringOnMemBlock(ref MemBlock, 0, currMem.size, currMem.value);
break;
+
default:
break;
}
@@ -1528,6 +1598,7 @@ namespace IOB_WIN
return valInt;
}
+
private static uint getScaledUInt(dataConf currMem)
{
uint valUInt;
@@ -1541,14 +1612,6 @@ namespace IOB_WIN
return valUInt;
}
- ///
- /// Metodo dispose x il currPLC contenuto
- ///
- public void Dispose()
- {
- currPLC.Dispose();
- }
-
- #endregion
+ #endregion Metodi specifici (da verificare/completare in implementazione)
}
-}
+}
\ No newline at end of file