123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
-
- using Sunny.UI;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Net.NetworkInformation;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace HRT_Measure
- {
- public partial class UCAxis : UserControl
- {
- public UCAxis()
- {
- InitializeComponent();
- }
- ClsAxis clsAxis = null;
- public Thread thMonitor = null;
- public UCAxis(string plc,string axisName, string strInfo, Dictionary<string, ClsAxis> dictAxis)
- {
- InitializeComponent();
-
- strPLCName = plc;
- AxisName = axisName;
- clsAxis = dictAxis[AxisName];
- string[] str = strInfo.Split(',');
- 当前位置 = str[0];
- 异常代码 = str[1];
- 点动速度 = str[2];
- 寸动负 = str[3];
- 寸动正 = str[4];
- 轴使能 = str[5];
- 回原点 = str[6];
- 使能完成 = str[7];
- 运行允许 = str[8];
- 异常 = str[9];
- 正极限 = str[10];
- 原点 = str[11];
- 负极限 = str[12];
- 定位 = str[13];
- commPLC = GetPLC();
- thMonitor = new Thread(new ThreadStart(ThMonitor));
- thMonitor.IsBackground = true;
- }
- private string strPLCName = "";
- CommPLC commPLC;
- public string 当前位置 = "";
- public string 异常代码 = "";
- public string 点动速度 = "";
- public string 寸动负 = "";
- public string 寸动正 = "";
- public string 轴使能 = "";
- public string 回原点 = "";
- public string 使能完成 = "";
- public string 运行允许 = "";
- public string 异常 = "";
- public string 正极限 = "";
- public string 原点 = "";
- public string 负极限 = "";
- public string 定位 = "";
- public string AxisName
- {
- set { titleName.Text = value; }
- get { return titleName.Text; }
- }
- public string PLCName
- {
- get { return strPLCName; }
- set { strPLCName = value; }
- }
- private CommPLC GetPLC()
- {
- if (PLCName == "M01M02") return ProgramHelp.Instance.commPLC_M01M02;
- if (PLCName == "M03") return ProgramHelp.Instance.commPLC_M03;
- if (PLCName == "M04M05") return ProgramHelp.Instance.commPLC_M04M05;
- return null;
- }
- private void UCAxis_Load(object sender, EventArgs e)
- {
- this.Dock = DockStyle.Fill;
- }
- private void ThMonitor()
- {
- while (true)
- {
- try
- {
- if ((PLCName == "M01M02" && ReadPLCHelp.EnumWindowDisplay != WindowDisplay.上料称重房) || (PLCName == "M03" && ReadPLCHelp.EnumWindowDisplay != WindowDisplay.压机房)
- || (PLCName == "M04M05" && ReadPLCHelp.EnumWindowDisplay != WindowDisplay.检测装箱房))
- {
- Thread.Sleep(10);
- continue;
- }
- if (clsAxis.使能完成 != "") uiLightAxisEnableDone.BeginInvoke(new Action(() => { uiLightAxisEnableDone.State = clsAxis.is使能完成 ? Sunny.UI.UILightState.On : Sunny.UI.UILightState.Off; }));
- if (clsAxis.运行允许 != "") uiLightRunAllow.BeginInvoke(new Action(() => { uiLightRunAllow.State = clsAxis.is运行允许 ? Sunny.UI.UILightState.On : Sunny.UI.UILightState.Off; }));
- if (clsAxis.异常 != "") uiLightException.BeginInvoke(new Action(() => { uiLightException.State = clsAxis.is异常 ? Sunny.UI.UILightState.On : Sunny.UI.UILightState.Off; }));
- if (clsAxis.正极限 != "") uiLightPostive.BeginInvoke(new Action(() => { uiLightPostive.State = clsAxis.isPositiveLimitOn ? Sunny.UI.UILightState.On : Sunny.UI.UILightState.Off; }));
- if (clsAxis.原点 != "") uiLightOriginal.BeginInvoke(new Action(() => { uiLightOriginal.State = clsAxis.isOriginalLimitOn ? Sunny.UI.UILightState.On : Sunny.UI.UILightState.Off; }));
- if (clsAxis.负极限 != "") uiLightNegative.BeginInvoke(new Action(() => { uiLightNegative.State = clsAxis.isNegativeLimitOn ? Sunny.UI.UILightState.On : Sunny.UI.UILightState.Off; }));
- if (clsAxis.当前位置 != "") lblCurrentPos.BeginInvoke(new Action(() => { lblCurrentPos.Text = (clsAxis.i当前位置 / 1000.0).ToString(); }));
- if (clsAxis.异常代码 != "") lblExceptionCode.BeginInvoke(new Action(() => { lblExceptionCode.Text = clsAxis.s异常代码.ToString(); }));
- if (clsAxis.轴使能 != "") btnAxisEnable.BeginInvoke(new Action(() => { btnAxisEnable.FillColor = clsAxis.is轴使能 ? Color.Red : Color.Green; }));
- }
- catch (Exception ) { }
- Thread.Sleep(10);
- }
- }
- private void btnJogNegative_MouseDown(object sender, MouseEventArgs e)
- {
- try
- {
- commPLC.WriteInt(点动速度, Convert.ToInt32(txtSpeed.Text), out string str);
- commPLC.WriteCoin(寸动负, true, out str);
- }
- catch (Exception ex) { MessageBox.Show(ex.ToString()); }
- }
- private void btnJogNegative_MouseUp(object sender, MouseEventArgs e)
- {
- try
- {
- commPLC.WriteCoin(寸动负, false, out string str);
- }
- catch (Exception ex) { MessageBox.Show(ex.ToString()); }
- }
- private void btnJogPositive_MouseDown(object sender, MouseEventArgs e)
- {
- try
- {
- commPLC.WriteInt(点动速度, Convert.ToInt32(txtSpeed.Text), out string str);
- commPLC.WriteCoin(寸动正, true, out str);
- }
- catch (Exception ex) { MessageBox.Show(ex.ToString()); }
- }
- private void btnJogPositive_MouseUp(object sender, MouseEventArgs e)
- {
- try
- {
- commPLC.WriteCoin(寸动正, false, out string str);
- }
- catch (Exception ex) { MessageBox.Show(ex.ToString()); }
- }
-
- private void btnAxisEnable_Click(object sender, EventArgs e)
- {
- try
- {
- //commPLC.ReadCoin(轴使能, out bool result, out string str);
- commPLC.WriteCoin(轴使能, !clsAxis.is轴使能, out string str);
- }
- catch (Exception ex) { MessageBox.Show(ex.ToString()); }
- }
- private void btnAxisHome_MouseDown(object sender, MouseEventArgs e)
- {
- try
- {
- commPLC.WriteCoin(回原点, true, out string str);
- }
- catch (Exception ex) { MessageBox.Show(ex.ToString()); }
- }
- private void btnAxisHome_MouseUp(object sender, MouseEventArgs e)
- {
- try
- {
- commPLC.WriteCoin(回原点, false, out string str);
- }
- catch (Exception ex) { MessageBox.Show(ex.ToString()); }
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- try
- {
- if (clsAxis.使能完成 != "") uiLightAxisEnableDone.BeginInvoke(new Action(() => { uiLightAxisEnableDone.State = clsAxis.is使能完成 ? Sunny.UI.UILightState.On : Sunny.UI.UILightState.Off; }));
- if (clsAxis.运行允许 != "") uiLightRunAllow.BeginInvoke(new Action(() => { uiLightRunAllow.State = clsAxis.is运行允许 ? Sunny.UI.UILightState.On : Sunny.UI.UILightState.Off; }));
- if (clsAxis.异常 != "") uiLightException.BeginInvoke(new Action(() => { uiLightException.State = clsAxis.is异常 ? Sunny.UI.UILightState.On : Sunny.UI.UILightState.Off; }));
- if (clsAxis.正极限 != "") uiLightPostive.BeginInvoke(new Action(() => { uiLightPostive.State = clsAxis.isPositiveLimitOn ? Sunny.UI.UILightState.On : Sunny.UI.UILightState.Off; }));
- if (clsAxis.原点 != "") uiLightOriginal.BeginInvoke(new Action(() => { uiLightOriginal.State = clsAxis.isOriginalLimitOn ? Sunny.UI.UILightState.On : Sunny.UI.UILightState.Off; }));
- if (clsAxis.负极限 != "") uiLightNegative.BeginInvoke(new Action(() => { uiLightNegative.State = clsAxis.isNegativeLimitOn ? Sunny.UI.UILightState.On : Sunny.UI.UILightState.Off; }));
- //if (AxisName == "取料X轴")
- //{
- if (clsAxis.当前位置 != "") lblCurrentPos.BeginInvoke(new Action(() => { lblCurrentPos.Text = (clsAxis.i当前位置 / 1000.0).ToString(); }));
- //}
-
- if (clsAxis.异常代码 != "") lblExceptionCode.BeginInvoke(new Action(() => { lblExceptionCode.Text = clsAxis.s异常代码.ToString(); }));
- if (clsAxis.轴使能 != "") btnAxisEnable.BeginInvoke(new Action(() => { btnAxisEnable.FillColor = clsAxis.is轴使能 ? Color.Red : Color.Green; }));
- }
- catch (Exception ex) { MessageBox.Show(ex.ToString()); }
- }
- private void UCAxis_Leave(object sender, EventArgs e)
- {
- timer1.Enabled = false;
- }
- private void btnLocation_MouseDown(object sender, MouseEventArgs e)
- {
- try
- {
- commPLC.WriteCoin(定位, true, out string str);
- }
- catch (Exception)
- {
- }
- }
- private void btnLocation_MouseUp(object sender, MouseEventArgs e)
- {
- try
- {
- commPLC.WriteCoin(定位, false, out string str);
- }
- catch (Exception)
- {
- }
- }
- }
- }
|