提交
This commit is contained in:
@ -10,6 +10,7 @@
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<ApplicationIcon>assets\favicon.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@ -22,6 +23,7 @@
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="assets\favicon.ico" />
|
||||
<Content Include="db\config.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
3
DHSoftware/LoginWindow.Designer.cs
generated
3
DHSoftware/LoginWindow.Designer.cs
generated
@ -53,6 +53,7 @@
|
||||
iptName.PlaceholderText = "请输入用户名";
|
||||
iptName.Size = new Size(227, 37);
|
||||
iptName.TabIndex = 1;
|
||||
iptName.Text = "user";
|
||||
//
|
||||
// iptPwd
|
||||
//
|
||||
@ -62,6 +63,7 @@
|
||||
iptPwd.PlaceholderText = "请输入密码";
|
||||
iptPwd.Size = new Size(227, 37);
|
||||
iptPwd.TabIndex = 2;
|
||||
iptPwd.Text = "123";
|
||||
iptPwd.UseSystemPasswordChar = true;
|
||||
//
|
||||
// button_cancel
|
||||
@ -101,7 +103,6 @@
|
||||
Name = "LoginWindow";
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Text = "登录界面";
|
||||
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -632,49 +632,7 @@ namespace DHSoftware
|
||||
segmented1.Items.Remove(itemToHide);
|
||||
}
|
||||
|
||||
public void LoadScheme()
|
||||
{
|
||||
try
|
||||
{
|
||||
//方案配置初始化
|
||||
SchemeHelper.Initialize();
|
||||
//读取方案列表
|
||||
List<string> list = SchemeHelper.GetAllSchemes();
|
||||
string CurrentScheme = "默认方案";
|
||||
//如果是空,新增默认数据
|
||||
if (list == null || list.Count <= 0)
|
||||
{
|
||||
list = new() { CurrentScheme };
|
||||
//显示到方案列表
|
||||
sltProjects.Items.Clear();
|
||||
|
||||
sltProjects.Items.Add(CurrentScheme);
|
||||
//保存到方案配置
|
||||
SchemeHelper.AddScheme(CurrentScheme);
|
||||
SchemeHelper.SetCurrentScheme(CurrentScheme);
|
||||
//新构建配置文件
|
||||
ConfigHelper.InitializeScheme(CurrentScheme);
|
||||
|
||||
sltProjects.SelectedIndex = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (string s in list)
|
||||
{
|
||||
sltProjects.Items.Add(s);
|
||||
}
|
||||
CurrentScheme = SchemeHelper.GetCurrentScheme();
|
||||
sltProjects.SelectedValue = CurrentScheme;
|
||||
}
|
||||
SystemModel.CurrentScheme = CurrentScheme;
|
||||
//加载当前方案配置
|
||||
ConfigHelper.LoadConfig();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AntdUI.Message.error(this, ex.Message, autoClose: 3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void ConnectCamera()
|
||||
{
|
||||
@ -973,7 +931,36 @@ namespace DHSoftware
|
||||
lblUPH.Text = UPM.ToString();
|
||||
}));
|
||||
}
|
||||
public void LoadScheme()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 初始化方案配置(会自动创建默认方案)
|
||||
SchemeHelper.Initialize();
|
||||
|
||||
// 读取方案列表
|
||||
var schemes = SchemeHelper.GetAllSchemes();
|
||||
sltProjects.Items.Clear();
|
||||
|
||||
// 绑定方案到下拉列表
|
||||
foreach (var scheme in schemes)
|
||||
{
|
||||
sltProjects.Items.Add(scheme);
|
||||
}
|
||||
|
||||
// 设置当前选中的方案
|
||||
string currentScheme = SchemeHelper.GetCurrentScheme();
|
||||
sltProjects.SelectedValue = currentScheme;
|
||||
SystemModel.CurrentScheme = currentScheme;
|
||||
|
||||
// 加载当前方案配置
|
||||
ConfigHelper.LoadConfig();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AntdUI.Message.error(this, ex.Message, autoClose: 3);
|
||||
}
|
||||
}
|
||||
private void BtnDeleteProject_Click(object? sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
@ -983,29 +970,21 @@ namespace DHSoftware
|
||||
var result = AntdUI.Modal.open(this, "删除警告!", "确认要删除该方案吗?", TType.Warn);
|
||||
if (result == DialogResult.OK)
|
||||
{
|
||||
string schemeToDelete = sltProjects.Text;
|
||||
int selectedIndex = sltProjects.SelectedIndex;
|
||||
|
||||
// 删除当前选中项
|
||||
SchemeHelper.DeleteScheme(sltProjects.Text);
|
||||
ConfigHelper.DeleteSchemeConfig(sltProjects.Text);
|
||||
AntdUI.Message.success(this, $"删除方案{sltProjects.Text}成功!", autoClose: 3);
|
||||
sltProjects.Items.RemoveAt(selectedIndex);
|
||||
// 自动选择下一个(如果存在)
|
||||
if (sltProjects.Items.Count > 0)
|
||||
{
|
||||
// 如果删除的不是最后一项,则选中原位置的新项,否则选中最后一项
|
||||
sltProjects.SelectedIndex = selectedIndex < sltProjects.Items.Count
|
||||
? selectedIndex
|
||||
: sltProjects.Items.Count - 1;
|
||||
// 删除方案(SchemeHelper会自动处理当前方案的切换)
|
||||
SchemeHelper.DeleteScheme(schemeToDelete);
|
||||
ConfigHelper.DeleteSchemeConfig(schemeToDelete);
|
||||
|
||||
SystemModel.CurrentScheme = sltProjects.Text;
|
||||
SchemeHelper.SetCurrentScheme(SystemModel.CurrentScheme);
|
||||
//加载当前方案配置
|
||||
ConfigHelper.LoadConfig();
|
||||
}
|
||||
else
|
||||
// 刷新UI
|
||||
LoadScheme();
|
||||
|
||||
AntdUI.Message.success(this, $"删除方案{schemeToDelete}成功!", autoClose: 3);
|
||||
|
||||
// 如果没有方案了,提示用户
|
||||
if (sltProjects.Items.Count == 0)
|
||||
{
|
||||
sltProjects.SelectedIndex = -1; // 清空选择
|
||||
AntdUI.Modal.open(this, "空方案警告!", "当前方案全部删除,需重启程序!", TType.Warn);
|
||||
}
|
||||
}
|
||||
@ -1021,18 +1000,23 @@ namespace DHSoftware
|
||||
try
|
||||
{
|
||||
if (sltProjects.Items.Count == 0 || sltProjects.SelectedIndex == -1) return;
|
||||
if (SystemModel.CurrentScheme == sltProjects.Text)
|
||||
|
||||
string selectedScheme = sltProjects.Text;
|
||||
|
||||
if (SystemModel.CurrentScheme == selectedScheme)
|
||||
{
|
||||
AntdUI.Message.warn(this, "当前已是该方案,无需重复载入!", autoClose: 3);
|
||||
return;
|
||||
}
|
||||
//修改当前软件当前方案
|
||||
SystemModel.CurrentScheme = sltProjects.Text;
|
||||
//修改配置当前方案
|
||||
SchemeHelper.SetCurrentScheme(SystemModel.CurrentScheme);
|
||||
//将配置文件替换为当前方案
|
||||
|
||||
// 设置当前方案
|
||||
SchemeHelper.SetCurrentScheme(selectedScheme);
|
||||
SystemModel.CurrentScheme = selectedScheme;
|
||||
|
||||
// 加载配置
|
||||
ConfigHelper.LoadConfig();
|
||||
AntdUI.Message.success(this, $"载入方案{SystemModel.CurrentScheme}成功!", autoClose: 3);
|
||||
|
||||
AntdUI.Message.success(this, $"载入方案{selectedScheme}成功!", autoClose: 3);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -1049,31 +1033,27 @@ namespace DHSoftware
|
||||
{
|
||||
BtnHeight = 0,
|
||||
});
|
||||
|
||||
if (form.submit)
|
||||
{
|
||||
string SchemeName = form.SchemeName;
|
||||
//保存到方案配置
|
||||
SchemeHelper.AddScheme(SchemeName);
|
||||
string schemeName = form.SchemeName;
|
||||
|
||||
// 保存到方案配置
|
||||
SchemeHelper.AddScheme(schemeName);
|
||||
|
||||
// 根据选择初始化配置
|
||||
if (form.NullScheme)
|
||||
{
|
||||
//新构建配置文件
|
||||
ConfigHelper.InitializeScheme(SchemeName);
|
||||
ConfigHelper.InitializeScheme(schemeName);
|
||||
}
|
||||
else
|
||||
{
|
||||
//派生当前方案
|
||||
ConfigHelper.DeriveScheme(SchemeName);
|
||||
ConfigHelper.DeriveScheme(schemeName);
|
||||
}
|
||||
//刷新方案列表
|
||||
sltProjects.Items.Clear();
|
||||
List<string> list = SchemeHelper.GetAllSchemes();
|
||||
foreach (string s in list)
|
||||
{
|
||||
sltProjects.Items.Add(s);
|
||||
}
|
||||
string CurrentScheme = SchemeHelper.GetCurrentScheme();
|
||||
sltProjects.SelectedValue = CurrentScheme;
|
||||
AntdUI.Message.success(this, $"新增方案{SchemeName}成功!", autoClose: 3);
|
||||
|
||||
// 刷新UI
|
||||
LoadScheme();
|
||||
AntdUI.Message.success(this, $"新增方案{schemeName}成功!", autoClose: 3);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -1087,11 +1067,84 @@ namespace DHSoftware
|
||||
public Dictionary<string, SimboObjectDetection> Dectection { get; } = new Dictionary<string, SimboObjectDetection>();
|
||||
public XinJEPLCTcpNet PLC { get; } = XinJEPLCTcpNet.Instance;
|
||||
private SLDMotion sLDMotion = new SLDMotion();
|
||||
|
||||
// 线程控制标志
|
||||
private volatile bool _isRunning = false;
|
||||
private Thread _monitorThread;
|
||||
private void MainWindow_Load(object sender, EventArgs e)
|
||||
{
|
||||
//开启按钮监听
|
||||
// 启动所有监控线程
|
||||
StartAllMonitors();
|
||||
}
|
||||
|
||||
private void StartAllMonitors()
|
||||
{
|
||||
if (PLC.Connected)
|
||||
{
|
||||
if (_monitorThread == null || !_monitorThread.IsAlive)
|
||||
{
|
||||
_isRunning = true;
|
||||
_monitorThread = new Thread(MonitorPlcButtons);
|
||||
_monitorThread.IsBackground = true; // 后台线程
|
||||
_monitorThread.Start();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void MonitorPlcButtons(object? obj)
|
||||
{
|
||||
while (_isRunning)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 读取 PLC 输入点状态
|
||||
bool startPressed = PLC.ReadBool("X3");
|
||||
bool resetPressed = PLC.ReadBool("X4");
|
||||
bool stopPressed = PLC.ReadBool("X5");
|
||||
bool eStopPressed = PLC.ReadBool("X6");
|
||||
|
||||
// 处理按钮状态变化
|
||||
if (startPressed)
|
||||
{
|
||||
PLC.TurnSpeed(0);
|
||||
PLC.TurnStart(false);
|
||||
HandleStartButton();
|
||||
}
|
||||
if (resetPressed)
|
||||
{
|
||||
//ResetProcess();
|
||||
}
|
||||
if (stopPressed)
|
||||
{
|
||||
HandleStopButton();
|
||||
}
|
||||
if (eStopPressed)
|
||||
{
|
||||
//EmergencyStop(null, null, null);
|
||||
}
|
||||
|
||||
Thread.Sleep(50); // 降低 CPU 占用,根据实际调整轮询间隔
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_isRunning = false;
|
||||
// 记录错误并停止线程
|
||||
// throw new ProcessException($"按钮监听线程:{ex.Message}");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 停止监听线程
|
||||
private void StopMonitoring()
|
||||
{
|
||||
_isRunning = false;
|
||||
if (_monitorThread != null && _monitorThread.IsAlive)
|
||||
{
|
||||
_monitorThread.Join(1000); // 等待线程退出
|
||||
}
|
||||
}
|
||||
private bool _isClosing = false; // 状态标志
|
||||
|
||||
private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
|
||||
@ -1122,6 +1175,7 @@ namespace DHSoftware
|
||||
{
|
||||
PLC.CloseProcess();
|
||||
}
|
||||
StopMonitoring();
|
||||
_visionEngine.Stop();//释放模型
|
||||
CloseWindow.Instance.Close();// 关闭提示窗口
|
||||
//Application.Exit();
|
||||
@ -1221,11 +1275,14 @@ namespace DHSoftware
|
||||
|
||||
|
||||
|
||||
private void StartProcess()
|
||||
private async void StartProcess()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
if (CurrentMachine)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BatchNO = textBoxBatchNO.Text;
|
||||
textBoxBatchNO.ReadOnly = true;
|
||||
@ -1314,20 +1371,41 @@ namespace DHSoftware
|
||||
//mOfflineImageTimer.Start();
|
||||
|
||||
#endregion 虚拟相机
|
||||
//流程执行时PLC
|
||||
PLC.StartProcess();
|
||||
LogAsync(DateTime.Now, LogLevel.Action, "流程启动11111111111完成!");
|
||||
///这里会执行完成后,会造成后台线程断断续续,会造成界面UI卡顿
|
||||
//var settings = ConfigModel.DetectionList.Where(u => u.IsEnabled && u.IsAddStation).ToList();
|
||||
//if (settings != null)
|
||||
//{
|
||||
// settings = settings.Where(s => s.IsEnabled).ToList();
|
||||
// ProductBaseCount = settings.Count;
|
||||
|
||||
var settings = _visionEngine.DetectionConfigs.Where(u => u.IsEnabled && u.IsAddStation).ToList();
|
||||
if (settings != null)
|
||||
// for (int i = 0; i < ProductBaseCount * ProductListMulti; i++)
|
||||
// {
|
||||
// ConcurrentDictionary<uint, ProductData> products = new ConcurrentDictionary<uint, ProductData>();
|
||||
// _productLists.Add(products);
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
await Task.Run(() =>
|
||||
{
|
||||
settings = settings.Where(s => s.IsEnabled).ToList();
|
||||
ProductBaseCount = settings.Count;
|
||||
|
||||
for (int i = 0; i < ProductBaseCount * ProductListMulti; i++)
|
||||
var settings = ConfigModel.DetectionList.Where(u => u.IsEnabled && u.IsAddStation).ToList();
|
||||
if (settings != null)
|
||||
{
|
||||
ConcurrentDictionary<uint, ProductData> products = new ConcurrentDictionary<uint, ProductData>();
|
||||
_productLists.Add(products);
|
||||
}
|
||||
}
|
||||
ProductBaseCount = settings.Count;
|
||||
_productLists.Clear(); // 清空旧数据
|
||||
|
||||
// 预分配列表容量(减少动态扩容开销)
|
||||
_productLists.Capacity = ProductBaseCount * ProductListMulti;
|
||||
|
||||
for (int i = 0; i < ProductBaseCount * ProductListMulti; i++)
|
||||
{
|
||||
_productLists.Add(new ConcurrentDictionary<uint, ProductData>());
|
||||
}
|
||||
}
|
||||
});
|
||||
// _MGSCameraList = DeviceCollection
|
||||
//.OfType<MGSCameraDriver>() // 直接筛选出 MGSCameraDriver 类型的元素
|
||||
//.Where(camera => camera.IConfig != null && camera.IConfig.IsEnabled) // 进一步筛选 IConfig 不为 null 且 IsEnabled 为 true
|
||||
@ -1337,9 +1415,10 @@ namespace DHSoftware
|
||||
|
||||
|
||||
|
||||
//流程执行时PLC
|
||||
PLC.StartProcess();
|
||||
|
||||
InitialOEEStatistic();
|
||||
|
||||
CurrentMachine = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -1771,14 +1850,19 @@ namespace DHSoftware
|
||||
|
||||
private void HandleStopButton()
|
||||
{
|
||||
if (!CurrentMachine)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
textBoxBatchNO.ReadOnly = false;
|
||||
btnCreateBatchNO.Enabled = true;
|
||||
|
||||
// Cameras.Clear();
|
||||
// Dectection.Clear();
|
||||
// Add the code for the "停止" button click here
|
||||
PLC.TurnStart(false);
|
||||
CurrentMachine = true;
|
||||
PLC.StopProcess();
|
||||
CurrentMachine = false;
|
||||
//sLDMotion.Stop();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user