From c4a9162499895bf7284a1a467c7ec8798fa1382e Mon Sep 17 00:00:00 2001 From: "GukSang.Jin" Date: Tue, 6 Jan 2026 11:18:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WindowsFormsApp6/MainForm.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/WindowsFormsApp6/MainForm.cs b/WindowsFormsApp6/MainForm.cs index 3fd2ff3..2f2a20c 100644 --- a/WindowsFormsApp6/MainForm.cs +++ b/WindowsFormsApp6/MainForm.cs @@ -253,7 +253,8 @@ namespace WindowsFormsApp6 // 使用ReadCoils读取线圈状态(M区) bool signalM103 = ReadCoil(slaveId, 103); // Form1信号量 - bool signalM252 = ReadCoil(slaveId, 252); // Form2信号量 + bool signalM252 = ReadCoil(slaveId, 252); // Form2 数据采集信号量 + bool signalM253 = ReadCoil(slaveId, 253); // Form2 设备停止信号量 bool signalM310 = ReadCoil(slaveId, 310); // Form3信号量 // 根据信号量触发相应的数据读取 @@ -264,7 +265,9 @@ namespace WindowsFormsApp6 WriteCoil(slaveId, 103, false); } - if (signalM252) + // Form2数据读取:只有M252为true且M253为false时才读取数据 + // M253为true表示设备停止,防止误触发 + if (signalM252 && !signalM253) { ReadForm2Data(slaveId); // 读取完成后清除信号量