123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370 |
- using Sunny.UI;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics.Eventing.Reader;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace HRT_Measure
- {
- public partial class UCHMI : UserControl
- {
- public UCHMI()
- {
- InitializeComponent();
- }
- public string DisplayLabel
- {
- set { uiTitlePanel1.Text = value; }
- get { return uiTitlePanel1.Text; }
- }
- public Thread thMonitor ;
- public string strPLC = "";
- private void UCHMI_Load(object sender, EventArgs e)
- {
- this.Dock = DockStyle.Fill;
- //timer1.Enabled = true;
- //splitContainer1.SplitterDistance = this.Height / 2;
- switch (DisplayLabel)
- {
- case "上料房 称重房":
- strPLC = "M01M02";
- break;
- case "压机房":
- strPLC = "M03";
- break;
- case "检测房 装箱房":
- strPLC = "M04M05";
- break;
- }
- thMonitor = new Thread(new ThreadStart(ThMonitor));
- thMonitor.IsBackground = true;
- txtAlm.Start();
- }
-
- #region Button
- private void btnInitilize_Click(object sender, EventArgs e)
- {
- //switch (strPLC)
- //{
- // case "M01M02":
- // ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.1", true, out string str);
- // break;
- // case "M03":
- // ProgramHelp.Instance.commPLC_M03.WriteCoin("DB20.4.1", true, out str);
- // break;
- // case "M04M05":
- // ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB20.0.1", true, out str);
- // break;
- //}
-
- }
- private void btnInitilize_MouseDown(object sender, MouseEventArgs e)
- {
- switch (strPLC)
- {
- case "M01M02":
- ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.1", true, out string str);
- break;
- case "M03":
- ProgramHelp.Instance.commPLC_M03.WriteCoin("DB20.4.1", true, out str);
- break;
- case "M04M05":
- ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB20.0.1", true, out str);
- break;
- }
- }
- private void btnInitilize_MouseUp(object sender, MouseEventArgs e)
- {
- switch (strPLC)
- {
- case "M01M02":
- ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.1", false, out string str);
- break;
- case "M03":
- ProgramHelp.Instance.commPLC_M03.WriteCoin("DB20.4.1", false, out str);
- break;
- case "M04M05":
- ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB20.0.1", false, out str);
- break;
- }
- }
- private void btnClearException_Click(object sender, EventArgs e)
- {
- switch (strPLC)
- {
- case "M01M02":
- ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.2", true, out string str);
- break;
- case "M03":
- ProgramHelp.Instance.commPLC_M03.WriteCoin("DB20.4.2", true, out str);
- break;
- case "M04M05":
- ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB20.0.2", true, out str);
- break;
- }
- txtAlm.Text = "";
- }
- private void btnClearException_MouseDown(object sender, MouseEventArgs e)
- {
- //switch (strPLC)
- //{
- // case "M01M02":
- // ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.2", true, out string str);
- // break;
- // case "M03":
- // ProgramHelp.Instance.commPLC_M03.WriteCoin("DB20.4.2", true, out str);
- // break;
- // case "M04M05":
- // ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB20.0.2", true, out str);
- // break;
- //}
- //txtAlm.Text = "";
- }
- private void btnClearException_MouseUp(object sender, MouseEventArgs e)
- {
- switch (strPLC)
- {
- case "M01M02":
- ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.2", false, out string str);
- break;
- case "M03":
- ProgramHelp.Instance.commPLC_M03.WriteCoin("DB20.4.2", false, out str);
- break;
- case "M04M05":
- ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB20.0.2", false, out str);
- break;
- }
- txtAlm.Text = "";
- }
- private void btnStop_Click(object sender, EventArgs e)
- {
- //switch (strPLC)
- //{
- // case "M01M02":
- // ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.4", true, out string str);
- // break;
- // case "M03":
- // ProgramHelp.Instance.commPLC_M03.WriteCoin("DB20.4.4", true, out str);
- // break;
- // case "M04M05":
- // ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB20.0.4", true, out str);
- // break;
- //}
- }
- private void btnStop_MouseDown(object sender, MouseEventArgs e)
- {
- switch (strPLC)
- {
- case "M01M02":
- ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.4", true, out string str);
- break;
- case "M03":
- ProgramHelp.Instance.commPLC_M03.WriteCoin("DB20.4.4", true, out str);
- break;
- case "M04M05":
- ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB20.0.4", true, out str);
- break;
- }
- }
- private void btnStop_MouseUp(object sender, MouseEventArgs e)
- {
- switch (strPLC)
- {
- case "M01M02":
- ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.4", false, out string str);
- break;
- case "M03":
- ProgramHelp.Instance.commPLC_M03.WriteCoin("DB20.4.4", false, out str);
- break;
- case "M04M05":
- ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB20.0.4", false, out str);
- break;
- }
- }
- private void btnStart_Click(object sender, EventArgs e)
- {
- //switch (strPLC)
- //{
- // case "M01M02":
- // ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.3", true, out string str);
- // break;
- // case "M03":
- // ProgramHelp.Instance.commPLC_M03.WriteCoin("DB48.25.1", true, out str);
- // break;
- // case "M04M05":
- // ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB48.25.1", true, out str);
- // break;
- //}
- }
- private void btnStart_MouseDown(object sender, MouseEventArgs e)
- {
- switch (strPLC)
- {
- case "M01M02":
- ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.3", true, out string str);
- break;
- case "M03":
- ProgramHelp.Instance.commPLC_M03.WriteCoin("DB48.25.1", true, out str);
- break;
- case "M04M05":
- ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB48.25.1", true, out str);
- break;
- }
- }
- private void btnStart_MouseUp(object sender, MouseEventArgs e)
- {
- switch (strPLC)
- {
- case "M01M02":
- ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.3", false, out string str);
- break;
- case "M03":
- ProgramHelp.Instance.commPLC_M03.WriteCoin("DB48.25.1", false, out str);
- break;
- case "M04M05":
- ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB48.25.1", false, out str);
- break;
- }
- }
- private void btnHandAndAuto_Click(object sender, EventArgs e)
- {
- switch (strPLC)
- {
- case "M01M02":
- //ProgramHelp.Instance.commPLC_M01M02.ReadCoin("DB20.494.5", out bool isTrue, out string str);
- ProgramHelp.Instance.commPLC_M01M02.WriteCoin("DB20.494.5", !PLCCylinder.dictPLC_InitIO["M01M02"].isHandOrAuto , out string str);//isTrue
- break;
- case "M03":
- //ProgramHelp.Instance.commPLC_M03.ReadCoin("DB20.4.5", out isTrue, out str);
- ProgramHelp.Instance.commPLC_M03.WriteCoin("DB20.4.5", !PLCCylinder.dictPLC_InitIO["M03"].isHandOrAuto, out str);
- break;
- case "M04M05":
- //ProgramHelp.Instance.commPLC_M04M05.ReadCoin("DB20.0.5", out isTrue, out str);
- ProgramHelp.Instance.commPLC_M04M05.WriteCoin("DB20.0.5", !PLCCylinder.dictPLC_InitIO["M04M05"].isHandOrAuto, out str);
- break;
- }
- }
- #endregion
-
- private void timer1_Tick(object sender, EventArgs e)
- {
- try
- {
- //string strPLC = strPLC;
-
- //if (PLCCylinder.dictPLC_InitIO[strPLC].isHandOrAuto) btnHandAndAuto.BeginInvoke(new Action(() => { btnHandAndAuto.Text = "手动"; btnHandAndAuto.Symbol = 362038; }));
- //else btnHandAndAuto.BeginInvoke(new Action(() => { btnHandAndAuto.Text = "自动"; btnHandAndAuto.Symbol = 57531; }));
- if (PLCCylinder.dictPLC_InitIO[strPLC].isInitDone) lightInitDone.BeginInvoke(new Action(() => { lightInitDone.State = Sunny.UI.UILightState.On; }));
- else lightInitDone.BeginInvoke(new Action(() => { lightInitDone.State = Sunny.UI.UILightState.Off; }));
- if (PLCCylinder.dictPLC_InitIO[strPLC].isWait) lightWait.BeginInvoke(new Action(() => { lightWait.State = Sunny.UI.UILightState.On; }));
- else lightWait.BeginInvoke(new Action(() => { lightWait.State = Sunny.UI.UILightState.Off; }));
- if (PLCCylinder.dictPLC_InitIO[strPLC].isAlm) lightAlm.BeginInvoke(new Action(() => { lightAlm.State = Sunny.UI.UILightState.On; }));
- else lightAlm.BeginInvoke(new Action(() => { lightAlm.State = Sunny.UI.UILightState.Off; }));
- if (PLCCylinder.dictPLC_InitIO[strPLC].isAutoRunning) lightAutoRun.BeginInvoke(new Action(() => { lightAutoRun.State = Sunny.UI.UILightState.On; }));
- else lightAutoRun.BeginInvoke(new Action(() => { lightAutoRun.State = Sunny.UI.UILightState.Off; }));
-
- btnInitilize.BeginInvoke(new Action(() => { btnInitilize.FillColor = PLCCylinder.dictPLC_InitIO[strPLC].isBtnInit ? Color.Red : Color.LightSkyBlue; }));
- btnClearException.BeginInvoke(new Action(() => { btnClearException.FillColor = PLCCylinder.dictPLC_InitIO[strPLC].isBtnExceptionQuit ? Color.Red : Color.LightSkyBlue; }));
- btnStop.BeginInvoke(new Action(() => { btnStop.FillColor = PLCCylinder.dictPLC_InitIO[strPLC].isBtnStop ? Color.Red : Color.LightSkyBlue; }));
- btnStart.BeginInvoke(new Action(() => { btnStart.FillColor = PLCCylinder.dictPLC_InitIO[strPLC].isBtnStart ? Color.Red : Color.LightSkyBlue; }));
- btnHandAndAuto.BeginInvoke(new Action(() => { btnHandAndAuto.FillColor = PLCCylinder.dictPLC_InitIO[strPLC].isBtnHandOrAuto ? Color.Red : Color.LightSkyBlue; }));
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- }
-
- private void ThMonitor()
- {
- while (true)
- {
- try
- {
- if (PLCCylinder.dictPLC_InitIO[strPLC].isInitDone) lightInitDone.BeginInvoke(new Action(() => { lightInitDone.State = Sunny.UI.UILightState.On; }));
- else lightInitDone.BeginInvoke(new Action(() => { lightInitDone.State = Sunny.UI.UILightState.Off; }));
- if (PLCCylinder.dictPLC_InitIO[strPLC].isWait) lightWait.BeginInvoke(new Action(() => { lightWait.State = Sunny.UI.UILightState.On; }));
- else lightWait.BeginInvoke(new Action(() => { lightWait.State = Sunny.UI.UILightState.Off; }));
- if (PLCCylinder.dictPLC_InitIO[strPLC].isAlm) lightAlm.BeginInvoke(new Action(() => { lightAlm.State = Sunny.UI.UILightState.On; }));
- else
- {
- lightAlm.BeginInvoke(new Action(() => { lightAlm.State = Sunny.UI.UILightState.Off; }));
- txtAlm.BeginInvoke(new Action(() => { txtAlm.Text = ""; }));
- }
- if (PLCCylinder.dictPLC_InitIO[strPLC].isAutoRunning) lightAutoRun.BeginInvoke(new Action(() => { lightAutoRun.State = Sunny.UI.UILightState.On; }));
- else lightAutoRun.BeginInvoke(new Action(() => { lightAutoRun.State = Sunny.UI.UILightState.Off; }));
- btnInitilize.BeginInvoke(new Action(() => { btnInitilize.FillColor = PLCCylinder.dictPLC_InitIO[strPLC].isBtnInit ? Color.Red : Color.LightSkyBlue; }));
- btnClearException.BeginInvoke(new Action(() => { btnClearException.FillColor = PLCCylinder.dictPLC_InitIO[strPLC].isBtnExceptionQuit ? Color.Red : Color.LightSkyBlue; }));
- btnStop.BeginInvoke(new Action(() => { btnStop.FillColor = PLCCylinder.dictPLC_InitIO[strPLC].isBtnStop ? Color.Red : Color.LightSkyBlue; }));
- btnStart.BeginInvoke(new Action(() => { btnStart.FillColor = PLCCylinder.dictPLC_InitIO[strPLC].isBtnStart ? Color.Red : Color.LightSkyBlue; }));
- btnHandAndAuto.BeginInvoke(new Action(() => { btnHandAndAuto.FillColor = PLCCylinder.dictPLC_InitIO[strPLC].isBtnHandOrAuto ? Color.Red : Color.LightSkyBlue;
- btnHandAndAuto.Text = PLCCylinder.dictPLC_InitIO[strPLC].isBtnHandOrAuto ? "自动模式" : "手动模式";
- }));
- switch(strPLC)
- {
- case "M01M02":
- foreach (var item in PLCCylinder.dictM01M02_Alm)
- {
- if (item.Value.isAlm) txtAlm.BeginInvoke(new Action(() => { if(!txtAlm.Text.Contains(item.Value.AlmName)) txtAlm.Text += item.Value.AlmName + ";"; }));
- }
- break;
- case "M03":
- foreach (var item in PLCCylinder.dictM03_Alm)
- {
- if (item.Value.isAlm) txtAlm.BeginInvoke(new Action(() => { if (!txtAlm.Text.Contains(item.Value.AlmName)) txtAlm.Text += item.Value.AlmName + ";"; }));
- }
- break;
- case "M04M05":
- foreach (var item in PLCCylinder.dictM04M05_Alm)
- {
- if (item.Value.isAlm) txtAlm.BeginInvoke(new Action(() => { if (!txtAlm.Text.Contains(item.Value.AlmName)) txtAlm.Text += item.Value.AlmName + ";"; }));
- }
- break;
- }
-
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- Thread.Sleep(1);
- }
- }
-
-
-
-
- }
- }
|