Fix scrittura stringhe siemens metodo comune
This commit is contained in:
+76
-5
@@ -32,6 +32,10 @@ namespace IOB_WIN
|
||||
/// </summary>
|
||||
protected int maxStrChar = 20;
|
||||
/// <summary>
|
||||
/// indica se scrivere i primi byte x string siemens x indicare lung max e corrente
|
||||
/// </summary>
|
||||
protected bool writePre = true;
|
||||
/// <summary>
|
||||
/// Oggetto PLC da ri-utilizzare...
|
||||
/// </summary>
|
||||
protected Plc currPLC;
|
||||
@@ -52,18 +56,18 @@ namespace IOB_WIN
|
||||
/// Salvo in memblock il valore stringa indicato con formattazione siemens
|
||||
/// </summary>
|
||||
/// <param name="MemBlock">Blocco memoria come byte[] dove scrivere</param>
|
||||
/// <param name="stringValue">Valore stringa da scrivere</param>
|
||||
/// <param name="stringKey">Nome del parametro da recuperare da prodData x scrivere</param>
|
||||
/// <param name="startPos">Posizione inizio scrittura</param>
|
||||
/// <param name="totLen">Lunghezza max stringa (se ci sono 2 byte iniziali verrà ridotta di 2)</param>
|
||||
/// <param name="writePre">Indica se scrivere i dati preliminari di lunghezza stringa max/occupata</param>
|
||||
public void saveStringOnMemBlock(ref byte[] MemBlock, string stringValue, int startPos, int totLen, bool writePre)
|
||||
public void saveStringOnMemBlock(ref byte[] MemBlock, string stringKey, int startPos, int totLen)
|
||||
{
|
||||
if (currProdData.ContainsKey(stringValue))
|
||||
if (currProdData.ContainsKey(stringKey))
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] stringPar = new byte[2];
|
||||
string valore = currProdData[stringValue];
|
||||
string valore = currProdData[stringKey];
|
||||
byte[] strByte = S7.Net.Types.String.ToByteArray(valore);
|
||||
int byteLen = strByte.Length <= totLen ? strByte.Length : totLen;
|
||||
int shiftStrByte = writePre ? 2 : 0;
|
||||
@@ -84,7 +88,7 @@ namespace IOB_WIN
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
lgError($"Errore in gestione scrittura {stringValue}{Environment.NewLine}{exc}");
|
||||
lgError($"Errore in gestione scrittura {stringKey}{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -348,6 +352,7 @@ namespace IOB_WIN
|
||||
public IobSiemens(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf)
|
||||
{
|
||||
memMap = new plcMemMap();
|
||||
writePre = true;
|
||||
if (IOBConf != null)
|
||||
{
|
||||
// gestione invio ritardato contapezzi
|
||||
@@ -958,6 +963,72 @@ namespace IOB_WIN
|
||||
return outVal;
|
||||
}
|
||||
/// <summary>
|
||||
/// OVerride metodo x scrittura parametri su PLC
|
||||
/// </summary>
|
||||
/// <param name="updatedPar"></param>
|
||||
protected override void plcWriteParams(List<objItem> updatedPar)
|
||||
{
|
||||
dataConf currMem = null;
|
||||
int byteSize = 0;
|
||||
byte[] MemBlock = new byte[1];
|
||||
string memAddrWrite = "";
|
||||
bool fatto = false;
|
||||
if (updatedPar != null)
|
||||
{
|
||||
// controllo i parametri... ne gestisco 4...
|
||||
foreach (var item in updatedPar)
|
||||
{
|
||||
try
|
||||
{
|
||||
memAddrWrite = "";
|
||||
// cerco in area memMapWrite...
|
||||
if (memMap.mMapWrite.ContainsKey(item.uid))
|
||||
{
|
||||
// recupero!
|
||||
currMem = memMap.mMapWrite[item.uid];
|
||||
byteSize = currMem.size;
|
||||
memAddrWrite = currMem.memAddr;
|
||||
MemBlock = new byte[byteSize];
|
||||
// faccio preliminarmente upsertKey...
|
||||
upsertKey(item.uid, currMem.value);
|
||||
switch (currMem.tipoMem)
|
||||
{
|
||||
case plcDataType.Boolean:
|
||||
break;
|
||||
case plcDataType.Int:
|
||||
saveIntOnMemBlock(ref MemBlock, item.uid, 0);
|
||||
break;
|
||||
case plcDataType.DInt:
|
||||
saveDIntOnMemBlock(ref MemBlock, item.uid, 0);
|
||||
break;
|
||||
case plcDataType.Real:
|
||||
saveRealOnMemBlock(ref MemBlock, item.uid, 0);
|
||||
break;
|
||||
case plcDataType.String:
|
||||
saveStringOnMemBlock(ref MemBlock, item.uid, 0, currMem.value.Length);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(memAddrWrite))
|
||||
{
|
||||
// scrivo su siemens
|
||||
fatto = S7WriteBB(ref MemBlock, memAddrWrite);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lgInfo($"Errore uid non trovato in area write memory: {item.uid}, ci sono {memMap.mMapWrite.Count} in area write");
|
||||
}
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
lgError($"Eccezione in fase di plcWriteParams per item {item.uid} con valore {item.value}{Environment.NewLine}{exc}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Metodo dispose x il currPLC contenuto
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace IOB_WIN
|
||||
MemBlock = new byte[byteSize];
|
||||
if (currMem.tipoMem == plcDataType.String)
|
||||
{
|
||||
saveStringOnMemBlock(ref MemBlock, item.Key, 0, byteSize, true);
|
||||
saveStringOnMemBlock(ref MemBlock, item.Key, 0, byteSize);
|
||||
}
|
||||
else if (currMem.tipoMem == plcDataType.DInt)
|
||||
{
|
||||
@@ -138,14 +138,35 @@ namespace IOB_WIN
|
||||
MemBlock[0] = (byte)0;
|
||||
memAddrWrite = "DB150.DBB4";
|
||||
break;
|
||||
case taskType.setParameter:
|
||||
// richiedo da URL i parametri WRITE da popolare
|
||||
taskVal = processMemWriteRequests();
|
||||
// se restituiscce "" faccio altra prova...
|
||||
if (string.IsNullOrEmpty(taskVal))
|
||||
{
|
||||
// i parametri me li aspetto come stringa composta paramName|paramvalue
|
||||
if (item.Value.Contains("|"))
|
||||
{
|
||||
string[] paramsJob = item.Value.Split('|');
|
||||
taskVal = $"REQUEST SET PARAMETERS: {paramsJob[0]} --> {paramsJob[1]}";
|
||||
}
|
||||
else
|
||||
{
|
||||
taskVal = $"WRONG REQUEST FOR SET PARAMETERS: {item.Value} doesnt contain pipe for splitting key/value";
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
taskVal = "SKIPPED | NO EXEC";
|
||||
break;
|
||||
}
|
||||
// aggiungo task!
|
||||
taskDone.Add(item.Key, taskVal);
|
||||
// scrivo comunque!
|
||||
taskOk = S7WriteBB(ref MemBlock, memAddrWrite);
|
||||
if (string.IsNullOrEmpty(memAddrWrite))
|
||||
{
|
||||
// scrivo comunque!
|
||||
taskOk = S7WriteBB(ref MemBlock, memAddrWrite);
|
||||
}
|
||||
if (!taskOk)
|
||||
{
|
||||
lgError($"Errore in S7WriteBB durante executeTasks: {item.Key} | {item.Value}");
|
||||
|
||||
@@ -192,7 +192,7 @@ namespace IOB_WIN
|
||||
MemBlock = new byte[byteSize];
|
||||
if (currMem.tipoMem == plcDataType.String)
|
||||
{
|
||||
saveStringOnMemBlock(ref MemBlock, item.Key, 0, byteSize, true);
|
||||
saveStringOnMemBlock(ref MemBlock, item.Key, 0, byteSize);
|
||||
}
|
||||
else if (currMem.tipoMem == plcDataType.DInt)
|
||||
{
|
||||
@@ -283,9 +283,9 @@ namespace IOB_WIN
|
||||
taskDone.Add(item.Key, taskVal);
|
||||
}
|
||||
// controllo SE HO da scrivere articolo/commessa/programma
|
||||
saveStringOnMemBlock(ref MemBlock, "setArt", 2, 22, true);
|
||||
saveStringOnMemBlock(ref MemBlock, "setComm", 24, 22, true);
|
||||
saveStringOnMemBlock(ref MemBlock, "setProg", 46, 22, true);
|
||||
saveStringOnMemBlock(ref MemBlock, "setArt", 2, 22);
|
||||
saveStringOnMemBlock(ref MemBlock, "setComm", 24, 22);
|
||||
saveStringOnMemBlock(ref MemBlock, "setProg", 46, 22);
|
||||
|
||||
// scrivo comunque!
|
||||
taskOk = S7WriteBB(ref MemBlock);
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace IOB_WIN
|
||||
MemBlock = new byte[byteSize];
|
||||
if (currMem.tipoMem == plcDataType.String)
|
||||
{
|
||||
saveStringOnMemBlock(ref MemBlock, item.Key, 0, byteSize, true);
|
||||
saveStringOnMemBlock(ref MemBlock, item.Key, 0, byteSize);
|
||||
}
|
||||
else if (currMem.tipoMem == plcDataType.DInt)
|
||||
{
|
||||
|
||||
@@ -143,14 +143,14 @@ namespace IOB_WIN
|
||||
case taskType.setArt:
|
||||
saveProdData(item);
|
||||
MemBlock = new byte[34];
|
||||
saveStringOnMemBlock(ref MemBlock, "setArt", 0, 32, true);
|
||||
saveStringOnMemBlock(ref MemBlock, "setArt", 0, 32);
|
||||
memAddrWrite = "DB1275.DBB96";
|
||||
taskVal = item.Value;
|
||||
break;
|
||||
case taskType.setComm:
|
||||
saveProdData(item);
|
||||
MemBlock = new byte[14];
|
||||
saveStringOnMemBlock(ref MemBlock, "setComm", 0, 12, true);
|
||||
saveStringOnMemBlock(ref MemBlock, "setComm", 0, 12);
|
||||
memAddrWrite = "DB1275.DBB130";
|
||||
taskVal = item.Value;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user