提交设备状态

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

@ -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()
{