提交设备状态

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
{
,
,
,
,
,
}

View File

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

View File

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

View File

@ -62,6 +62,7 @@
lblOEE_Total = new Label();
label10 = new Label();
label7 = new Label();
tagMachineStatus = new AntdUI.Tag();
panel2 = new AntdUI.Panel();
panel1 = new AntdUI.Panel();
segmented2 = new AntdUI.Segmented();
@ -295,6 +296,7 @@
tableLayoutNums.ColumnCount = 1;
tableLayoutNums.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
tableLayoutNums.Controls.Add(tableLayoutPanel3, 0, 1);
tableLayoutNums.Controls.Add(tagMachineStatus, 0, 0);
tableLayoutNums.Dock = DockStyle.Fill;
tableLayoutNums.Location = new Point(0, 0);
tableLayoutNums.Name = "tableLayoutNums";
@ -419,6 +421,16 @@
label7.Text = "总计数";
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.Location = new Point(511, 86);
@ -502,7 +514,7 @@
btnCreateBatchNO.Name = "btnCreateBatchNO";
btnCreateBatchNO.Size = new Size(72, 35);
btnCreateBatchNO.TabIndex = 21;
btnCreateBatchNO.Tag = "sys-load";
btnCreateBatchNO.Tag = "";
btnCreateBatchNO.Text = "生成批次";
btnCreateBatchNO.Click += btnCreateBatchNO_Click;
//
@ -753,5 +765,6 @@
private AntdUI.Button btnCreateBatchNO;
private AntdUI.Input textBoxBatchNO;
private AntdUI.Segmented segmented2;
public AntdUI.Tag tagMachineStatus;
}
}

View File

@ -701,49 +701,57 @@ namespace DHSoftware
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];
if (plcBase.PLCType == EnumPLCType.XC网口 || plcBase.PLCType == EnumPLCType.XD网口)
for (int i = 0; i < ConfigModel.PLCBaseList.Count; i++)
{
PLC.IP = plcBase.IP;
PLC.PLCType = plcBase.PLCType;
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)
var plcBase = ConfigModel.PLCBaseList[i];
if (plcBase.PLCType == EnumPLCType.XC网口 || plcBase.PLCType == EnumPLCType.XD网口)
{
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))
PLC.IP = plcBase.IP;
PLC.PLCType = plcBase.PLCType;
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)
{
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;
public void InitModel()
@ -1122,7 +1130,7 @@ namespace DHSoftware
//EmergencyStop(null, null, null);
}
Thread.Sleep(50); // 降低 CPU 占用,根据实际调整轮询间隔
Thread.Sleep(50);
}
catch (Exception ex)
{
@ -1264,13 +1272,58 @@ namespace DHSoftware
private void HandleStartButton()
{
InitialCameraSumsView();
LogAsync(DateTime.Now, LogLevel.Information, "流程启动中,请稍候...");
ResetAllCameraCounts();
//开始流程
StartProcess();
LogAsync(DateTime.Now, LogLevel.Action, "流程启动完成!");
lock (_stopLock)
{
if (_isStopProcessing) return;
_isStopProcessing = true;
}
try
{
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
{
if (CurrentMachine)
{
return;
}
BatchNO = textBoxBatchNO.Text;
textBoxBatchNO.ReadOnly = true;
@ -1848,26 +1898,89 @@ namespace DHSoftware
}
private void HandleStopButton()
{
if (!CurrentMachine)
private readonly object _stopLock = new object(); // 锁对象
private bool _isStopProcessing = false; // 状态标志
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();
}
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()
{

View File

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