Bladeren bron

撤销写入速度更改

KWD 2 maanden geleden
bovenliggende
commit
ec1d759d2f
1 gewijzigde bestanden met toevoegingen van 150 en 150 verwijderingen
  1. 150 150
      TeamAAS-VM/Core/Management.cs

+ 150 - 150
TeamAAS-VM/Core/Management.cs

@@ -1387,7 +1387,7 @@ namespace TeamAAS_VP.Core
                 addressConfig.ManualMode.Address,
                 addressConfig.ClearMode.Address,
                 addressConfig.WorkCt.Address,
-                addressConfig.WorkSpeed.Address,
+                //addressConfig.WorkSpeed.Address,
             };
             for (int i = 0; i < 10; i++)
             {
@@ -1511,7 +1511,7 @@ namespace TeamAAS_VP.Core
         //List<Task<(bool IsSucceed, ICogImage[] Images, string Message, int cameraIndex, Guid procedureId)>> _ImageTaskList = new List<Task<(bool IsSucceed, ICogImage[] Images, string Message, int cameraIndex, Guid procedureId)>>();
 
         private readonly object _stateLock = new object();
-        private SharedSpeedFileHelper _speedFileHelper = new SharedSpeedFileHelper();
+       // private SharedSpeedFileHelper _speedFileHelper = new SharedSpeedFileHelper();
         /// <summary>
         /// PLC命令触发时S
         /// </summary>
@@ -2719,62 +2719,62 @@ namespace TeamAAS_VP.Core
                     }
                 }
                 //读取写入PLC速度
-                else if (addressConfig.WorkSpeed.Address.Contains(tuple.nodeId))
-                {
-                    if (tuple.value is Int16 state)
-                    {
-                        if (_Lastworkspeed != state)
-                        {
-                            _Lastworkspeed = state;
-                        }
-                        else
-                        {
-                            return;
-                        }
-                        if (state==1)
-                        {
-                            try
-                            {
-                                // 1. 从PLC读取速度
-                                string speed = plc.ReadNode<string>(string.Format(addressConfig.In_ReadSpeed.Address));
-                                SendTaskMessage($"读取PLC速度:{speed}", MessageLevel.Info);
-
-                                // 2. 写入共享文件
-                                _speedFileHelper.WriteSpeedData(speed, state);
-                                SendTaskMessage($"速度数据已写入共享文件", MessageLevel.Info);
-                            }
-                            catch (Exception ex)
-                            {
-                                SendTaskMessage($"读取PLC速度或写入文件失败: {ex.Message}", MessageLevel.Error);
-                            }
-                        }
-                        else if(state == 2)
-                        {
-                            try
-                            {
-                                // 1. 从共享文件读取速度数据
-                                var speedData = _speedFileHelper.ReadSpeedData();
-
-                                if (speedData != null && !string.IsNullOrEmpty(speedData.SpeedValue))
-                                {
-                                    // 2. 写入PLC
-                                    string address = string.Format(addressConfig.In_WriteSpeed.Address);
-                                    plc.WriteNode<string>(address, speedData.SpeedValue);
-
-                                    SendTaskMessage($"从文件读取速度:{speedData.SpeedValue}, 已写入PLC", MessageLevel.Info);
-                                }
-                                else
-                                {
-                                    SendTaskMessage("共享文件中没有有效的速度数据", MessageLevel.Alarm);
-                                }
-                            }
-                            catch (Exception ex)
-                            {
-                                SendTaskMessage($"读取文件或写入PLC失败: {ex.Message}", MessageLevel.Error);
-                            }
-                        }
-                    }
-                }
+                //else if (addressConfig.WorkSpeed.Address.Contains(tuple.nodeId))
+                //{
+                //    if (tuple.value is Int16 state)
+                //    {
+                //        if (_Lastworkspeed != state)
+                //        {
+                //            _Lastworkspeed = state;
+                //        }
+                //        else
+                //        {
+                //            return;
+                //        }
+                //        if (state==1)
+                //        {
+                //            try
+                //            {
+                //                // 1. 从PLC读取速度
+                //                string speed = plc.ReadNode<string>(string.Format(addressConfig.In_ReadSpeed.Address));
+                //                SendTaskMessage($"读取PLC速度:{speed}", MessageLevel.Info);
+
+                //                // 2. 写入共享文件
+                //                _speedFileHelper.WriteSpeedData(speed, state);
+                //                SendTaskMessage($"速度数据已写入共享文件", MessageLevel.Info);
+                //            }
+                //            catch (Exception ex)
+                //            {
+                //                SendTaskMessage($"读取PLC速度或写入文件失败: {ex.Message}", MessageLevel.Error);
+                //            }
+                //        }
+                //        else if(state == 2)
+                //        {
+                //            try
+                //            {
+                //                // 1. 从共享文件读取速度数据
+                //                var speedData = _speedFileHelper.ReadSpeedData();
+
+                //                if (speedData != null && !string.IsNullOrEmpty(speedData.SpeedValue))
+                //                {
+                //                    // 2. 写入PLC
+                //                    string address = string.Format(addressConfig.In_WriteSpeed.Address);
+                //                    plc.WriteNode<string>(address, speedData.SpeedValue);
+
+                //                    SendTaskMessage($"从文件读取速度:{speedData.SpeedValue}, 已写入PLC", MessageLevel.Info);
+                //                }
+                //                else
+                //                {
+                //                    SendTaskMessage("共享文件中没有有效的速度数据", MessageLevel.Alarm);
+                //                }
+                //            }
+                //            catch (Exception ex)
+                //            {
+                //                SendTaskMessage($"读取文件或写入PLC失败: {ex.Message}", MessageLevel.Error);
+                //            }
+                //        }
+                //    }
+                //}
                 // 过站检查
                 else
                 {
@@ -5831,99 +5831,99 @@ namespace TeamAAS_VP.Core
 
         #endregion
 
-        #region 读取写入plc速度
-
-        // 速度数据模型
-        [Serializable]
-        public class SpeedData
-        {
-            public string SpeedValue { get; set; }
-            public DateTime UpdateTime { get; set; }
-            public int State { get; set; }
-        }
-
-        public class SharedSpeedFileHelper
-        {
-            private static readonly object _lockObj = new object();
-            string directoryPath = @"Z:\\XTM\\Speed";
-            //public SharedSpeedFileHelper()
-            //{
-            //    try
-            //    {
-            //        string directoryPath = @"Z:\\1111\\2222\\3333";
-
-            //        // 确保目录存在
-            //        if (!Directory.Exists(directoryPath))
-            //            Directory.CreateDirectory(directoryPath);
-
-            //        _filePath = Path.Combine(directoryPath, "SharedSpeedData.json");
-            //    }
-            //    catch
-            //    {
-            //        LogHelper.WriteLogInfo("Z盘路径不存在");
-            //    }
-            //}
-
-            // 写入速度数据
-            public void WriteSpeedData(string speed, int state)
-            {
-                lock (_lockObj)
-                {
-                    try
-                    {
-                        var data = new SpeedData
-                        {
-                            SpeedValue = speed,
-                            UpdateTime = DateTime.Now,
-                            State = state
-                        };
-
-                        string json = JsonSerializer.Serialize(data, new JsonSerializerOptions
-                        {
-                            WriteIndented = true
-                        });
+        //#region 读取写入plc速度
+
+        //// 速度数据模型
+        //[Serializable]
+        //public class SpeedData
+        //{
+        //    public string SpeedValue { get; set; }
+        //    public DateTime UpdateTime { get; set; }
+        //    public int State { get; set; }
+        //}
+
+        //public class SharedSpeedFileHelper
+        //{
+        //    private static readonly object _lockObj = new object();
+        //    string directoryPath = @"Z:\\XTM\\Speed";
+        //    //public SharedSpeedFileHelper()
+        //    //{
+        //    //    try
+        //    //    {
+        //    //        string directoryPath = @"Z:\\1111\\2222\\3333";
+
+        //    //        // 确保目录存在
+        //    //        if (!Directory.Exists(directoryPath))
+        //    //            Directory.CreateDirectory(directoryPath);
+
+        //    //        _filePath = Path.Combine(directoryPath, "SharedSpeedData.json");
+        //    //    }
+        //    //    catch
+        //    //    {
+        //    //        LogHelper.WriteLogInfo("Z盘路径不存在");
+        //    //    }
+        //    //}
+
+        //    // 写入速度数据
+        //    public void WriteSpeedData(string speed, int state)
+        //    {
+        //        lock (_lockObj)
+        //        {
+        //            try
+        //            {
+        //                var data = new SpeedData
+        //                {
+        //                    SpeedValue = speed,
+        //                    UpdateTime = DateTime.Now,
+        //                    State = state
+        //                };
+
+        //                string json = JsonSerializer.Serialize(data, new JsonSerializerOptions
+        //                {
+        //                    WriteIndented = true
+        //                });
                       
-                        // 确保目录存在
-                        if (!Directory.Exists(directoryPath))
-                            Directory.CreateDirectory(directoryPath);
-
-                       string _filePath = Path.Combine(directoryPath, "SharedSpeedData.json");
-
-                        File.WriteAllText(_filePath, json, Encoding.UTF8);
-                    }
-                    catch (Exception ex)
-                    {
-                        throw new InvalidOperationException($"写入速度文件失败: {ex.Message}", ex);
-                    }
-                }
-            }
-
-            // 读取速度数据
-            public SpeedData ReadSpeedData()
-            {
-                lock (_lockObj)
-                {
-                    try
-                    {
-                        // 确保目录存在
-                        if (!Directory.Exists(directoryPath))
-                        {
-                            return null;
-                        }
-                        string _filePath = Path.Combine(directoryPath, "SharedSpeedData.json");
-
-                        string json = File.ReadAllText(_filePath, Encoding.UTF8);
-                        return JsonSerializer.Deserialize<SpeedData>(json);
-                    }
-                    catch (Exception ex)
-                    {
-                        throw new InvalidOperationException($"读取速度文件失败: {ex.Message}", ex);
-                    }
-                }
-            }
-        }
-
-        #endregion
+        //                // 确保目录存在
+        //                if (!Directory.Exists(directoryPath))
+        //                    Directory.CreateDirectory(directoryPath);
+
+        //               string _filePath = Path.Combine(directoryPath, "SharedSpeedData.json");
+
+        //                File.WriteAllText(_filePath, json, Encoding.UTF8);
+        //            }
+        //            catch (Exception ex)
+        //            {
+        //                throw new InvalidOperationException($"写入速度文件失败: {ex.Message}", ex);
+        //            }
+        //        }
+        //    }
+
+        //    // 读取速度数据
+        //    public SpeedData ReadSpeedData()
+        //    {
+        //        lock (_lockObj)
+        //        {
+        //            try
+        //            {
+        //                // 确保目录存在
+        //                if (!Directory.Exists(directoryPath))
+        //                {
+        //                    return null;
+        //                }
+        //                string _filePath = Path.Combine(directoryPath, "SharedSpeedData.json");
+
+        //                string json = File.ReadAllText(_filePath, Encoding.UTF8);
+        //                return JsonSerializer.Deserialize<SpeedData>(json);
+        //            }
+        //            catch (Exception ex)
+        //            {
+        //                throw new InvalidOperationException($"读取速度文件失败: {ex.Message}", ex);
+        //            }
+        //        }
+        //    }
+        //}
+
+        //#endregion
 
     }
 }