pulizia codice

This commit is contained in:
Samuele E. Locatelli
2018-11-26 17:41:11 +01:00
parent 51d39e743d
commit 0515e96d43
2 changed files with 129 additions and 145 deletions
+128 -139
View File
@@ -1,4 +1,5 @@
using System;
using IOB_UT;
using System;
using System.Collections.Generic;
namespace IOB_WIN
@@ -29,6 +30,132 @@ namespace IOB_WIN
/// <param name="caller"></param>
/// <param name="adpConf"></param>
public IobKawasaki(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf)
{
// i dati RAW principali sono 6 byte...
RawInput = new byte[6];
// gestione invio ritardato contapezzi
pzCountDelay = utils.CRI("pzCountDelay");
lastPzCountSend = DateTime.Now;
lastWarnODL = DateTime.Now;
// inizializzo correttamente aree memoria secondo CONF - iniFileName
IniFile fIni = new IniFile(IOBConf.iniFileName);
// fix enable prgName
enablePrgName = fIni.ReadBoolean("CNC", "GETPRGNAME", true);
#if false
// effettuo lettura della conf sigLUT... cercando 1:1 i bit...
string currBit = "";
string memArea = "";
for (int i = 0; i < 8; i++)
{
currBit = string.Format("BIT{0}", i);
memArea = fIni.ReadString("MEMORY", currBit, "");
// se trovo un valore...
if (memArea != "")
{
signLUT.Add(currBit, memArea);
}
}
// è little endian (NON serve conversione)
hasBigEndian = false;
lgInfo("Start init Adapter OSAI, tipo all'IP/NOME {0}, variante {1} per IOB {2}", IOBConf.cncIpAddr, IOBConf.tipoIob, IOBConf.codIOB);
// Creo oggetto x gestione connessione/comunicazione NC: secondo il tipo creo CNDEX o OPEN
parentForm.commPlcActive = true;
if (IOBConf.tipoIob == tipoAdapter.OSAI_OPEN)
{
OSAI_ref = new Open_Series(IOBConf.cncIpAddr, false);
}
else if (IOBConf.tipoIob == tipoAdapter.OSAI_VB6)
{
OSAI_ref = new ComCNOSAIVB6(IOBConf.cncIpAddr, false);
}
else
{
OSAI_ref = new ComCNOsai(IOBConf.cncIpAddr, false);
}
parentForm.commPlcActive = false;
if (utils.CRB("verbose"))
{
lgInfo(string.Format("INIT OSAI_ref da CncLib come {0}", IOBConf.tipoIob));
}
// disconnetto e connetto...
if (utils.CRB("verbose"))
{
lgInfo("OSAI: tryDisconnect");
}
tryDisconnect();
lgInfo("OSAI: tryConnect");
tryConnect();
// recupero machine status e mode da cui decodificare info sul PLC...
byte machineStatus = OSAI_ref.GetMachineStatus();
byte modeSelected = OSAI_ref.GetModeSelected();
lgInfo(string.Format("Lettura preliminare: machineStatus={0} | modeSelected={1}", machineStatus, modeSelected));
// possiamo leggere tutto da qui che contiene status, mode e last_nc_error
oData = new Cndex.GETINFO1DATA();
var ncInfo = OSAI_ref.NcInfo1(ref oData);
lgInfo(string.Format("Lettura START completa NCINFO1DATA{0} lastNcError={1}{0}status={2}{0}substatus={9}{0}mode_select={3}{0}main_progr_name={4}{0}speed_ov={5}{0}progr_speed={6}{0}real_speed={7}{0}real_feed={8}{0}", Environment.NewLine, oData.last_nc_error, oData.status, oData.mode_select, oData.main_progr_name, oData.speed_ov, oData.progr_speed, oData.real_speed, oData.real_feed, oData.substatus));
// inizio il calcolo dello status semaforico
short bitStatus = 0;
if (OSAI_ref.Connected)
{
bitStatus += 1;
}
if (utils.CRB("enableContapezzi"))
{
lgInfo("OSAI: inizio gestione contapezzi");
try
{
// verifico quale modalità sia richiesta: STD (6711) oppure BIT (Custom, con indicazione area)
if (currIobConf.optPar.Count > 0 && currIobConf.optPar["PZCOUNT_MODE"] != "")
{
if (currIobConf.optPar["PZCOUNT_MODE"].StartsWith("OVAR"))
{
pzCntReload();
// refresh associazione Macchina - IOB
sendM2IOB();
// per adesso imposto lettura dal CNC == contapezzi (poi farà vera lettura...)
lastCountCNC = contapezzi;
}
else
{
contapezzi = 0;
lgInfo("Contapezzi STD disabilitato: modalità {0}", currIobConf.optPar["PZCOUNT_MODE"]);
}
}
else
{
contapezzi = 0;
lgInfo("Parametro mancante PZCOUNT_MODE");
}
}
catch (Exception exc)
{
lgError(exc, "Errore in contapezzi OSAI");
}
}
// finisco INIT ADAPTER
lgInfo("End init Adapter OSAI");
#endif
// test completo funzionalità kawasaki
kawasakiFullTest();
}
/// <summary>
/// Test completo funzioni kawasaki
/// </summary>
private void kawasakiFullTest()
{
// faccio un try-catch di test vari...
try
@@ -87,144 +214,6 @@ namespace IOB_WIN
{ // e.Message = "can't connect TCP/IP" or // "can't login"
Console.WriteLine(e.Message);
}
#if false
// i dati RAW principali sono 6 byte...
RawInput = new byte[6];
// gestione invio ritardato contapezzi
pzCountDelay = utils.CRI("pzCountDelay");
lastPzCountSend = DateTime.Now;
lastWarnODL = DateTime.Now;
// inizializzo correttamente aree memoria secondo CONF - iniFileName
IniFile fIni = new IniFile(IOBConf.iniFileName);
// inizializzo aree di memoria correnti...
MemBlockG = new byte[fIni.ReadInteger("MEMORY", "AREAG_SIZE", 8)];
MemBlockR = new byte[fIni.ReadInteger("MEMORY", "AREAR_SIZE", 8)];
MemBlockX = new byte[fIni.ReadInteger("MEMORY", "AREAX_SIZE", 8)];
MemBlockY = new byte[fIni.ReadInteger("MEMORY", "AREAY_SIZE", 8)];
// loggo aree di memoria avviate...
lgInfo(string.Format("Avviare area di memoria MemBlockG: {0} byte", MemBlockG.Length));
lgInfo(string.Format("Avviare area di memoria MemBlockR: {0} byte", MemBlockR.Length));
lgInfo(string.Format("Avviare area di memoria MemBlockX: {0} byte", MemBlockX.Length));
lgInfo(string.Format("Avviare area di memoria MemBlockY: {0} byte", MemBlockY.Length));
// fix enable prgName
enablePrgName = fIni.ReadBoolean("CNC", "GETPRGNAME", true);
// salvo le aree X-Y-D (per dump/sample/ottimizzazione lettura)
areaD = new memAreaFanuc
{
areaName = "AreaD",
startIdx = fIni.ReadInteger("MEMORY", "AREAD_START", 0),
arraySize = fIni.ReadInteger("MEMORY", "AREAD_SIZE", 0)
};
areaPAR = new memAreaFanuc
{
areaName = "AreaPARR",
startIdx = fIni.ReadInteger("MEMORY", "PAR_START", 0),
arraySize = fIni.ReadInteger("MEMORY", "PAR_SIZE", 0)
};
areaR = new memAreaFanuc
{
areaName = "AreaR",
startIdx = fIni.ReadInteger("MEMORY", "AREAR_START", 0),
arraySize = fIni.ReadInteger("MEMORY", "AREAR_SIZE", 0)
};
areaX = new memAreaFanuc
{
areaName = "AreaX",
startIdx = fIni.ReadInteger("MEMORY", "AREAX_START", 0),
arraySize = fIni.ReadInteger("MEMORY", "AREAX_SIZE", 0)
};
areaY = new memAreaFanuc
{
areaName = "AreaY",
startIdx = fIni.ReadInteger("MEMORY", "AREAY_START", 0),
arraySize = fIni.ReadInteger("MEMORY", "AREAY_SIZE", 0)
};
lgInfo(string.Format("Salvata area di memoria: {0}, da {1} per {2} byte", areaD.areaName, areaD.startIdx, areaD.arraySize));
lgInfo(string.Format("Salvata area di memoria: {0}, da {1} per {2} byte", areaR.areaName, areaR.startIdx, areaR.arraySize));
lgInfo(string.Format("Salvata area di memoria: {0}, da {1} per {2} byte", areaX.areaName, areaX.startIdx, areaX.arraySize));
lgInfo(string.Format("Salvata area di memoria: {0}, da {1} per {2} byte", areaY.areaName, areaY.startIdx, areaY.arraySize));
// effettuo lettura della conf sigLUT... cercando 1:1 i bit...
string currBit = "";
string memArea = "";
for (int i = 0; i < 8; i++)
{
currBit = string.Format("BIT{0}", i);
memArea = fIni.ReadString("MEMORY", currBit, "");
// se trovo un valore...
if (memArea != "")
{
signLUT.Add(currBit, memArea);
}
}
// è little endian (NON serve conversione)
hasBigEndian = false;
lgInfo("Start init Adapter FANUC all'IP {0}:{1} per IOB {2}", IOBConf.cncIpAddr, IOBConf.cncPort, IOBConf.codIOB);
// Creo oggetto connessione NC
parentForm.commPlcActive = true;
Runtime.CreateNC(CNC.NcType.FANUC, IOBConf.cncIpAddr, IOBConf.cncPort);
parentForm.commPlcActive = false;
// aggiungo referenza obj FANUC
FANUC_ref = (FANUC)Runtime.NC;
if (utils.CRB("verbose"))
{
lgInfo("FANUC_ref da CncLib");
}
// disconnetto e connetto...
if (utils.CRB("verbose"))
{
lgInfo("FANUC: tryDisconnect");
}
tryDisconnect();
lgInfo("FANUC: tryConnect");
tryConnect();
if (utils.CRB("enableContapezzi"))
{
lgInfo("FANUC: inizio gestione contapezzi");
try
{
// verifico quale modalità sia richiesta: STD (6711) oppure BIT (Custom, con indicazione area)
if (currIobConf.optPar.Count > 0 && currIobConf.optPar["PZCOUNT_MODE"] != "")
{
if (currIobConf.optPar["PZCOUNT_MODE"].StartsWith("STD"))
{
pzCntReload();
// refresh associazione Macchina - IOB
sendM2IOB();
// per adesso imposto lettura fanuc == contapezzi (poi farà vera lettura...)
lastCountCNC = contapezzi;
}
else
{
contapezzi = 0;
lgInfo("Contapezzi STD disabilitato: modalità {0}", currIobConf.optPar["PZCOUNT_MODE"]);
}
}
else
{
contapezzi = 0;
lgInfo("Parametro mancante PZCOUNT_MODE");
}
}
catch (Exception exc)
{
lgError(exc, "Errore in contapezzi FANUC");
}
}
// finisco INIT ADAPTER
lgInfo("End init Adapter FANUC");
#endif
}
#if false
+1 -6
View File
@@ -38,9 +38,6 @@ namespace IOB_WIN
/// <param name="adpConf"></param>
public IobOSAI(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf)
{
// i dati RAW principali sono 6 byte...
RawInput = new byte[6];
// gestione invio ritardato contapezzi
pzCountDelay = utils.CRI("pzCountDelay");
lastPzCountSend = DateTime.Now;
@@ -49,8 +46,6 @@ namespace IOB_WIN
// inizializzo correttamente aree memoria secondo CONF - iniFileName
IniFile fIni = new IniFile(IOBConf.iniFileName);
// inizializzo aree di memoria correnti...
// fix enable prgName
enablePrgName = fIni.ReadBoolean("CNC", "GETPRGNAME", true);
@@ -484,7 +479,7 @@ namespace IOB_WIN
int resVal = 0;
// lettura variabili (es contapezzi)
resVal = (int)OSAI_ref.ReadVarSN((short)cntAddr);
if (utils.CRB("recTime"))
{
TimingData.addResult(currIobConf.codIOB, string.Format("R{0}-MEM", 2), stopwatch.ElapsedTicks);