Update adapter...

This commit is contained in:
Samuele Locatelli
2020-04-06 19:46:01 +02:00
parent e3039c13be
commit ea795b377a
2 changed files with 8 additions and 245 deletions
-65
View File
@@ -119,71 +119,6 @@ namespace EsaCncLib
private EsaByteMem SCMA_MMan_OVR;
private EsaByteMem SCMA_MMan_status;
// byteSize
#if fase
private UInt16 IOT_ByteAreaByteSize;
private UInt16 IOT_WordAreaByteSize;
private UInt16 IOT_DWordAreaByteSize;
private UInt16 IOT_String_AreaByteSize;
#endif
// registri e nome aree
#if false
private string IOT_ByteAreaAddressName;
private TS_REG IOT_ByteAreaAddress;
private string IOT_WordAreaAddressName;
private TS_REG IOT_WordAreaAddress;
private string IOT_DWordAreaAddressName;
private TS_REG IOT_DWordAreaAddress;
private string IOT_StringA_AreaAddressName;
private TS_REG IOT_StringA_AreaAddress;
private string IOT_StringB_AreaAddressName;
private TS_REG IOT_StringB_AreaAddress;
private string IOT_StringC_AreaAddressName;
private TS_REG IOT_StringC_AreaAddress;
private string IOT_StringD_AreaAddressName;
private TS_REG IOT_StringD_AreaAddress;
#endif
// memorie temp e reali
#if false
/// <summary>
/// Area IOT_Byte: memoria temp di UINT di 4 byte (32 bit)
/// </summary>
public UInt32[] PLC_MemoryAreaIOT_Byte_tmp;
/// <summary>
/// Area IOT_Word: memoria temp di UINT di 4 byte (32 bit)
/// </summary>
public UInt32[] PLC_MemoryAreaIOT_Word_tmp;
/// <summary>
/// memorie a 1 byte (8 bit) x area IOT.Byte
/// </summary>
public Byte[] PLC_MemoryAreaIOT_Byte;
/// <summary>
/// memorie a 2 byte (16 bit) x area IOT.Word
/// </summary>
public UInt16[] PLC_MemoryAreaIOT_Word;
/// <summary>
/// memorie a 4 byte (32 bit) x area IOT.DWord
/// </summary>
public UInt32[] PLC_MemoryAreaIOT_DWord;
/// <summary>
/// memorie TEMP x area IOT.String
/// </summary>
public UInt32[] PLC_MemoryAreaIOT_String_tmp;
/// <summary>
/// memorie a 1 byte (8 bit) x area IOT.String (singoli caratteri...)
/// </summary>
public Byte[] PLC_MemoryAreaIOT_String_row;
/// <summary>
/// memorie a 1 byte (8 bit) x area IOT.String (singoli caratteri...)
/// </summary>
public Byte[,] PLC_MemoryAreaIOT_String;
#endif
#endregion
+8 -180
View File
@@ -33,22 +33,6 @@ namespace SCMA.AdapterPLC.CMS
/// </summary>
public allarme[] elencoAllarmiCNC;
/// <summary>
/// dimensione buffer BYTE (da file map)
/// </summary>
public int numByte = 0;
/// <summary>
/// dimensione buffer WORD (da file map)
/// </summary>
public int numWord = 0;
/// <summary>
/// dimensione buffer DWORD (da file map)
/// </summary>
public int numDWord = 0;
/// <summary>
/// Dimensione buffer string (FISSO!!!)
/// </summary>
public int numString = 255;
/// <summary>
/// Carico file conf dati IOT
@@ -56,42 +40,15 @@ namespace SCMA.AdapterPLC.CMS
protected override void loadOtherFile()
{
base.loadOtherFile();
#if false
loadByteListMap();
loadWordListMap();
loadDWordListMap();
loadStringListMap();
loadStringListMap();
#endif
loadAllarmiCNC();
}
/// <summary>
/// Carico conf vettore dati STRING
/// </summary>
private void loadStringListMap()
{
loadConfFile(ref mapIOT_String, filePath("IOTStringFilePath"), 1, ref numString);
// riporto numString a 255!
numString = 255;
}
/// <summary>
/// Carico conf vettore dati DWORD
/// </summary>
private void loadDWordListMap()
{
loadConfFile(ref mapIOT_DWord, filePath("IOTDWordFilePath"), 1, ref numDWord);
}
/// <summary>
/// Carico conf vettore dati WORD
/// </summary>
private void loadWordListMap()
{
loadConfFile(ref mapIOT_Word, filePath("IOTWordFilePath"), 1, ref numWord);
}
/// <summary>
/// Carico conf vettore dati BYTE
/// </summary>
private void loadByteListMap()
{
loadConfFile(ref mapIOT_Byte, filePath("IOTByteFilePath"), 1, ref numByte);
}
/// <summary>
/// caricamento allarmi da file (CON RIEMPIMENTO MANCANTI!!!!)
/// </summary>
@@ -151,84 +108,6 @@ namespace SCMA.AdapterPLC.CMS
{
return string.Format(@"{0}\{1}", utils.confDir, utils.CRS(keyFile));
}
/// <summary>
/// Legge il file di conf di una MAP di informazioni da gestire con lettura set memoria
/// </summary>
/// <param name="vettoreConf">nome vettore memoria</param>
/// <param name="nomeFile">file origine</param>
/// <param name="memSize">dimensione (in byte) della memoria</param>
/// <param name="numVett">dimensione (in byte) della memoria</param>
protected void loadConfFile(ref otherData[] vettoreConf, string nomeFile, int memSize, ref int numVett)
{
otherData lastData = new otherData();
int totRighe = 0;
string linea;
totRighe = File.ReadLines(nomeFile).Count();
// creo un vettore della dimensione corretta... conta anche commenti tanto poi riduco...
vettoreConf = new otherData[File.ReadLines(nomeFile).Count()];
// carica da file...
StreamReader file = new StreamReader(nomeFile);
// leggo 1 linea alla volta...
int numRiga = 0;
int bitNum = 0;
int byteNum = 0;
while ((linea = file.ReadLine()) != null)
{
// SE non è un commento...
if (linea.Substring(0, 1) != "#")
{
// se finisce per BIT allora processo bit-a-bit...
if (linea.EndsWith("BOOL"))
{
try
{
string[] memIdx = linea.Split(utils.CRC("testCharSep"))[0].Split('.');
// calcolo bit e byte number...
int.TryParse(memIdx[0], out byteNum);
if (memIdx.Length > 1)
{
int.TryParse(memIdx[1], out bitNum);
}
else
{
bitNum = 0;
}
}
catch
{
byteNum = 0;
bitNum = 0;
}
lastData = decodeBitData(linea, utils.CRC("testCharSep"), byteNum, 1, bitNum);
vettoreConf[numRiga] = lastData;
}
else
{
lastData = decodeOtherData(linea, utils.CRC("testCharSep"), "", 1, memSize);
vettoreConf[numRiga] = lastData;
}
numRiga++;
}
}
// salvo lunghezza file...
try
{
numVett = Convert.ToInt32(lastData.memAddr) + 1;
}
catch
{
numVett = numRiga + 1;
}
// chiudo file
file.Close();
// ora trimmo vettore al solo numero VERO dei valori caricati...
Array.Resize<otherData>(ref vettoreConf, numRiga);
if (utils.CRB("verbose"))
{
lg.Info(string.Format("Fine caricamento vettore di {0} variabili per file {1}", numRiga, nomeFile));
}
}
/// <summary>
/// oggetto onnessione ESA
@@ -261,8 +140,8 @@ namespace SCMA.AdapterPLC.CMS
loadOtherFile();
parentForm.commPlcActive = true;
//ncDevice = new thdNcEsaGvKvara(EsaIni, mapIOT_Byte.Length, mapIOT_Word.Length, mapIOT_DWord.Length, 255); // impostato a 255 byte (char) FISSO x la parte stringa... mapIOT_String.Length);
ncDevice = new thdNcEsaKvara(EsaIni, numByte, numWord, numDWord, numString); // impostato a 255 byte (char) FISSO x la parte stringa... mapIOT_String.Length);
// init classe comunicazione NC
ncDevice = new thdNcEsaKvara(EsaIni);
parentForm.commPlcActive = false;
if (utils.CRB("verbose"))
@@ -339,15 +218,15 @@ namespace SCMA.AdapterPLC.CMS
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);
TimingData.addResult("R-PLC_SCMA-Byte", DateTime.Now.Subtract(inizio).Ticks);
}
parentForm.commPlcActive = false;
}
else
{
lg.Error("Errore connessione mancante in getIotMem_Byte");
}
// Processing area BYTE
int numero = 0;
string status = "";
@@ -973,57 +852,7 @@ namespace SCMA.AdapterPLC.CMS
// update form!
parentForm.dataMonitor_1 += sb.ToString();
}
/// <summary>
/// Carica ed acquisisce dati del buffer STRING di memoria
/// </summary>
protected void getIotMem_String()
{
// accodo dati path in DataMonitor......
StringBuilder sb = new StringBuilder();
if (connectionOk)
{
// leggo TUTTO il blocco di memoria
parentForm.commPlcActive = true;
inizio = DateTime.Now;
ncDevice.ReadBufferString();
if (utils.CRB("recTime"))
{
TimingData.addResult(string.Format("R{0}-PLC_IOT-DWord", ncDevice.PLC_MemoryAreaIOT_DWord.Length), DateTime.Now.Subtract(inizio).Ticks);
}
parentForm.commPlcActive = false;
}
else
{
lg.Error("Errore connessione mancante in getIotMem_DWord");
}
// Processing area STRING: OGNI area di memoria...
for (int j = 0; j < mapIOT_String.Length; j++)
{
string valString = "";
for (int i = 0; i < numString; i++)
{
try
{
valString += Convert.ToChar(ncDevice.PLC_MemoryAreaIOT_String[j, i]).ToString().Replace("\0", " ");
}
catch (Exception exc)
{
lg.Error(exc, "Errore in decodifica " + mapIOT_String[i].varName);
}
}
// trimmo!
valString = valString.Trim();
// salvo
currGateway.updateItemNodeCodeValue(vettMemArea[j].prgNameKey, j.ToString(), valString);
// aggiungo nomi programmi...
sb.AppendLine(string.Format("{0}: {1}", mapIOT_String[j].varName, valString));
}
// update form!
parentForm.dataMonitor_2 += sb.ToString();
}
public override void getGlobalData()
{
base.getGlobalData();
@@ -1040,7 +869,6 @@ namespace SCMA.AdapterPLC.CMS
parentForm.dataMonitor_3 = "";
// recupero le varie memorie (prima string che mi serve x area selezionata --> programma selezionato)
getIotMem_String();
getIotMem_Byte();
getIotMem_Word();
getIotMem_DWord();