This commit is contained in:
2025-10-20 14:47:17 +08:00
parent 2e46747ba9
commit 546b894e6b
16 changed files with 917 additions and 141 deletions

View File

@@ -19,6 +19,8 @@ namespace Check.Main
public partial class FrmMain : Form
{
// private FrmCamConfig _formCameraConfig;
public static EasyPlcClient PlcClient;//定义全局PLC对象 --- 10.10添加①
private FrmConfig _frmConfig;
private FrmLog _formLog;
private ThemeBase _theme = new VS2015BlueTheme(); // 外观主题
@@ -40,11 +42,28 @@ namespace Check.Main
_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
}
private void FrmMain_Load(object sender, EventArgs e)
//添加 PLC 初始化方法 --- 10.10添加②
private async Task InitPlcConnection()
{
try
{
PlcClient = new EasyPlcClient("192.168.1.88", 502);
await PlcClient.ConnectAsync();
ThreadSafeLogger.Log("[PLC] 已成功连接到汇川PLC");
}
catch (Exception ex)
{
ThreadSafeLogger.Log($"[PLC] 连接失败: {ex.Message}");
}
}
private async void FrmMain_Load(object sender, EventArgs e)//添加了一个async原来是private void FrmMain_Load-----10.10修改
{
// 初始化PLC连接-----10.10添加
await InitPlcConnection();
EasyPlcClient easyPlcClient = new EasyPlcClient("127.0.0.1", 502, 1);
easyPlcClient.ConnectAsync();
_frmConfig = new FrmConfig { Text = "主程序配置" };
_formLog = new FrmLog { Text = "运行日志" };
_formStatistics = new FormStatistics { Text = "生产统计" };