2021-06-05 14:17:30 +08:00
|
|
|
|
using CleanMachineHMI.Utils;
|
2021-12-26 21:30:02 +08:00
|
|
|
|
using Krypton.Toolkit;
|
2021-06-05 14:17:30 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
using System.Data;
|
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Windows.Forms;
|
2021-12-31 19:53:53 +08:00
|
|
|
|
using CleanMachine.Model;
|
2022-05-05 20:42:02 +08:00
|
|
|
|
using CleanMachine.Model.BAS;
|
|
|
|
|
|
|
2021-06-05 14:17:30 +08:00
|
|
|
|
namespace CleanMachineHMI
|
|
|
|
|
|
{
|
|
|
|
|
|
public partial class frmIoMonitorNew : KryptonForm
|
|
|
|
|
|
{
|
|
|
|
|
|
public frmIoMonitorNew()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
}
|
|
|
|
|
|
private object lockObj = new object();
|
2022-03-18 21:25:34 +08:00
|
|
|
|
|
2021-06-05 14:17:30 +08:00
|
|
|
|
public const int WM_SYSCOMMAND = 0x112;
|
|
|
|
|
|
public const int SC_MOVE = 0xF012;
|
|
|
|
|
|
protected override void WndProc(ref Message m)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m.Msg == WM_SYSCOMMAND)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ((int)m.WParam == SC_MOVE)
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
base.WndProc(ref m);
|
|
|
|
|
|
}
|
|
|
|
|
|
private void kryptonButton1_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
Task.Run(async delegate {
|
|
|
|
|
|
GlobalHelper.eventLock = true;
|
|
|
|
|
|
await Task.Delay(100);
|
|
|
|
|
|
Invoke(new Action(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
GlobalHelper.OnShowX_Y_Status -= Show_X_Y_Status;
|
|
|
|
|
|
GlobalHelper.OnShowSensorStatus -= ShowSensorStatus;
|
|
|
|
|
|
GlobalHelper.IoMonitor_2.SuspendLayout();
|
|
|
|
|
|
GlobalHelper.IoMonitor_2.Hide();
|
|
|
|
|
|
GlobalHelper.eventLock = false;
|
|
|
|
|
|
}));
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private void frmIoMonitorNew_2_Load(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
initControl();
|
|
|
|
|
|
GlobalHelper.OnShowX_Y_Status += Show_X_Y_Status;
|
|
|
|
|
|
GlobalHelper.OnShowSensorStatus += ShowSensorStatus;
|
|
|
|
|
|
}
|
|
|
|
|
|
private void ShowSensorStatus(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
lock (lockObj)
|
|
|
|
|
|
{
|
2021-12-31 19:53:53 +08:00
|
|
|
|
PlcItem item = sender as PlcItem;
|
2021-06-05 14:17:30 +08:00
|
|
|
|
Invoke(new Action(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.PlcItemDataType == 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
Control[] crnLst = this.Controls.Find("picb_X" + Convert.ToString(Convert.ToInt32(item.PlcItemPriAddress), 8).PadLeft(2, '0'), true);
|
|
|
|
|
|
if (crnLst.Length > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
PictureBox ctn = crnLst[0] as PictureBox;
|
|
|
|
|
|
if (string.IsNullOrEmpty(item.PlcItemValue))
|
|
|
|
|
|
{
|
|
|
|
|
|
ctn.BackColor = Color.White;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (bool.Parse(item.PlcItemValue.ToString()))
|
|
|
|
|
|
{
|
|
|
|
|
|
ctn.BackColor = Color.Lime;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
ctn.BackColor = Color.White;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Control[] crnLst = this.Controls.Find("picb_M" + Convert.ToInt32(item.PlcItemPriAddress), true);
|
|
|
|
|
|
if (crnLst.Length > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
PictureBox ctn = crnLst[0] as PictureBox;
|
|
|
|
|
|
if (string.IsNullOrEmpty(item.PlcItemValue))
|
|
|
|
|
|
{
|
|
|
|
|
|
ctn.BackColor = Color.White;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (bool.Parse(item.PlcItemValue.ToString()))
|
|
|
|
|
|
{
|
|
|
|
|
|
ctn.BackColor = Color.Lime;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
ctn.BackColor = Color.White;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private void Show_X_Y_Status(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
lock (lockObj)
|
|
|
|
|
|
{
|
2021-12-31 19:53:53 +08:00
|
|
|
|
PlcItem item = sender as PlcItem;
|
2021-06-05 14:17:30 +08:00
|
|
|
|
Invoke(new Action(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item.PlcItemDataType == 2)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
Control[] crnLst = this.Controls.Find("cbt_X" + Convert.ToString(Convert.ToInt32(item.PlcItemPriAddress), 8).PadLeft(2, '0'), true);
|
|
|
|
|
|
if (crnLst.Length > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
CircleButton ctn = crnLst[0] as CircleButton;
|
|
|
|
|
|
if (string.IsNullOrEmpty(item.PlcItemValue))
|
|
|
|
|
|
{
|
|
|
|
|
|
ctn.BackColor = Color.FromArgb(191, 219, 255);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (bool.Parse(item.PlcItemValue.ToString()))
|
|
|
|
|
|
{
|
|
|
|
|
|
ctn.BackColor = Color.Lime;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
ctn.BackColor = Color.Red;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Control[] crnLst = this.Controls.Find("cbt_Y" + Convert.ToString(Convert.ToInt32(item.PlcItemPriAddress), 8).PadLeft(2, '0'), true);
|
|
|
|
|
|
if (crnLst.Length > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
CircleButton ctn = crnLst[0] as CircleButton;
|
|
|
|
|
|
if (string.IsNullOrEmpty(item.PlcItemValue))
|
|
|
|
|
|
{
|
|
|
|
|
|
ctn.BackColor = Color.FromArgb(191, 219, 255);
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (bool.Parse(item.PlcItemValue.ToString()))
|
|
|
|
|
|
{
|
|
|
|
|
|
ctn.BackColor = Color.Lime;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
ctn.BackColor = Color.Red;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private void initControl()
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
if (GlobalHelper.PlcItemMd_X_List != null && GlobalHelper.PlcItemMd_X_List.Count > 0)
|
|
|
|
|
|
{
|
2021-12-31 19:53:53 +08:00
|
|
|
|
List<PlcItem> tempLst = GlobalHelper.PlcItemMd_X_List.OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList();
|
|
|
|
|
|
foreach (PlcItem item in tempLst)
|
2021-06-05 14:17:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
Invoke(new Action(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (this.Controls.Find("klb_X" + Convert.ToString(Convert.ToInt32(item.PlcItemPriAddress), 8).PadLeft(2, '0'), true).Length > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
KryptonLabel label1 = this.Controls.Find("klb_X" + Convert.ToString(Convert.ToInt32(item.PlcItemPriAddress), 8).PadLeft(2, '0'), true)[0] as KryptonLabel;
|
|
|
|
|
|
|
2022-05-06 08:45:56 +08:00
|
|
|
|
label1.Text = this.T(item.PlcItemName.Replace("(I/O监控)", ""), item.PlcItemCode);
|
2021-06-05 14:17:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (GlobalHelper.PlcItemMd_Y_List != null && GlobalHelper.PlcItemMd_Y_List.Count > 0)
|
|
|
|
|
|
{
|
2021-12-31 19:53:53 +08:00
|
|
|
|
List<PlcItem> tempLst = GlobalHelper.PlcItemMd_Y_List.OrderBy(x => Convert.ToInt32(x.PlcItemPriAddress)).ToList();
|
|
|
|
|
|
foreach (PlcItem item in tempLst)
|
2021-06-05 14:17:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
Invoke(new Action(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (this.Controls.Find("klb_Y" + Convert.ToString(Convert.ToInt32(item.PlcItemPriAddress), 8).PadLeft(2, '0'), true).Length > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
KryptonLabel label1 = this.Controls.Find("klb_Y" + Convert.ToString(Convert.ToInt32(item.PlcItemPriAddress), 8).PadLeft(2, '0'), true)[0] as KryptonLabel;
|
|
|
|
|
|
|
2022-05-06 08:45:56 +08:00
|
|
|
|
label1.Text = this.T(item.PlcItemName.Replace("(I/O监控)", ""), item.PlcItemCode);
|
2021-06-05 14:17:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
KryptonMessageBox.Show(ex.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void picb_X30_MouseHover(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
ToolTip ttp = new ToolTip();
|
|
|
|
|
|
ttp.InitialDelay = 200;
|
|
|
|
|
|
ttp.AutoPopDelay = 3000;
|
|
|
|
|
|
ttp.ReshowDelay = 200;
|
|
|
|
|
|
ttp.ShowAlways = true;
|
|
|
|
|
|
ttp.IsBalloon = true;
|
|
|
|
|
|
PictureBox pic = sender as PictureBox;
|
|
|
|
|
|
string plcItemNameAddress = pic.Name.Replace("picb_", "");
|
|
|
|
|
|
if (plcItemNameAddress.StartsWith("M"))
|
|
|
|
|
|
{
|
2021-12-31 19:53:53 +08:00
|
|
|
|
PlcItem tmpPlc = GlobalHelper.PlcItemMd_M_List.First(x => x.PlcItemPriAddress == plcItemNameAddress.Replace("M", ""));
|
2021-06-05 14:17:30 +08:00
|
|
|
|
if (tmpPlc != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
ttp.SetToolTip(pic, tmpPlc.PlcItemName);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2021-12-31 19:53:53 +08:00
|
|
|
|
PlcItem tmpPlc = GlobalHelper.PlcItemMd_X_List.First(x => x.PlcItemPriAddress == Convert.ToInt32(plcItemNameAddress.Replace("X", ""), 10).ToString());
|
2021-06-05 14:17:30 +08:00
|
|
|
|
if (tmpPlc != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
ttp.SetToolTip(pic, tmpPlc.PlcItemName);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
KryptonMessageBox.Show(ex.Message);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|