Files
cms-core-active/CMS_CORE_Application/Form1.cs
T
Nicola Carminati dc5a2e501a
2017-11-23 16:34:14 +00:00

129 lines
3.5 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 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 != "")
t.Start();
}
private void test()
{
Nc.PROC_Mode mode = Nc.PROC_Mode.AUTO;
Nc.PROC_Status status = Nc.PROC_Status.ERROR;
try
{
if (NCType == "Siemens")
N = new Nc_Siemens(300);
if (NCType == "Demo")
N = new Nc_Demo(NCIp, NCPort);
if (NCType == "Osai")
N = new Nc_Osai(NCIp, NCPort,1000);
if (NCType == "Fanuc")
N = new Nc_Fanuc(NCIp, NCPort, 1000);
N.NC_Connect();
while (true)
{
N.PROC_RMode(1,ref mode);
N.PROC_RStatus(1, ref status);
if (!this.IsDisposed && this.InvokeRequired)
{
this.Invoke((ThreadStart)delegate ()
{
TXTPath1.Text = mode.ToString();
TXTStat1.Text = status.ToString();
panel1.Enabled = false;
});
}
Thread.Sleep(200);
}
}
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();
}
}
}