123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
-
- using Newtonsoft.Json.Linq;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace HRT_Measure
- {
- public partial class UCCylinder : UserControl
- {
- public UCCylinder()
- { InitializeComponent(); }
- public UCCylinder(string plcName, string strInfo,Dictionary<string,ClsPLCIO> dictIO)
- {
- InitializeComponent();
- strPLCName = plcName;
- DictPLCIO = dictIO;
- string[] arrStr = strInfo.Split(',');
- CylinderName = arrStr[0];
- if (arrStr.Length == 2)
- {
- lightReset.Visible = false;
- lightSet.Visible = false;
- btnReset.Visible = false;
- string[] arrStrAdd = arrStr[1].Split('-');
- btnSetting.Text = arrStrAdd[0];
- strSetAdd = arrStrAdd[1];
- strLedSetAdd = arrStrAdd[2];
- }
- else if (arrStr.Length == 3)
- {
- string strreset = arrStr[1];
- string[] arrreset = strreset.Split('-');
- if(arrreset.Length == 5)
- {
- btnReset.Text = arrreset[0];
- strResetAdd = arrreset[1];
- strLedResetAdd = arrreset[2];
- strResetEnableAdd = arrreset[3];
- strSensorResetAdd = arrreset[4];
- }
- else if(arrreset.Length == 4)
- {
- btnReset.Text = arrreset[0];
- strResetAdd = arrreset[1];
- strLedResetAdd = arrreset[2];
- strResetEnableAdd = arrreset[3];
- lightReset.Visible = false;
- }
- string strset= arrStr[2];
- string[] arrset = strset.Split('-');
- if(arrset.Length == 5)
- {
- btnSetting.Text = arrset[0];
- strSetAdd = arrset[1];
- strLedSetAdd = arrset[2];
- strSetEnableAdd = arrset[3];
- strSensorSetAdd = arrset[4];
- }
- else if(arrset.Length == 4)
- {
- btnSetting.Text = arrset[0];
- strSetAdd = arrset[1];
- strLedSetAdd = arrset[2];
- strSetEnableAdd = arrset[3];
- lightSet.Visible = false;
- }
- }
- commPLC = GetPLC();
- thMonitor = new Thread(new ThreadStart(ThMonitor));
- thMonitor.IsBackground = true;
- }
- public Thread thMonitor ;
- CommPLC commPLC;
- private Dictionary<string, ClsPLCIO> DictPLCIO = null;
- public string CylinderName
- {
- set { TitleName.Text = value; }
- get { return TitleName.Text; }
- }
- private string strResetAdd = "";
- private string strSetAdd = "";
- private string strLedResetAdd = "";
- private string strLedSetAdd = "";
- private string strSensorResetAdd = "";
- private string strSensorSetAdd = "";
- private string strResetEnableAdd = "";
- private string strSetEnableAdd = "";
- private string strPLCName = "";
-
- #region MyRegion
- public string ResetAdd
- {
- get { return strResetAdd; }
- set { strResetAdd = value; }
- }
- public string SetAdd
- {
- get { return strSetAdd; }
- set { strSetAdd = value; }
- }
- public string LedResetAdd
- {
- get { return strLedResetAdd; }
- set { strLedResetAdd = value; }
- }
- public string LedSetAdd
- {
- get { return strLedSetAdd; }
- set { strLedSetAdd = value; }
- }
- public string SensorResetAdd
- {
- get { return strSensorResetAdd; }
- set { strSensorResetAdd = value; }
- }
- public string SensorSetAdd
- {
- get { return strSensorSetAdd; }
- set { strSensorSetAdd = value; }
- }
- public string ResetEnableAdd
- {
- get { return strResetEnableAdd; }
- set { strResetEnableAdd = value; }
- }
- public string SetEnableAdd
- {
- get { return strSetEnableAdd; }
- set { strSetEnableAdd = value; }
- }
- public string PLCName
- {
- get { return strPLCName; }
- set { strPLCName = value; }
- }
- #endregion
- private void UCCylinder_Load(object sender, EventArgs e)
- {
- this.Dock = DockStyle.Fill;
- }
-
- 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 btnReset_MouseDown(object sender, MouseEventArgs e)
- {
- try
- {
- ReadPLCHelp.SetBoolValue(ResetAdd, commPLC, true);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- }
- private void btnReset_MouseUp(object sender, MouseEventArgs e)
- {
- try
- {
- ReadPLCHelp.SetBoolValue(ResetAdd, commPLC, false);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- }
- private void btnSetting_MouseDown(object sender, MouseEventArgs e)
- {
- try
- {
- ReadPLCHelp.SetBoolValue(SetAdd, commPLC, true);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- }
- private void btnSetting_MouseUp(object sender, MouseEventArgs e)
- {
- try
- {
- ReadPLCHelp.SetBoolValue(SetAdd, commPLC, false);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- try
- {
- if (strSensorResetAdd != "") lightReset?.BeginInvoke(new Action(() => { lightReset.State = DictPLCIO[CylinderName].isSensorResetOn ? Sunny.UI.UILightState.On : Sunny.UI.UILightState.Off; }));
- if (strSensorSetAdd != "") lightSet?.BeginInvoke(new Action(() => { lightSet.State = DictPLCIO[CylinderName].isSensorSetOn ? Sunny.UI.UILightState.On : Sunny.UI.UILightState.Off; }));
- if (strLedResetAdd != "") btnReset?.BeginInvoke(new Action(() => { btnReset.FillColor = DictPLCIO[CylinderName].isLedResetOn ? Color.Green : Color.Gray; }));
- if (strLedSetAdd != "") btnSetting?.BeginInvoke(new Action(() => { btnSetting.FillColor = DictPLCIO[CylinderName].isLedSetOn ? Color.Green : Color.Gray; }));
- }
- catch (Exception )
- {
- //MessageBox.Show(ex.ToString());
- }
- }
- private void UCCylinder_Leave(object sender, EventArgs e)
- {
- timer1.Enabled = false;
- //try
- //{
- // thMonitor.Abort();
- //}
- //catch (Exception)
- //{
- //}
- }
- 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 (strSensorResetAdd != "") lightReset?.BeginInvoke(new Action(() => { lightReset.State = DictPLCIO[CylinderName].isSensorResetOn ? Sunny.UI.UILightState.On : Sunny.UI.UILightState.Off; }));
- if (strSensorSetAdd != "") lightSet?.BeginInvoke(new Action(() => { lightSet.State = DictPLCIO[CylinderName].isSensorSetOn ? Sunny.UI.UILightState.On : Sunny.UI.UILightState.Off; }));
- if (strLedResetAdd != "") btnReset?.BeginInvoke(new Action(() => { btnReset.FillColor = DictPLCIO[CylinderName].isLedResetOn ? Color.Green : Color.Gray; }));
- if (strLedSetAdd != "") btnSetting?.BeginInvoke(new Action(() => { btnSetting.FillColor = DictPLCIO[CylinderName].isLedSetOn ? Color.Green : Color.Gray; }));
- }
- catch (Exception )
- {
- //MessageBox.Show(ex.ToString());
- }
- Thread.Sleep(20);
-
- }
- }
- }
- }
|