160 lines
4.8 KiB
C#
160 lines
4.8 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.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;
|
|
|
|
namespace CMS_CORE_Application
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
static Nc N;
|
|
static Nc N2;
|
|
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 != "")
|
|
{
|
|
panel1.Enabled = false;
|
|
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 = "";
|
|
Dictionary<String, double> Axes = new Dictionary<String,double>();
|
|
Stopwatch sw = new Stopwatch();
|
|
List<String> Alm = new List<string>();
|
|
List<String> Msg = 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);
|
|
|
|
N.NC_Connect();
|
|
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.PLC_RActiveAlarms(ref Msg);
|
|
sw.Stop();
|
|
|
|
|
|
|
|
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;
|
|
TXTTime.Text = sw.ElapsedMilliseconds.ToString()+" mS";
|
|
TXTAlm.Text = String.Join(Environment.NewLine, Alm);
|
|
TXTMsg.Text = String.Join(Environment.NewLine, Msg);
|
|
panel1.Enabled = false;
|
|
});
|
|
|
|
}
|
|
if ((150 - (int)sw.ElapsedMilliseconds) > 0)
|
|
Thread.Sleep(150 - (int)sw.ElapsedMilliseconds);
|
|
else
|
|
Debug.WriteLine("Ritardo");
|
|
}
|
|
}
|
|
catch (Nc_Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
|
|
if (!this.IsDisposed && this.InvokeRequired)
|
|
{
|
|
this.Invoke((ThreadStart)delegate ()
|
|
{
|
|
panel1.Enabled = true;
|
|
});
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (NcCombo.SelectedItem.ToString().Equals("Siemens"))
|
|
{
|
|
TXTip.Enabled = false;
|
|
TXTport.Enabled = false;
|
|
}
|
|
else
|
|
{
|
|
TXTip.Enabled = true;
|
|
TXTport.Enabled = true;
|
|
}
|
|
}
|
|
|
|
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
if(t != null)
|
|
t.Abort();
|
|
}
|
|
}
|
|
} |