322 lines
12 KiB
C#
322 lines
12 KiB
C#
using CMS_CORE_Library;
|
|
using CMS_CORE_Library.Demo;
|
|
using CMS_CORE_Library.Fanuc;
|
|
using CMS_CORE_Library.Models;
|
|
using CMS_CORE_Library.Osai;
|
|
using CMS_CORE_Library.S7Net;
|
|
using CMS_CORE_Library.Siemens;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
using static CMS_CORE_Library.Models.DataStructures;
|
|
|
|
namespace CMS_CORE_Application
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
private static Nc N;
|
|
private static string NCType;
|
|
private static string NCIp;
|
|
private static ushort NCPort;
|
|
private Thread t;
|
|
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
}
|
|
|
|
private void connectDemo_Click(object sender, EventArgs e)
|
|
{
|
|
t = new Thread(new ThreadStart(ReadBasicData));
|
|
|
|
if (NcCombo.SelectedItem == null)
|
|
return;
|
|
|
|
NCType = NcCombo.SelectedItem.ToString().Trim();
|
|
NCIp = TXTip.Text.Trim();
|
|
NCPort = ushort.Parse(TXTport.Text.Trim());
|
|
|
|
if (NCType != "")
|
|
{
|
|
Connect.Enabled = false;
|
|
Disconnect.Enabled = true;
|
|
t.Start();
|
|
}
|
|
}
|
|
|
|
private void ReadBasicData()
|
|
{
|
|
try
|
|
{
|
|
PROC_MODE mode = PROC_MODE.AUTO;
|
|
PROC_STATUS status = PROC_STATUS.ERROR;
|
|
ushort procnum = 0;
|
|
string MachNumber = "";
|
|
string ModelName = "";
|
|
string SFTVersion = "";
|
|
string PPName = "";
|
|
DateTime NcTime = new DateTime();
|
|
Dictionary<string, double> Axes = new Dictionary<string, double>();
|
|
Dictionary<int, string> messages = new Dictionary<int, string>();
|
|
Stopwatch sw = new Stopwatch();
|
|
List<AlarmModel> procAlarms = new List<AlarmModel>();
|
|
List<PlcAlarmModel> plcMsg = new List<PlcAlarmModel>();
|
|
PreAndPostPowerOnModel powerOn = new PreAndPostPowerOnModel();
|
|
List<AlarmModel> ncAlarms = new List<AlarmModel>();
|
|
List<string> Lines = new List<string>();
|
|
List<HeadDataModel> Heads = new List<HeadDataModel>();
|
|
|
|
N = SetNcByType();
|
|
|
|
CmsError cmsError = N.NC_Connect();
|
|
cmsError = N.NC_RModelName(ref ModelName);
|
|
cmsError = N.NC_RSoftwareVersion(ref SFTVersion);
|
|
cmsError = N.NC_RSerialNumber(ref MachNumber);
|
|
|
|
List<uint> val = new List<uint>();
|
|
|
|
|
|
bool error = false;
|
|
string serial = "";
|
|
|
|
while (true)
|
|
{
|
|
/////////////////////////////////// Load basic data
|
|
//cmsError = N.PROC_RMode(1, ref mode);
|
|
//if (cmsError.IsError()) { error = true; SetError(Lines, cmsError); }
|
|
|
|
//cmsError = N.PROC_RStatus(1, ref status);
|
|
//if (cmsError.IsError()) { error = true; SetError(Lines, cmsError); }
|
|
|
|
//cmsError = N.PROC_RActiveAlarms(1, ref procAlarms);
|
|
//if (cmsError.IsError()) { error = true; SetError(Lines, cmsError); }
|
|
|
|
//cmsError = N.NC_RActiveAlarms(ref ncAlarms);
|
|
//if (cmsError.IsError()) { error = true; SetError(Lines, cmsError); }
|
|
|
|
//cmsError = N.PLC_RActiveMessages(ref plcMsg);
|
|
//if (cmsError.IsError()) { error = true; SetError(Lines, cmsError); }
|
|
|
|
//cmsError = N.NC_RDateTime(ref NcTime);
|
|
//if (cmsError.IsError()) { error = true; SetError(Lines, cmsError); }
|
|
|
|
//cmsError = N.PLC_RHeadsData(Heads, 1);
|
|
//if (cmsError.IsError()) { error = true; SetError(Lines, cmsError); }
|
|
|
|
//cmsError = N.NC_RSerialNumber(ref serial);
|
|
//if (cmsError.IsError()) { error = true; SetError(Lines, cmsError); }
|
|
|
|
////////////////////////////////////////////////////////////// TEST
|
|
|
|
Stopwatch st = new Stopwatch();
|
|
sw.Restart();
|
|
|
|
OffsetModel off = new OffsetModel();
|
|
cmsError = N.TOOLS_ROffset(1, ref off);
|
|
// in caso di errore (es S7Net) escludo
|
|
if (cmsError.IsError())
|
|
{
|
|
error = true; SetError(Lines, cmsError);
|
|
}
|
|
else
|
|
{
|
|
try
|
|
{
|
|
off.CustomDouble[3] = 88.22;
|
|
|
|
off.CustomInt[1] = 15;
|
|
cmsError = N.TOOLS_WOffset(1, ref off);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
labelTest1TXT.Text = ex.Message;
|
|
}
|
|
}
|
|
|
|
MovementBetweenMagazinesModel mov = new MovementBetweenMagazinesModel();
|
|
cmsError = N.PLC_RToolMovement(ref mov);
|
|
if (cmsError.IsError()) { error = true; SetError(Lines, cmsError); }
|
|
|
|
N.NC_Connect();
|
|
SelectedProcessData a = new SelectedProcessData();
|
|
N.PROC_RSelectedProcessData(1, ref a);
|
|
|
|
sw.Stop();
|
|
Console.WriteLine("TEMPO PER FUNZIONE " + sw.ElapsedMilliseconds);
|
|
|
|
////////////////////////////////////////////////////////////// END TEST
|
|
if (!this.IsDisposed && this.InvokeRequired)
|
|
{
|
|
this.Invoke((ThreadStart)delegate ()
|
|
{
|
|
TXTPath1.Text = mode.ToString();
|
|
TXTStat1.Text = status.ToString();
|
|
TXTNProcess.Text = procnum.ToString();
|
|
TXTName.Text = ModelName;
|
|
TXTMachNum.Text = MachNumber;
|
|
TXTSft.Text = SFTVersion;
|
|
TXTTime.Text = sw.ElapsedMilliseconds.ToString() + " mS";
|
|
TXTAlm.Text = string.Join(Environment.NewLine, procAlarms.Select(x => x.Message));
|
|
TXTAlmNc.Text = string.Join(Environment.NewLine, ncAlarms.Select(x => x.Message));
|
|
TXTMsg.Text = string.Join(Environment.NewLine, plcMsg.Select(x => x.Id));
|
|
TXTPPName.Text = PPName;
|
|
TXTNow.Text = NcTime.ToString();
|
|
|
|
if (error == false)
|
|
Error.Text = "";
|
|
|
|
TXTPPLines.Text = string.Join(Environment.NewLine, Lines);
|
|
Connect.Enabled = false;
|
|
Disconnect.Enabled = true;
|
|
});
|
|
}
|
|
error = false;
|
|
|
|
if ((200 - (int)sw.ElapsedMilliseconds) < 0)
|
|
Debug.WriteLine("Ritardo " + sw.ElapsedMilliseconds);
|
|
|
|
Thread.Sleep(200);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void SetError(List<string> Lines, CmsError cmsError)
|
|
{
|
|
if (!this.IsDisposed && this.InvokeRequired)
|
|
{
|
|
this.Invoke((ThreadStart)delegate ()
|
|
{
|
|
Error.Text = cmsError.localizationKey;
|
|
|
|
TXTPPLines.Text = string.Join(Environment.NewLine, Lines);
|
|
Connect.Enabled = true;
|
|
// Disconnect.Enabled = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
private Nc SetNcByType()
|
|
{
|
|
if (NCType == "Siemens")
|
|
return new Nc_Siemens(500);
|
|
if (NCType == "Demo")
|
|
return new Nc_Demo(NCIp, NCPort);
|
|
if (NCType == "Osai")
|
|
return new Nc_Osai(NCIp, NCPort, 50000);
|
|
if (NCType == "Fanuc")
|
|
return new Nc_Fanuc(NCIp, NCPort, 2000);
|
|
|
|
return null;
|
|
}
|
|
private NcThermo SetNcThermoByType()
|
|
{
|
|
if (NCType == "S7Net")
|
|
return new Nc_S7Net(NCIp, NCPort, 500);
|
|
|
|
return null;
|
|
}
|
|
|
|
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (NcCombo.SelectedItem.ToString().Equals("Siemens"))
|
|
{
|
|
TXTip.Enabled = false;
|
|
TXTport.Enabled = false;
|
|
}
|
|
else if (NcCombo.SelectedItem.ToString().Equals("Fanuc"))
|
|
{
|
|
TXTip.Enabled = true;
|
|
TXTport.Enabled = true;
|
|
//TXTip.Text = "192.168.139.1";
|
|
TXTip.Text = "10.69.48.24";
|
|
//TXTip.Text = "10.69.36.33";
|
|
TXTport.Text = "8193";
|
|
}
|
|
else if (NcCombo.SelectedItem.ToString().Equals("Osai"))
|
|
{
|
|
TXTip.Enabled = true;
|
|
TXTport.Enabled = true;
|
|
// TXTip.Text = "192.168.139.1";
|
|
TXTip.Text = "192.168.157.2";
|
|
TXTport.Text = "8080";
|
|
}
|
|
else if (NcCombo.SelectedItem.ToString().Equals("Demo"))
|
|
{
|
|
TXTip.Enabled = true;
|
|
TXTport.Enabled = true;
|
|
TXTip.Text = "localhost";
|
|
TXTport.Text = "8080";
|
|
}
|
|
else if (NcCombo.SelectedItem.ToString().Equals("S7Net"))
|
|
{
|
|
TXTip.Enabled = true;
|
|
TXTport.Enabled = false;
|
|
TXTip.Text = "192.168.0.102";
|
|
TXTport.Text = "102";
|
|
}
|
|
}
|
|
|
|
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
if (t != null)
|
|
t.Abort();
|
|
|
|
if (N != null)
|
|
N.NC_Disconnect();
|
|
}
|
|
|
|
private void Disconnect_Click(object sender, EventArgs e)
|
|
{
|
|
N.NC_Disconnect();
|
|
if (t != null)
|
|
t.Abort();
|
|
|
|
|
|
t = new Thread(new ThreadStart(ReadBasicData));
|
|
t.Start();
|
|
|
|
TXTPath1.Text = "";
|
|
TXTStat1.Text = "";
|
|
TXTNProcess.Text = "";
|
|
TXTName.Text = "";
|
|
TXTMachNum.Text = "";
|
|
TXTSft.Text = "";
|
|
TXTTime.Text = "";
|
|
TXTAlm.Text = "";
|
|
TXTAlmNc.Text = "";
|
|
TXTMsg.Text = "";
|
|
TXTPPName.Text = "";
|
|
TXTNow.Text = "";
|
|
TXTPPLines.Text = "";
|
|
Connect.Enabled = true;
|
|
Disconnect.Enabled = false;
|
|
}
|
|
|
|
private void NetworkReadButton_Click(object sender, EventArgs e)
|
|
{
|
|
List<NcToolModel> obj = new List<NcToolModel>()
|
|
{
|
|
new NcToolModel() { ToolId = 22, FamilyId = 1, OffsetId1 = 1, OffsetId2 = 2, OffsetId3 = 3, OffsetLength = 4, ResidualLife = 5, ResidualRevive = 6, ShankId = 7 },
|
|
new NcToolModel() { ToolId = 22, FamilyId = 1, OffsetId1 = 1, OffsetId2 = 2, OffsetId3 = 3, OffsetLength = 4, ResidualLife = 5, ResidualRevive = 6, ShankId = 7 }
|
|
};
|
|
N.TOOLS_WUpdateTools(obj);
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
N.NC_SetScreenVisible(Nc.SCREEN_PAGE.Siemens_Machine);
|
|
}
|
|
}
|
|
} |