提交设备状态

This commit is contained in:
Admin 2025-04-25 09:03:47 +08:00
parent ae5c1122ed
commit b749eb4266
6 changed files with 197 additions and 66 deletions

View File

@ -9,8 +9,9 @@ namespace DH.Commons.Enums
{ {
public enum EnumStatus public enum EnumStatus
{ {
, ,
, ,
,
, ,
} }

View File

@ -18,7 +18,7 @@ namespace DH.Commons.Models
/// <summary> /// <summary>
/// 当前状态 /// 当前状态
/// </summary> /// </summary>
public static EnumStatus CurrentStatus =EnumStatus.; public static EnumStatus CurrentStatus =EnumStatus.;
} }
/// <summary> /// <summary>

View File

@ -846,6 +846,9 @@ namespace DH.Devices.PLC
Thread.Sleep(1000); Thread.Sleep(1000);
//计数清零 //计数清零
CountToZero(); CountToZero();
Thread.Sleep(1000);
//绿灯
GreenLight(true);
LogAsync(DateTime.Now, LogLevel.Information, $"状态复位-关闭定位-写入流程加载点位配置-计数清零"); LogAsync(DateTime.Now, LogLevel.Information, $"状态复位-关闭定位-写入流程加载点位配置-计数清零");
Thread.Sleep(200); Thread.Sleep(200);
@ -870,11 +873,8 @@ namespace DH.Devices.PLC
Thread.Sleep(1000); Thread.Sleep(1000);
StopProcessAction(); StopProcessAction();
TurnStart(false); TurnStart(false);
LogAsync(DateTime.Now, LogLevel.Action, $"流程停止");
Task.Run(async () => {
await ExecuteClearDelayAsync();
});
} }
@ -883,10 +883,8 @@ namespace DH.Devices.PLC
int? clearTime = ConfigModel.GlobalList?.FirstOrDefault()?.ClearTime; int? clearTime = ConfigModel.GlobalList?.FirstOrDefault()?.ClearTime;
if (clearTime != null) if (clearTime != null)
{ {
LogAsync(DateTime.Now, LogLevel.Action, $"转盘清料开始");
TurnClear(true); TurnClear(true);
await Task.Delay(clearTime.Value * 1000); await Task.Delay(clearTime.Value * 1000);
LogAsync(DateTime.Now, LogLevel.Action, $"转盘清料完成");
TurnClear(false); TurnClear(false);
} }
} }

View File

@ -62,6 +62,7 @@
lblOEE_Total = new Label(); lblOEE_Total = new Label();
label10 = new Label(); label10 = new Label();
label7 = new Label(); label7 = new Label();
tagMachineStatus = new AntdUI.Tag();
panel2 = new AntdUI.Panel(); panel2 = new AntdUI.Panel();
panel1 = new AntdUI.Panel(); panel1 = new AntdUI.Panel();
segmented2 = new AntdUI.Segmented(); segmented2 = new AntdUI.Segmented();
@ -295,6 +296,7 @@
tableLayoutNums.ColumnCount = 1; tableLayoutNums.ColumnCount = 1;
tableLayoutNums.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); tableLayoutNums.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
tableLayoutNums.Controls.Add(tableLayoutPanel3, 0, 1); tableLayoutNums.Controls.Add(tableLayoutPanel3, 0, 1);
tableLayoutNums.Controls.Add(tagMachineStatus, 0, 0);
tableLayoutNums.Dock = DockStyle.Fill; tableLayoutNums.Dock = DockStyle.Fill;
tableLayoutNums.Location = new Point(0, 0); tableLayoutNums.Location = new Point(0, 0);
tableLayoutNums.Name = "tableLayoutNums"; tableLayoutNums.Name = "tableLayoutNums";
@ -419,6 +421,16 @@
label7.Text = "总计数"; label7.Text = "总计数";
label7.TextAlign = ContentAlignment.MiddleCenter; label7.TextAlign = ContentAlignment.MiddleCenter;
// //
// tagMachineStatus
//
tagMachineStatus.Font = new Font("Microsoft YaHei UI", 14.25F, FontStyle.Regular, GraphicsUnit.Point, 134);
tagMachineStatus.Location = new Point(3, 3);
tagMachineStatus.Name = "tagMachineStatus";
tagMachineStatus.Size = new Size(141, 44);
tagMachineStatus.TabIndex = 12;
tagMachineStatus.Text = "待机中";
tagMachineStatus.Type = AntdUI.TTypeMini.Primary;
//
// panel2 // panel2
// //
panel2.Location = new Point(511, 86); panel2.Location = new Point(511, 86);
@ -502,7 +514,7 @@
btnCreateBatchNO.Name = "btnCreateBatchNO"; btnCreateBatchNO.Name = "btnCreateBatchNO";
btnCreateBatchNO.Size = new Size(72, 35); btnCreateBatchNO.Size = new Size(72, 35);
btnCreateBatchNO.TabIndex = 21; btnCreateBatchNO.TabIndex = 21;
btnCreateBatchNO.Tag = "sys-load"; btnCreateBatchNO.Tag = "";
btnCreateBatchNO.Text = "生成批次"; btnCreateBatchNO.Text = "生成批次";
btnCreateBatchNO.Click += btnCreateBatchNO_Click; btnCreateBatchNO.Click += btnCreateBatchNO_Click;
// //
@ -753,5 +765,6 @@
private AntdUI.Button btnCreateBatchNO; private AntdUI.Button btnCreateBatchNO;
private AntdUI.Input textBoxBatchNO; private AntdUI.Input textBoxBatchNO;
private AntdUI.Segmented segmented2; private AntdUI.Segmented segmented2;
public AntdUI.Tag tagMachineStatus;
} }
} }

View File

@ -701,49 +701,57 @@ namespace DHSoftware
public void ConnectPLC() public void ConnectPLC()
{ {
if (ConfigModel.PLCBaseList.Count > 0) try
{ {
for (int i = 0; i < ConfigModel.PLCBaseList.Count; i++) if (ConfigModel.PLCBaseList.Count > 0)
{ {
var plcBase = ConfigModel.PLCBaseList[i]; for (int i = 0; i < ConfigModel.PLCBaseList.Count; i++)
if (plcBase.PLCType == EnumPLCType.XC网口 || plcBase.PLCType == EnumPLCType.XD网口)
{ {
PLC.IP = plcBase.IP; var plcBase = ConfigModel.PLCBaseList[i];
PLC.PLCType = plcBase.PLCType; if (plcBase.PLCType == EnumPLCType.XC网口 || plcBase.PLCType == EnumPLCType.XD网口)
PLC.Enable = plcBase.Enable;
PLC.PLCName = plcBase.PLCName;
PLC.PLCItemList = plcBase.PLCItemList;
PLC.Port = plcBase.Port;
PLC.OnLog -= _visionEngine_OnLog;
PLC.OnLog += _visionEngine_OnLog;
if(PLC.Enable)
{ {
PLC.PLCConnect(); PLC.IP = plcBase.IP;
Button CamLabel = new Button(); PLC.PLCType = plcBase.PLCType;
CamLabel.Name = PLC.PLCName; PLC.Enable = plcBase.Enable;
CamLabel.Text = PLC.PLCName; // 关键1必须有文本 PLC.PLCName = plcBase.PLCName;
CamLabel.AutoSize = true; PLC.PLCItemList = plcBase.PLCItemList;
CamLabel.Size = new System.Drawing.Size(20, 20); // 关键2自动调整大小 PLC.Port = plcBase.Port;
CamLabel.Location = new Point(20 + 50 * (i + ConfigModel.CameraBaseList.Count), 12); // 关键3明确位置 PLC.OnLog -= _visionEngine_OnLog;
if (PLC.Connected) PLC.OnLog += _visionEngine_OnLog;
CamLabel.BackColor = Color.Green; // 关键4避免透明 if (PLC.Enable)
else
CamLabel.BackColor = Color.Yellow; // 关键4避免透明
CamLabel.ForeColor = Color.Black; // 关键4避免透明
//CamLabel.ForeColor = Color.Green; // 关键4避免透明
CamLabel.Font = new Font("Microsoft YaHei", 9); // 可选:字体
// 关键5确保添加到父控件
if (pageHeader1 != null && !pageHeader1.Controls.Contains(CamLabel))
{ {
pageHeader1.Controls.Add(CamLabel); PLC.PLCConnect();
Button CamLabel = new Button();
CamLabel.Name = PLC.PLCName;
CamLabel.Text = PLC.PLCName; // 关键1必须有文本
CamLabel.AutoSize = true;
CamLabel.Size = new System.Drawing.Size(20, 20); // 关键2自动调整大小
CamLabel.Location = new Point(20 + 50 * (i + ConfigModel.CameraBaseList.Count), 12); // 关键3明确位置
if (PLC.Connected)
CamLabel.BackColor = Color.Green; // 关键4避免透明
else
CamLabel.BackColor = Color.Yellow; // 关键4避免透明
CamLabel.ForeColor = Color.Black; // 关键4避免透明
//CamLabel.ForeColor = Color.Green; // 关键4避免透明
CamLabel.Font = new Font("Microsoft YaHei", 9); // 可选:字体
// 关键5确保添加到父控件
if (pageHeader1 != null && !pageHeader1.Controls.Contains(CamLabel))
{
pageHeader1.Controls.Add(CamLabel);
}
} }
} }
} }
} }
} }
catch (Exception ex)
{
}
} }
FrmLog frmLog; FrmLog frmLog;
public void InitModel() public void InitModel()
@ -1122,7 +1130,7 @@ namespace DHSoftware
//EmergencyStop(null, null, null); //EmergencyStop(null, null, null);
} }
Thread.Sleep(50); // 降低 CPU 占用,根据实际调整轮询间隔 Thread.Sleep(50);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -1264,13 +1272,58 @@ namespace DHSoftware
private void HandleStartButton() private void HandleStartButton()
{ {
InitialCameraSumsView(); lock (_stopLock)
LogAsync(DateTime.Now, LogLevel.Information, "流程启动中,请稍候..."); {
ResetAllCameraCounts(); if (_isStopProcessing) return;
//开始流程 _isStopProcessing = true;
}
StartProcess(); try
LogAsync(DateTime.Now, LogLevel.Action, "流程启动完成!"); {
if (SystemModel.CurrentStatus == EnumStatus.)
{
InitialCameraSumsView();
LogAsync(DateTime.Now, LogLevel.Information, "流程启动中,请稍候...");
ResetAllCameraCounts();
//开始流程
StartProcess();
SystemModel.CurrentStatus = EnumStatus.;
this.BeginInvoke(new MethodInvoker(delegate ()
{
tagMachineStatus.Type = TTypeMini.Success;
tagMachineStatus.Text = "运行中";
}));
LogAsync(DateTime.Now, LogLevel.Action, "流程启动完成!");
}
else if (SystemModel.CurrentStatus == EnumStatus.)
{
LogAsync(DateTime.Now, LogLevel.Warning, "设备正在运行,无需启动!");
}
else if (SystemModel.CurrentStatus == EnumStatus.)
{
LogAsync(DateTime.Now, LogLevel.Warning, "设备正在清料,请稍候!");
}
else if (SystemModel.CurrentStatus == EnumStatus.)
{
LogAsync(DateTime.Now, LogLevel.Warning, "设备报警,请复位后重试!");
}
else if (SystemModel.CurrentStatus == EnumStatus.)
{
LogAsync(DateTime.Now, LogLevel.Warning, "设备异常,请检查!");
}
}
finally
{
lock (_stopLock)
{
_isStopProcessing = false;
}
}
} }
@ -1279,10 +1332,7 @@ namespace DHSoftware
{ {
try try
{ {
if (CurrentMachine)
{
return;
}
BatchNO = textBoxBatchNO.Text; BatchNO = textBoxBatchNO.Text;
textBoxBatchNO.ReadOnly = true; textBoxBatchNO.ReadOnly = true;
@ -1848,26 +1898,89 @@ namespace DHSoftware
} }
private void HandleStopButton() private readonly object _stopLock = new object(); // 锁对象
{ private bool _isStopProcessing = false; // 状态标志
if (!CurrentMachine) private async void HandleStopButton()
{
// 通过锁和状态标志实现双重检查
lock (_stopLock)
{ {
return; if (_isStopProcessing) return;
_isStopProcessing = true;
}
try
{
if (SystemModel.CurrentStatus == EnumStatus.)
{
LogAsync(DateTime.Now, LogLevel.Warning, "设备待机中,无需停止!");
}
else if (SystemModel.CurrentStatus == EnumStatus.)
{
textBoxBatchNO.ReadOnly = false;
btnCreateBatchNO.Enabled = true;
// Cameras.Clear();
// Dectection.Clear();
// Add the code for the "停止" button click here
PLC.StopProcess();
SystemModel.CurrentStatus = EnumStatus.;
this.BeginInvoke(new MethodInvoker(delegate ()
{
tagMachineStatus.Type = TTypeMini.Primary;
tagMachineStatus.Text = "待机中";
}));
LogAsync(DateTime.Now, LogLevel.Action, $"流程停止!");
await Task.Run(async () =>
{
await ExecuteClearDelayAsync();
});
}
else if (SystemModel.CurrentStatus == EnumStatus.)
{
LogAsync(DateTime.Now, LogLevel.Warning, "设备正在清料,请稍候!");
}
else if (SystemModel.CurrentStatus == EnumStatus.)
{
LogAsync(DateTime.Now, LogLevel.Warning, "设备报警,请复位后重试!");
}
else if (SystemModel.CurrentStatus == EnumStatus.)
{
LogAsync(DateTime.Now, LogLevel.Warning, "设备异常,请检查!");
}
}
finally
{
lock (_stopLock)
{
_isStopProcessing = false;
}
} }
textBoxBatchNO.ReadOnly = false;
btnCreateBatchNO.Enabled = true;
// Cameras.Clear();
// Dectection.Clear();
// Add the code for the "停止" button click here
PLC.StopProcess();
CurrentMachine = false;
//sLDMotion.Stop(); //sLDMotion.Stop();
} }
private async Task ExecuteClearDelayAsync()
{
LogAsync(DateTime.Now, LogLevel.Action, $"转盘清料开始");
SystemModel.CurrentStatus = EnumStatus.;
this.BeginInvoke(new MethodInvoker(delegate ()
{
tagMachineStatus.Type = TTypeMini.Warn;
tagMachineStatus.Text = "清料中";
}));
await PLC.ExecuteClearDelayAsync();
LogAsync(DateTime.Now, LogLevel.Action, $"转盘清料完成");
SystemModel.CurrentStatus = EnumStatus.;
this.BeginInvoke(new MethodInvoker(delegate ()
{
tagMachineStatus.Type = TTypeMini.Primary;
tagMachineStatus.Text = "待机中";
}));
}
public void CalculateOEE() public void CalculateOEE()
{ {

View File

@ -67,6 +67,8 @@ namespace DHSoftware
catch (Exception ex) catch (Exception ex)
{ {
SystemModel.CurrentStatus = EnumStatus.; SystemModel.CurrentStatus = EnumStatus.;
MainWindow.Instance.tagMachineStatus.Type = TTypeMini.Error;
MainWindow.Instance.tagMachineStatus.Text = "异常";
Modal.open(WelcomeWindow.Instance, "错误!", ex.ToString(), TType.Error); Modal.open(WelcomeWindow.Instance, "错误!", ex.ToString(), TType.Error);
} }
@ -99,6 +101,8 @@ namespace DHSoftware
catch (Exception ex) catch (Exception ex)
{ {
SystemModel.CurrentStatus = EnumStatus.; SystemModel.CurrentStatus = EnumStatus.;
MainWindow.Instance.tagMachineStatus.Type = TTypeMini.Error;
MainWindow.Instance.tagMachineStatus.Text = "异常";
Modal.open(WelcomeWindow.Instance, "错误!", ex.ToString(), TType.Error); Modal.open(WelcomeWindow.Instance, "错误!", ex.ToString(), TType.Error);
} }
UpdateStep(80, "正在加载算法模型", true); UpdateStep(80, "正在加载算法模型", true);
@ -109,6 +113,8 @@ namespace DHSoftware
catch (Exception ex) catch (Exception ex)
{ {
SystemModel.CurrentStatus = EnumStatus.; SystemModel.CurrentStatus = EnumStatus.;
MainWindow.Instance.tagMachineStatus.Type = TTypeMini.Error;
MainWindow.Instance.tagMachineStatus.Text = "异常";
Modal.open(WelcomeWindow.Instance, "错误!", ex.ToString(), TType.Error); Modal.open(WelcomeWindow.Instance, "错误!", ex.ToString(), TType.Error);
} }
UpdateStep(100, "程序初始化完成", true); UpdateStep(100, "程序初始化完成", true);