123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
-
- using Newtonsoft.Json.Linq;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Text;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace HRT_Measure
- {
- public partial class UCAxisPos : UserControl
- {
- public UCAxisPos()
- {
- InitializeComponent();
- }
- ClsAxisPos clsAxisPos = null;
- public Thread thMonitor = null;
- public UCAxisPos(string strInfo, Dictionary<string, ClsAxisPos> dictAxisPos)
- {
- InitializeComponent();
- // DictAxisPos = dictAxisPos;
- string [] str = strInfo.Split(',');
- PosName = str[0];
- clsAxisPos = dictAxisPos[PosName];
- strPLCName = clsAxisPos.PLCName;
- strAxisName = clsAxisPos.AxisName;
- strAddGo = clsAxisPos.GoAdd;
- strAddPos = clsAxisPos.PosAdd;
- strAddSpeed = clsAxisPos.SpeedAdd;
- strAddLight = clsAxisPos.LightAdd;
- commPLC = GetPLC();
- btnPosGo.Text = PosName;
- thMonitor = new Thread(new ThreadStart(ThMonitor));
- thMonitor.IsBackground = true;
- }
- private string strPLCName = "";
- private string strAxisName = "";
- CommPLC commPLC;
- private string strAddGo = "";
- private string strAddPos = "";
- private string strAddSpeed = "";
- private string strAddLight = "";
- #region MyRegion
- public string PosName = "";
- //{
- // set { titleName.Text = value; }
- // get { return titleName.Text; }
- //}
- public string PLCName
- {
- get { return strPLCName; }
- set { strPLCName = value; }
- }
- public string AxisName
- {
- get { return strAxisName; }
- set { strAxisName = value; }
- }
- public string AddGo
- {
- get { return strAddGo; }
- set { strAddGo = value; }
- }
- public string AddPos
- {
- get { return strAddPos; }
- set { strAddPos = value; }
- }
- public string AddSpeed
- {
- get { return strAddSpeed; }
- set { strAddSpeed = value; }
- }
- public string AddLight
- {
- get { return strAddLight; }
- set { strAddLight = value; }
- }
- #endregion
- private void UCM01M02取料X轴点位_Load(object sender, EventArgs e)
- {
- this.Dock = DockStyle.Fill;
- txtPos.Text = clsAxisPos.ReadPara(AxisName, $"{clsAxisPos.PosName}位置");
- txtSpeed.Text = clsAxisPos.ReadPara(AxisName, $"{clsAxisPos.PosName}速度");
-
- }
- 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 (clsAxisPos.LightAdd != "") uiLight.BeginInvoke(new Action(() => { uiLight.State = clsAxisPos.isLightOn ? Sunny.UI.UILightState.On : Sunny.UI.UILightState.Off; }));
- btnPosGo.BeginInvoke(new Action(() => { btnPosGo.FillColor = ((clsAxisPos.GoCurrValue != clsAxisPos.uGoValue) ? Color.Gray : Color.Green); }));
- }
- catch (Exception ) { }
- Thread.Sleep(10);
- }
-
- }
- 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 btnPosGo_Click(object sender, EventArgs e)
- {
- try
- {
- float value = Convert.ToSingle(txtPos.Text);
- //commPLC.WriteInt(clsAxisPos.PosAdd,Convert.ToInt32(value * 1000), out string str);
- //commPLC.WriteInt(clsAxisPos.SpeedAdd, Convert.ToInt32(txtSpeed.Text), out str);
- commPLC.WriteUShort(clsAxisPos.GoAdd, clsAxisPos.uGoValue, out string str);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- }
- private void btnWrite_Click(object sender, EventArgs e)
- {
- try
- {
- float value = Convert.ToSingle(txtPos.Text);
- commPLC.WriteInt(clsAxisPos.PosAdd,Convert.ToInt32(value * 1000),out string str);
- commPLC.WriteInt(clsAxisPos.SpeedAdd, Convert.ToInt32(txtSpeed.Text), out str);
- clsAxisPos.WritePara($"{clsAxisPos.PosName}位置", AxisName, txtPos.Text.Trim());
- clsAxisPos.WritePara($"{clsAxisPos.PosName}速度", AxisName, txtSpeed.Text.Trim());
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- try
- {
- if(clsAxisPos.LightAdd!= "") uiLight.BeginInvoke(new Action(() => { uiLight.State = clsAxisPos.isLightOn ? Sunny.UI.UILightState.On : Sunny.UI.UILightState.Off; }));
- btnPosGo.BeginInvoke(new Action(() => { btnPosGo.FillColor = ((clsAxisPos.GoCurrValue != clsAxisPos.uGoValue) ? Color.Gray : Color.Green); }));
- }
- catch (Exception ex) { MessageBox.Show(ex.ToString()); }
- }
- private void UCAxisPos_Leave(object sender, EventArgs e)
- {
- timer1.Enabled = false;
- }
- }
- }
|