551 lines
13 KiB
C#
551 lines
13 KiB
C#
using MTC;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
|
|
namespace SCMA
|
|
{
|
|
public partial class SetupAdapter : Form
|
|
{
|
|
public SetupAdapter()
|
|
{
|
|
InitializeComponent();
|
|
|
|
// fix icon!
|
|
this.Icon = Icon.ExtractAssociatedIcon(defIconFilePath);
|
|
}
|
|
protected string defIconFilePath
|
|
{
|
|
get
|
|
{
|
|
return string.Format(@"{0}\Scma.ico", utils.resxDir);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// Percorso file completo
|
|
/// </summary>
|
|
protected string filePath
|
|
{
|
|
get
|
|
{
|
|
return string.Format("{0}/{1}", utils.CRS("dataConfPath"), txtFileName.Text);
|
|
}
|
|
}
|
|
|
|
protected int numVacPump
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
try
|
|
{
|
|
answ = Convert.ToInt32(nVacPump.Text);
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
nVacPump.Text = value.ToString();
|
|
}
|
|
}
|
|
protected int numVacAct
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
try
|
|
{
|
|
answ = Convert.ToInt32(nVacAct.Text);
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
nVacAct.Text = value.ToString();
|
|
}
|
|
}
|
|
protected int numLubro
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
try
|
|
{
|
|
answ = Convert.ToInt32(nLubro.Text);
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
nLubro.Text = value.ToString();
|
|
}
|
|
}
|
|
protected int numCooler
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
try
|
|
{
|
|
answ = Convert.ToInt32(nCooler.Text);
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
nCooler.Text = value.ToString();
|
|
}
|
|
}
|
|
protected int numPress
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
try
|
|
{
|
|
answ = Convert.ToInt32(nPress.Text);
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
nPress.Text = value.ToString();
|
|
}
|
|
}
|
|
protected int numTemp
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
try
|
|
{
|
|
answ = Convert.ToInt32(nTempe.Text);
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
nTempe.Text = value.ToString();
|
|
}
|
|
}
|
|
protected int numPath
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
try
|
|
{
|
|
answ = Convert.ToInt32(nPath.Text);
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
nPath.Text = value.ToString();
|
|
}
|
|
}
|
|
protected int numUnOp
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
try
|
|
{
|
|
answ = Convert.ToInt32(nUnOp.Text);
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
nUnOp.Text = value.ToString();
|
|
}
|
|
}
|
|
protected int numAxis
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
try
|
|
{
|
|
answ = Convert.ToInt32(nAssi.Text);
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
nAssi.Text = value.ToString();
|
|
}
|
|
}
|
|
protected int numMemArea
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
try
|
|
{
|
|
answ = Convert.ToInt32(nMemArea.Text);
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
nMemArea.Text = value.ToString();
|
|
}
|
|
}
|
|
protected int numSlittaMag
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
try
|
|
{
|
|
answ = Convert.ToInt32(nSlittaMag.Text);
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
nSlittaMag.Text = value.ToString();
|
|
}
|
|
}
|
|
protected int numProtMag
|
|
{
|
|
get
|
|
{
|
|
int answ = 0;
|
|
try
|
|
{
|
|
answ = Convert.ToInt32(nProtMag.Text);
|
|
}
|
|
catch
|
|
{ }
|
|
return answ;
|
|
}
|
|
set
|
|
{
|
|
nProtMag.Text = value.ToString();
|
|
}
|
|
}
|
|
|
|
protected element[] oAxisLoad { get; set; }
|
|
|
|
private void btnCreateFile_Click(object sender, EventArgs e)
|
|
{
|
|
// creo un nuovo file adapter...
|
|
AdapterConf c = new AdapterConf
|
|
{
|
|
// nome da txtbox, vers 1
|
|
NomeAdapt = txtAdapter.Text,
|
|
Version = 1
|
|
};
|
|
// tipo da selettore
|
|
string valTipo = "";
|
|
try
|
|
{
|
|
valTipo = cbTipoAdapt.SelectedItem.ToString().ToUpper();
|
|
}
|
|
catch
|
|
{
|
|
valTipo = cbTipoAdapt.SelectedText;
|
|
}
|
|
switch (valTipo)
|
|
{
|
|
case "FANUC":
|
|
c.TipoAdapt = tipoAdapter.FANUC;
|
|
break;
|
|
case "OSAI":
|
|
c.TipoAdapt = tipoAdapter.OSAI;
|
|
break;
|
|
case "SIEMENS":
|
|
c.TipoAdapt = tipoAdapter.SIEMENS;
|
|
break;
|
|
case "HMI-ESA":
|
|
case "HMI_ESA":
|
|
case "ESAGV":
|
|
c.TipoAdapt = tipoAdapter.ESAGVSCM;
|
|
break;
|
|
case "DEMO":
|
|
default:
|
|
c.TipoAdapt = tipoAdapter.DEMO;
|
|
break;
|
|
}
|
|
|
|
// init lista parametri
|
|
List<DataRefItem<string, string>> listaDR;
|
|
|
|
// MemArea
|
|
if (numMemArea > 0)
|
|
{
|
|
// creo elementi richiesti
|
|
element[] MemArea = new element[numMemArea];
|
|
// ciclo x istanziare!
|
|
for (int i = 0; i < numMemArea; i++)
|
|
{
|
|
// inizializzo list x parametri
|
|
listaDR = new List<DataRefItem<string, string>>();
|
|
MemArea[i] = new element(string.Format("MemArea_{0:00}", i + 1), listaDR);
|
|
}
|
|
// salvo oggetto
|
|
c.MemArea = MemArea;
|
|
}
|
|
|
|
// VAC PUMP
|
|
if (numVacPump > 0)
|
|
{
|
|
// creo elementi richiesti
|
|
element[] VacuumPump = new element[numVacPump];
|
|
// ciclo x istanziare!
|
|
for (int i = 0; i < numVacPump; i++)
|
|
{
|
|
// inizializzo list x parametri
|
|
listaDR = new List<DataRefItem<string, string>>();
|
|
VacuumPump[i] = new element(string.Format("VacPump_{0:00}", i + 1), listaDR);
|
|
}
|
|
// salvo oggetto
|
|
c.VacuumPump = VacuumPump;
|
|
}
|
|
|
|
// VACUUM ACT
|
|
if (numVacAct > 0)
|
|
{
|
|
// creo elementi richiesti
|
|
element[] VacuumAct = new element[numVacAct];
|
|
// ciclo x istanziare!
|
|
for (int i = 0; i < numVacAct; i++)
|
|
{
|
|
// inizializzo list x parametri
|
|
listaDR = new List<DataRefItem<string, string>>();
|
|
VacuumAct[i] = new element(string.Format("VacAct_{0:00}", i + 1), listaDR);
|
|
}
|
|
// salvo oggetto
|
|
c.VacuumAct = VacuumAct;
|
|
}
|
|
|
|
// LUBRO
|
|
if (numLubro > 0)
|
|
{
|
|
// creo elementi richiesti
|
|
element[] Lubro = new element[numLubro];
|
|
// ciclo x istanziare!
|
|
for (int i = 0; i < numLubro; i++)
|
|
{
|
|
// inizializzo list x parametri
|
|
listaDR = new List<DataRefItem<string, string>>();
|
|
Lubro[i] = new element(string.Format("Lubro_{0:00}", i + 1), listaDR);
|
|
}
|
|
// salvo oggetto
|
|
c.Lubro = Lubro;
|
|
}
|
|
|
|
// SlittaMag
|
|
if (numSlittaMag > 0)
|
|
{
|
|
// creo elementi richiesti
|
|
element[] SlittaMag = new element[numSlittaMag];
|
|
// ciclo x istanziare!
|
|
for (int i = 0; i < numSlittaMag; i++)
|
|
{
|
|
// inizializzo list x parametri
|
|
listaDR = new List<DataRefItem<string, string>>();
|
|
SlittaMag[i] = new element(string.Format("SlittaMagazzino_{0:00}", i + 1), listaDR);
|
|
}
|
|
// salvo oggetto
|
|
c.SlittaMag = SlittaMag;
|
|
}
|
|
|
|
// ProtMag
|
|
if (numProtMag > 0)
|
|
{
|
|
// creo elementi richiesti
|
|
element[] ProtMag = new element[numProtMag];
|
|
// ciclo x istanziare!
|
|
for (int i = 0; i < numProtMag; i++)
|
|
{
|
|
// inizializzo list x parametri
|
|
listaDR = new List<DataRefItem<string, string>>();
|
|
ProtMag[i] = new element(string.Format("ProtMagazzino_{0:00}", i + 1), listaDR);
|
|
}
|
|
// salvo oggetto
|
|
c.ProtMag = ProtMag;
|
|
}
|
|
|
|
// COOLER
|
|
if (numCooler > 0)
|
|
{
|
|
// creo elementi richiesti
|
|
element[] Cooler = new element[numCooler];
|
|
// ciclo x istanziare!
|
|
for (int i = 0; i < numCooler; i++)
|
|
{
|
|
// inizializzo list x parametri
|
|
listaDR = new List<DataRefItem<string, string>>();
|
|
Cooler[i] = new element(string.Format("Cooler_{0:00}", i + 1), listaDR);
|
|
}
|
|
// salvo oggetto
|
|
c.Cooler = Cooler;
|
|
}
|
|
|
|
// PRESS
|
|
if (numPress > 0)
|
|
{
|
|
// creo elementi richiesti
|
|
element[] Press = new element[numPress];
|
|
// ciclo x istanziare!
|
|
for (int i = 0; i < numPress; i++)
|
|
{
|
|
// inizializzo list x parametri
|
|
listaDR = new List<DataRefItem<string, string>>();
|
|
Press[i] = new element(string.Format("Press_{0:00}", i + 1), listaDR);
|
|
}
|
|
// salvo oggetto
|
|
c.Press = Press;
|
|
}
|
|
|
|
// TEMPERATURE
|
|
if (numTemp > 0)
|
|
{
|
|
// creo elementi richiesti
|
|
element[] Temp = new element[numTemp];
|
|
// ciclo x istanziare!
|
|
for (int i = 0; i < numTemp; i++)
|
|
{
|
|
// inizializzo list x parametri
|
|
listaDR = new List<DataRefItem<string, string>>();
|
|
Temp[i] = new element(string.Format("Temp_{0:00}", i + 1), listaDR);
|
|
}
|
|
// salvo oggetto
|
|
c.Temp = Temp;
|
|
}
|
|
|
|
// PATH
|
|
if (numPath > 0)
|
|
{
|
|
// creo elementi richiesti
|
|
element[] Path = new element[numPath];
|
|
// ciclo x istanziare!
|
|
for (int i = 0; i < numPath; i++)
|
|
{
|
|
// inizializzo list x parametri
|
|
listaDR = new List<DataRefItem<string, string>>();
|
|
Path[i] = new element(string.Format("Path_{0:00}", i + 1), listaDR);
|
|
}
|
|
// salvo oggetto
|
|
c.Path = Path;
|
|
}
|
|
|
|
// UNITA OPERATRICI
|
|
if (numUnOp > 0)
|
|
{
|
|
// creo elementi richiesti
|
|
element[] UnOp = new element[numUnOp];
|
|
// ciclo x istanziare!
|
|
for (int i = 0; i < numUnOp; i++)
|
|
{
|
|
// inizializzo list x parametri
|
|
listaDR = new List<DataRefItem<string, string>>();
|
|
UnOp[i] = new element(string.Format("UnOp_{0:00}", i + 1), listaDR);
|
|
}
|
|
// salvo oggetto
|
|
c.UnOp = UnOp;
|
|
}
|
|
|
|
// ASSI
|
|
if (numAxis > 0)
|
|
{
|
|
// creo elementi richiesti
|
|
element[] newAxis = new element[numAxis];
|
|
// ciclo x istanziare!
|
|
for (int i = 0; i < numAxis; i++)
|
|
{
|
|
// inizializzo list x parametri
|
|
listaDR = new List<DataRefItem<string, string>>();
|
|
// se ho un vettore di assi uso i valori già letti..
|
|
if (oAxisLoad != null && oAxisLoad.Length > 0 && i < oAxisLoad.Length)
|
|
{
|
|
newAxis[i] = oAxisLoad[i];
|
|
// se non ho tutto aggiungo...
|
|
if (newAxis[i].dataRefList.Count < 2)
|
|
{
|
|
// copio lista attuale
|
|
listaDR = newAxis[i].dataRefList;
|
|
// in base a cosa manca aggiunto...
|
|
if (listaDR.Count == 0)
|
|
{
|
|
// aggiungo tutto con valori default
|
|
listaDR.Add(new DataRefItem<string, string>(string.Format("Axis_{0:00}_Type", i + 1), "LINEAR"));
|
|
listaDR.Add(new DataRefItem<string, string>(string.Format("Axis_{0:00}_Grp", i + 1), "00"));
|
|
newAxis[i] = new element(string.Format("Axis_{0:00}", i + 1), listaDR);
|
|
}
|
|
else if (listaDR.Count == 1)
|
|
{
|
|
// aggiungo solo GRP con valori default, IPOTIZZO di avere solo type...
|
|
listaDR.Add(new DataRefItem<string, string>(string.Format("Axis_{0:00}_Grp", i + 1), "00"));
|
|
newAxis[i] = new element(string.Format("Axis_{0:00}", i + 1), listaDR);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// altrimenti popolo con valori default
|
|
listaDR.Add(new DataRefItem<string, string>(string.Format("Axis_{0:00}_Type", i + 1), "LINEAR"));
|
|
listaDR.Add(new DataRefItem<string, string>(string.Format("Axis_{0:00}_Grp", i + 1), "00"));
|
|
newAxis[i] = new element(string.Format("Axis_{0:00}", i + 1), listaDR);
|
|
}
|
|
}
|
|
// salvo oggetto
|
|
c.Axis = newAxis;
|
|
}
|
|
|
|
// Serializzo oggetto conf su file
|
|
AdapterConf.Serialize(filePath, c);
|
|
}
|
|
|
|
private void btnLoad_Click(object sender, EventArgs e)
|
|
{
|
|
// Read the configuration object from a file
|
|
AdapterConf objLoad = AdapterConf.Deserialize(filePath);
|
|
|
|
txtAdapter.Text = objLoad.NomeAdapt;
|
|
cbTipoAdapt.SelectedText = objLoad.TipoAdapt.ToString();
|
|
// carico valori da file....
|
|
numVacPump = objLoad.nVacuumPump;
|
|
numVacAct = objLoad.nVacuumAct;
|
|
numLubro = objLoad.nLubro;
|
|
numCooler = objLoad.nCooler;
|
|
numPress = objLoad.nPress;
|
|
numTemp = objLoad.nTemp;
|
|
numPath = objLoad.nPath;
|
|
numUnOp = objLoad.nUnOp;
|
|
numAxis = objLoad.nAxis;
|
|
numMemArea = objLoad.nMemArea;
|
|
numSlittaMag = objLoad.nSlittaMag;
|
|
numProtMag = objLoad.nProtMag;
|
|
// salvo assi correnti...
|
|
oAxisLoad = objLoad.Axis;
|
|
}
|
|
}
|
|
}
|