240 lines
7.9 KiB
C#
240 lines
7.9 KiB
C#
using CMS_CORE;
|
|
using CMS_CORE.Demo;
|
|
using CMS_CORE.Exceptions;
|
|
using CMS_CORE.Fanuc;
|
|
using CMS_CORE.Osai;
|
|
using CMS_CORE.Siemens;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Diagnostics;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.ServiceModel;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using static CMS_CORE.Nc;
|
|
|
|
namespace CMS_CORE_Application
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
static Nc N;
|
|
static String NCType;
|
|
static String NCIp;
|
|
static ushort NCPort;
|
|
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(test));
|
|
|
|
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 test()
|
|
{
|
|
Nc.PROC_Mode mode = Nc.PROC_Mode.AUTO;
|
|
Nc.PROC_Status status = Nc.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>();
|
|
Stopwatch sw = new Stopwatch();
|
|
List<String> Alm = new List<string>();
|
|
List<String> Msg = new List<string>();
|
|
List<String> Alm2 = new List<string>();
|
|
List<String> Lines = new List<string>();
|
|
|
|
try
|
|
{
|
|
if (NCType == "Siemens")
|
|
N = new Nc_Siemens(500);
|
|
if (NCType == "Demo")
|
|
N = new Nc_Demo(NCIp, NCPort);
|
|
if (NCType == "Osai")
|
|
N = new Nc_Osai(NCIp, NCPort,500);
|
|
if (NCType == "Fanuc")
|
|
N = new Nc_Fanuc(NCIp, NCPort, 500);
|
|
|
|
CmsError cmsError = N.NC_Connect();
|
|
cmsError = N.NC_RModelName(ref ModelName);
|
|
N.NC_RProcessesNum(ref procnum);
|
|
N.NC_RMachineNumber(ref MachNumber);
|
|
|
|
while (true)
|
|
{
|
|
sw.Restart();
|
|
N.PROC_RMode(1,ref mode);
|
|
N.PROC_RStatus(1, ref status);
|
|
N.PROC_RActiveAlarms(1,ref Alm);
|
|
N.NC_RActiveAlarms(ref Alm2);
|
|
N.PLC_RActiveMessages(ref Msg);
|
|
N.NC_RSoftwareVersion(ref SFTVersion);
|
|
N.PROC_RPPLines(1,ref Lines);
|
|
N.PROC_RPPName(1, ref PPName);
|
|
N.NC_RDateTime(ref NcTime);
|
|
|
|
|
|
|
|
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, Alm);
|
|
TXTAlmNc.Text = String.Join(Environment.NewLine, Alm2);
|
|
TXTMsg.Text = String.Join(Environment.NewLine, Msg);
|
|
TXTPPName.Text = PPName;
|
|
TXTNow.Text = NcTime.ToString();
|
|
|
|
TXTPPLines.Text = String.Join(Environment.NewLine, Lines);
|
|
Connect.Enabled = false;
|
|
Disconnect.Enabled = true;
|
|
});
|
|
|
|
}
|
|
|
|
//sw.Stop();
|
|
if ((200 - (int)sw.ElapsedMilliseconds) < 0)
|
|
Debug.WriteLine("Ritardo");
|
|
|
|
Thread.Sleep(200);
|
|
}
|
|
}
|
|
catch (Nc_Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
|
|
if (!this.IsDisposed && this.InvokeRequired)
|
|
{
|
|
this.Invoke((ThreadStart)delegate ()
|
|
{
|
|
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 = "";
|
|
|
|
TXTPPLines.Text = String.Join(Environment.NewLine, Lines);
|
|
Connect.Enabled = true;
|
|
Disconnect.Enabled = false;
|
|
});
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
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 = "10.69.36.33";
|
|
TXTport.Text = "8193";
|
|
|
|
}
|
|
else if (NcCombo.SelectedItem.ToString().Equals("Osai"))
|
|
{
|
|
TXTip.Enabled = true;
|
|
TXTport.Enabled = true;
|
|
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";
|
|
|
|
}
|
|
}
|
|
|
|
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
if(t != null)
|
|
t.Abort();
|
|
}
|
|
|
|
private void panel1_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void Disconnect_Click(object sender, EventArgs e)
|
|
{
|
|
if (t != null)
|
|
t.Abort();
|
|
|
|
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;
|
|
}
|
|
}
|
|
} |