using CCDCount.DLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace CCDCountWpf
{
    public class PlcMessageShowBindingClass : INotifyPropertyChanged
    {
        /// <summary>
        /// 使能完成
        /// </summary>
        private bool enableCompletion;
        public bool EnableCompletion
        {
            get { return enableCompletion; }
            set
            {
                enableCompletion = value;
                OnPropertyChanged("EnableCompletion");
            }
        }

        /// <summary>
        /// 速度运行
        /// </summary>
        private bool speedRunning;
        public bool SpeedRunning
        {
            get { return speedRunning; }
            set
            {
                speedRunning = value;
                OnPropertyChanged("SpeedRunning");
            }
        }

        /// <summary>
        /// 允许数据交换
        /// </summary>
        private bool allowsDataExchange;
        public bool AllowsDataExchange
        {
            get { return allowsDataExchange; }
            set
            {
                allowsDataExchange = value;
                OnPropertyChanged("AllowsDataExchange");
            }
        }

        /// <summary>
        /// 暂停数据交换
        /// </summary>
        private bool pauseDataExchange;
        public bool PauseDataExchange
        {
            get { return pauseDataExchange; }
            set
            {
                pauseDataExchange = value;
                OnPropertyChanged("PauseDataExchange");
            }
        }

        /// <summary>
        /// 缓存计数延迟完成
        /// </summary>
        private bool cacheCountDelayed;
        public bool CacheCountDelayed
        {
            get { return cacheCountDelayed; }
            set
            {
                cacheCountDelayed = value;
                OnPropertyChanged("CacheCountDelayed");
            }
        }

        /// <summary>
        /// 使能
        /// </summary>
        private bool enable;
        public bool Enable
        {
            get { return enable; }
            set
            {
                enable = value;
                OnPropertyChanged("Enable");
            }
        }

        /// <summary>
        /// 罐装模式
        /// </summary>
        private ushort fillingModel;
        public ushort FillingModel
        {
            get { return fillingModel; }
            set
            {
                ushort oldValue = fillingModel;
                if (PlcSettingMessageBus.pLCManagement.WriteFillingMode(value))
                {
                    fillingModel = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"罐装模式从{oldValue}修改为{value}");
                }
                OnPropertyChanged("FillingModel");
            }
        }

        /// <summary>
        /// 传送带速度
        /// </summary>
        private ushort beltsSpeed;
        public ushort BeltsSpeed
        {
            get { return beltsSpeed; }
            set
            {
                ushort oldValue = beltsSpeed;
                if (PlcSettingMessageBus.pLCManagement.WriteBeltsSpeed(value))
                {
                    beltsSpeed = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"传送带速度从{oldValue}修改为{value}");
                }
                OnPropertyChanged("BeltsSpeed");
            }
        }

        /// <summary>
        /// 罐装料筒震台高速值
        /// </summary>
        private ushort shakeTable1H_FillingSpeed;
        public ushort ShakeTable1H_FillingSpeed
        {
            get { return shakeTable1H_FillingSpeed; }
            set
            {
                ushort oldValue = shakeTable1H_FillingSpeed;
                if (PlcSettingMessageBus.pLCManagement.WriteShakeTable1H_FillingSpeed(value))
                {
                    shakeTable1H_FillingSpeed = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"罐装料筒震台高速值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("ShakeTable1H_FillingSpeed");
            }
        }

        /// <summary>
        /// 罐装过滤震台高速值
        /// </summary>
        private ushort shakeTable2H_FillingSpeed;
        public ushort ShakeTable2H_FillingSpeed
        {
            get { return shakeTable2H_FillingSpeed; }
            set
            {
                ushort oldValue = shakeTable2H_FillingSpeed;
                if (PlcSettingMessageBus.pLCManagement.WriteShakeTable2H_FillingSpeed(value))
                {
                    shakeTable2H_FillingSpeed = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"罐装过滤震台高速值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("ShakeTable2H_FillingSpeed");
            }
        }

        /// <summary>
        /// 罐装计数震台高速值
        /// </summary>
        private ushort shakeTable3H_FillingSpeed;
        public ushort ShakeTable3H_FillingSpeed
        {
            get { return shakeTable3H_FillingSpeed; }
            set
            {
                ushort oldValue = shakeTable3H_FillingSpeed;
                if(PlcSettingMessageBus.pLCManagement.WriteShakeTable3H_FillingSpeed(value))
                {
                    shakeTable3H_FillingSpeed = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"罐装计数震台高速值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("ShakeTable3H_FillingSpeed");
            }
        }

        /// <summary>
        /// 罐装料筒震台减速值
        /// </summary>
        private ushort shakeTable1M_FillingSpeed;
        public ushort ShakeTable1M_FillingSpeed
        {
            get { return shakeTable1M_FillingSpeed; }
            set
            {
                ushort oldValue = shakeTable1M_FillingSpeed;
                if(PlcSettingMessageBus.pLCManagement.WriteShakeTable1M_FillingSpeed(value))
                {
                    shakeTable1M_FillingSpeed = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"罐装料筒震台减速值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("ShakeTable1M_FillingSpeed");
            }
        }

        /// <summary>
        /// 罐装过滤震台减速值
        /// </summary>
        private ushort shakeTable2M_FillingSpeed;
        public ushort ShakeTable2M_FillingSpeed
        {
            get { return shakeTable2M_FillingSpeed; }
            set
            {
                ushort oldValue = shakeTable2M_FillingSpeed;
                if(PlcSettingMessageBus.pLCManagement.WriteShakeTable2M_FillingSpeed(value))
                {
                    shakeTable2M_FillingSpeed = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"罐装过滤震台减速值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("ShakeTable2M_FillingSpeed");
            }
        }

        /// <summary>
        /// 罐装计数震台减速值
        /// </summary>
        private ushort shakeTable3M_FillingSpeed;
        public ushort ShakeTable3M_FillingSpeed
        {
            get { return shakeTable3M_FillingSpeed; }
            set
            {
                ushort oldValue = shakeTable3M_FillingSpeed;
                if(PlcSettingMessageBus.pLCManagement.WriteShakeTable3M_FillingSpeed(value))
                {
                    shakeTable3M_FillingSpeed = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"罐装计数震台减速值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("ShakeTable3M_FillingSpeed");
            }
        }

        /// <summary>
        /// 罐装料筒震台低速值
        /// </summary>
        private ushort shakeTable1L_FillingSpeed;
        public ushort ShakeTable1L_FillingSpeed
        {
            get { return shakeTable1L_FillingSpeed; }
            set
            {
                ushort oldValue = shakeTable1L_FillingSpeed;
                if (PlcSettingMessageBus.pLCManagement.WriteShakeTable1L_FillingSpeed(value))
                {
                    shakeTable1L_FillingSpeed = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"罐装料筒震台低速值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("ShakeTable1L_FillingSpeed");
            }
        }

        /// <summary>
        /// 罐装过滤震台低速值
        /// </summary>
        private ushort shakeTable2L_FillingSpeed;
        public ushort ShakeTable2L_FillingSpeed
        {
            get { return shakeTable2L_FillingSpeed; }
            set
            {
                ushort oldValue = shakeTable2L_FillingSpeed;
                if (PlcSettingMessageBus.pLCManagement.WriteShakeTable2L_FillingSpeed(value))
                {
                    shakeTable2L_FillingSpeed = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"罐装过滤震台低速值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("ShakeTable2L_FillingSpeed");
            }
        }

        /// <summary>
        /// 罐装计数震台减速值
        /// </summary>
        private ushort shakeTable3L_FillingSpeed;
        public ushort ShakeTable3L_FillingSpeed
        {
            get { return shakeTable3L_FillingSpeed; }
            set
            {
                ushort oldValue = shakeTable3L_FillingSpeed;
                if (PlcSettingMessageBus.pLCManagement.WriteShakeTable3L_FillingSpeed(value))
                {
                    shakeTable3L_FillingSpeed = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"罐装计数震台低速值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("ShakeTable3L_FillingSpeed");
            }
        }

        /// <summary>
        /// 缓存料筒震台高速值
        /// </summary>
        private ushort shakeTable1H_CacheSpeed;
        public ushort ShakeTable1H_CacheSpeed
        {
            get { return shakeTable1H_CacheSpeed; }
            set
            {
                ushort oldValue = shakeTable1H_CacheSpeed;
                if(PlcSettingMessageBus.pLCManagement.WriteShakeTable1H_CacheSpeed(value))
                {
                    shakeTable1H_CacheSpeed = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"缓存料筒震台高速值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("ShakeTable1H_CacheSpeed");
            }
        }

        /// <summary>
        /// 缓存过滤震台高速值
        /// </summary>
        private ushort shakeTable2H_CacheSpeed;
        public ushort ShakeTable2H_CacheSpeed
        {
            get { return shakeTable2H_CacheSpeed; }
            set
            {
                ushort oldValue = shakeTable2H_CacheSpeed;
                if(PlcSettingMessageBus.pLCManagement.WriteShakeTable2H_CacheSpeed(value))
                {
                    shakeTable2H_CacheSpeed = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"缓存过滤震台高速值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("ShakeTable2H_CacheSpeed");
            }
        }

        /// <summary>
        /// 缓存计数震台高速值
        /// </summary>
        private ushort shakeTable3H_CacheSpeed;
        public ushort ShakeTable3H_CacheSpeed
        {
            get { return shakeTable3H_CacheSpeed; }
            set
            {
                ushort oldValue = shakeTable3H_CacheSpeed;
                if(PlcSettingMessageBus.pLCManagement.WriteShakeTable3H_CacheSpeed(value))
                {
                    shakeTable3H_CacheSpeed = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"缓存计数震台高速值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("ShakeTable3H_CacheSpeed");
            }
        }

        /// <summary>
        /// 缓存料筒震台减速值
        /// </summary>
        private ushort shakeTable1M_CacheSpeed;
        public ushort ShakeTable1M_CacheSpeed
        {
            get { return shakeTable1M_CacheSpeed; }
            set
            {
                ushort oldValue = shakeTable1M_CacheSpeed;
                if(PlcSettingMessageBus.pLCManagement.WriteShakeTable1M_CacheSpeed(value))
                {
                    shakeTable1M_CacheSpeed = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"缓存料筒震台减速值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("ShakeTable1M_CacheSpeed");
            }
        }

        /// <summary>
        /// 缓存过滤震台减速值
        /// </summary>
        private ushort shakeTable2M_CacheSpeed;
        public ushort ShakeTable2M_CacheSpeed
        {
            get { return shakeTable2M_CacheSpeed; }
            set
            {
                ushort oldValue = shakeTable2M_CacheSpeed;
                if(PlcSettingMessageBus.pLCManagement.WriteShakeTable2M_CacheSpeed(value))
                {
                    shakeTable2M_CacheSpeed = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"缓存过滤震台减速值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("ShakeTable2M_CacheSpeed");
            }
        }

        /// <summary>
        /// 缓存计数震台减速值
        /// </summary>
        private ushort shakeTable3M_CacheSpeed;
        public ushort ShakeTable3M_CacheSpeed
        {
            get { return shakeTable3M_CacheSpeed; }
            set
            {
                ushort oldValue = shakeTable3M_CacheSpeed;
                if(PlcSettingMessageBus.pLCManagement.WriteShakeTable3M_CacheSpeed(value))
                {
                    shakeTable3M_CacheSpeed = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"缓存计数震台减速值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("ShakeTable3M_CacheSpeed");
            }
        }

        /// <summary>
        /// 缓存料筒震台减速值
        /// </summary>
        private ushort shakeTable1L_CacheSpeed;
        public ushort ShakeTable1L_CacheSpeed
        {
            get { return shakeTable1L_CacheSpeed; }
            set
            {
                ushort oldValue = shakeTable1L_CacheSpeed;
                if (PlcSettingMessageBus.pLCManagement.WriteShakeTable1L_CacheSpeed(value))
                {
                    shakeTable1L_CacheSpeed = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"缓存料筒震台低速值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("ShakeTable1L_CacheSpeed");
            }
        }

        /// <summary>
        /// 缓存过滤震台减速值
        /// </summary>
        private ushort shakeTable2L_CacheSpeed;
        public ushort ShakeTable2L_CacheSpeed
        {
            get { return shakeTable2L_CacheSpeed; }
            set
            {
                ushort oldValue = shakeTable2L_CacheSpeed;
                if (PlcSettingMessageBus.pLCManagement.WriteShakeTable2L_CacheSpeed(value))
                {
                    shakeTable2L_CacheSpeed = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"缓存过滤震台低速值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("ShakeTable2L_CacheSpeed");
            }
        }

        /// <summary>
        /// 缓存计数震台低速值
        /// </summary>
        private ushort shakeTable3L_CacheSpeed;
        public ushort ShakeTable3L_CacheSpeed
        {
            get { return shakeTable3L_CacheSpeed; }
            set
            {
                ushort oldValue = shakeTable3L_CacheSpeed;
                if (PlcSettingMessageBus.pLCManagement.WriteShakeTable3L_CacheSpeed(value))
                {
                    shakeTable3L_CacheSpeed = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"缓存计数震台低速值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("ShakeTable3L_CacheSpeed");
            }
        }


        /// <summary>
        /// 罐装高速区间
        /// </summary>
        private ushort fillingH_SpeedRatio;
        public ushort FillingH_SpeedRatio
        {
            get { return fillingH_SpeedRatio; }
            set
            {
                ushort oldValue = fillingH_SpeedRatio;
                if (PlcSettingMessageBus.pLCManagement.WriteFillingH_SpeedRatio(value))
                {
                    fillingH_SpeedRatio = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"罐装高速区间值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("FillingH_SpeedRatio");
            }
        }

        /// <summary>
        /// 罐装减速区间
        /// </summary>
        private ushort fillingM_SpeedRatio;
        public ushort FillingM_SpeedRatio
        {
            get { return fillingM_SpeedRatio; }
            set
            {
                ushort oldValue = fillingM_SpeedRatio;
                if (PlcSettingMessageBus.pLCManagement.WriteFillingM_SpeedRatio(value))
                {
                    fillingM_SpeedRatio = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"罐装减速区间值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("FillingM_SpeedRatio");
            }
        }

        /// <summary>
        /// 罐装低速区间
        /// </summary>
        private ushort fillingL_SpeedRatio;
        public ushort FillingL_SpeedRatio
        {
            get { return fillingL_SpeedRatio; }
            set
            {
                ushort oldValue = fillingL_SpeedRatio;
                if (PlcSettingMessageBus.pLCManagement.WriteFillingL_SpeedRatio(value))
                {
                    fillingL_SpeedRatio = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"罐装低速区间值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("FillingL_SpeedRatio");
            }
        }

        /// <summary>
        /// 缓存高速区间
        /// </summary>
        private ushort cacheH_SpeedRatio;
        public ushort CacheH_SpeedRatio
        {
            get { return cacheH_SpeedRatio; }
            set
            {
                ushort oldValue = cacheH_SpeedRatio;
                if (PlcSettingMessageBus.pLCManagement.WriteCacheH_SpeedRatio(value))
                {
                    cacheH_SpeedRatio = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"缓存高速区间值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("CacheH_SpeedRatio");
            }
        }

        /// <summary>
        /// 缓存减速区间
        /// </summary>
        private ushort cacheM_SpeedRatio;
        public ushort CacheM_SpeedRatio
        {
            get { return cacheM_SpeedRatio; }
            set
            {
                ushort oldValue = cacheM_SpeedRatio;
                if (PlcSettingMessageBus.pLCManagement.WriteCacheM_SpeedRatio(value))
                {
                    cacheM_SpeedRatio = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"缓存减速区间值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("CacheM_SpeedRatio");
            }
        }

        /// <summary>
        /// 缓存低速区间
        /// </summary>
        private ushort cacheL_SpeedRatio;
        public ushort CacheL_SpeedRatio
        {
            get { return cacheL_SpeedRatio; }
            set
            {
                ushort oldValue = cacheL_SpeedRatio;
                if (PlcSettingMessageBus.pLCManagement.WriteCacheL_SpeedRatio(value))
                {
                    cacheL_SpeedRatio = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"缓存低速区间值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("CacheL_SpeedRatio");
            }
        }

        /// <summary>
        /// 传动轴点动速度
        /// </summary>
        private double screwJogSpeed;
        public string ScrewJogSpeed
        {
            get { return screwJogSpeed.ToString("F2"); }
            set
            {
                if (float.TryParse(value, out float result))
                {
                    double oldValue = screwJogSpeed;
                    if (PlcSettingMessageBus.pLCManagement.WriteScrewJogSpeed(result))
                    {
                        screwJogSpeed = result;
                        if (oldValue != result)
                            FaultLog.RecordValueChangeMessage($"传动轴点动速度从{oldValue}修改为{result}");
                    }
                    OnPropertyChanged("ScrewJogSpeed");
                }
            }
        }

        /// <summary>
        /// 进瓶速度
        /// </summary>
        private double inBottleSpeed;
        public string InBottleSpeed
        {
            get { return inBottleSpeed.ToString("F2"); }
            set
            {
                if (float.TryParse(value, out float result))
                {
                    double oldValue = inBottleSpeed;
                    if (PlcSettingMessageBus.pLCManagement.WriteInBottleSpeed(result))
                    {
                        inBottleSpeed = result;
                        if (oldValue != result)
                            FaultLog.RecordValueChangeMessage($"传动轴点动速度从{oldValue}修改为{result}");
                    }
                    OnPropertyChanged("InBottleSpeed");
                }
            }
        }

        /// <summary>
        /// 传动轴绝对定位速度
        /// </summary>
        private double bottlePosSpeed;
        public string BottlePosSpeed
        {
            get { return bottlePosSpeed.ToString("F2"); }
            set
            {
                if (float.TryParse(value, out float result))
                {
                    double oldValue = bottlePosSpeed;
                    if (PlcSettingMessageBus.pLCManagement.WriteBottlePosSpeed(result))
                    {
                        bottlePosSpeed = result;
                        if (oldValue != result)
                            FaultLog.RecordValueChangeMessage($"传动轴绝对定位速度从{oldValue}修改为{result}");
                    }
                    OnPropertyChanged("BottlePosSpeed");
                }
            }
        }

        /// <summary>
        /// 传动轴绝对定位位置
        /// </summary>
        private double bottlePosPosition;
        public string BottlePosPosition
        {
            get { return bottlePosPosition.ToString("F2"); }
            set
            {
                if (float.TryParse(value, out float result))
                {
                    double oldValue = bottlePosPosition;
                    if (PlcSettingMessageBus.pLCManagement.WriteBottlePosPosition(result))
                    {
                        bottlePosPosition = result;
                        if (oldValue != result)
                            FaultLog.RecordValueChangeMessage($"传动轴绝对定位位置从{oldValue}修改为{result}");
                    }
                    OnPropertyChanged("BottlePosPosition");
                }
            }
        }


        /// <summary>
        /// 中转阀打开速度
        /// </summary>
        private float fillingValveOpenSpeed;
        public string FillingValveOpenSpeed
        {
            get { return fillingValveOpenSpeed.ToString("F2"); }
            set
            {
                if (float.TryParse(value, out float result))
                {
                    float oldValue = fillingValveOpenSpeed;
                    if (PlcSettingMessageBus.pLCManagement.WriteFillingValveOpenSpeed(result))
                    {
                        fillingValveOpenSpeed = result;
                        if (oldValue != result)
                            FaultLog.RecordValueChangeMessage($"中转阀打开速度从{oldValue}修改为{result}");
                    }
                    OnPropertyChanged("FillingValveOpenSpeed");
                }
            }
        }

        /// <summary>
        /// 中转阀打开位置
        /// </summary>
        private float fillingValveOpenPosition;
        public string FillingValveOpenPosition
        {
            get { return fillingValveOpenPosition.ToString("F2"); }
            set
            {
                if (float.TryParse(value, out float result))
                {
                    float oldValue = fillingValveOpenPosition;
                    if (PlcSettingMessageBus.pLCManagement.WriteFillingValveOpenPosition(result))
                    {
                        fillingValveOpenPosition = result;
                        if (oldValue != result)
                            FaultLog.RecordValueChangeMessage($"中转阀打开速度从{oldValue}修改为{result}");
                    }
                    OnPropertyChanged("FillingValveOpenPosition");
                }
            }
        }

        /// <summary>
        /// 中转阀关闭速度
        /// </summary>
        private double fillingValveCloseSpeed;
        public string FillingValveCloseSpeed
        {
            get { return fillingValveCloseSpeed.ToString("F2"); }
            set
            {
                if (float.TryParse(value, out float result))
                {
                    double oldValue = fillingValveCloseSpeed;
                    if(PlcSettingMessageBus.pLCManagement.WriteFillingValveCloseSpeed(result))
                    {
                        fillingValveCloseSpeed = result;
                        if (oldValue != result)
                            FaultLog.RecordValueChangeMessage($"中转阀关闭速度从{oldValue}修改为{result}");
                    }
                    OnPropertyChanged("FillingValveCloseSpeed");
                }
            }
        }

        /// <summary>
        /// 中转阀关位置
        /// </summary>
        private double fillingValveClosePosition;
        public string FillingValveClosePosition
        {
            get { return fillingValveClosePosition.ToString("F2"); }
            set
            {
                if (float.TryParse(value, out float result))
                {
                    double oldValue = fillingValveClosePosition;
                    if(PlcSettingMessageBus.pLCManagement.WriteFillingValveClosePosition(result))
                    {
                        fillingValveClosePosition = result;
                        if (oldValue != result)
                            FaultLog.RecordValueChangeMessage($"中转阀关位置从{oldValue}修改为{result}");
                    }
                    OnPropertyChanged("FillingValveClosePosition");
                }
            }
        }

        /// <summary>
        /// 中转阀缓存速度
        /// </summary>
        private double fillingValveCacheSpeed;
        public string FillingValveCacheSpeed
        {
            get { return fillingValveCacheSpeed.ToString("F2"); }
            set
            {
                if (float.TryParse(value, out float result))
                {
                    double oldValue = fillingValveCacheSpeed;
                    if (PlcSettingMessageBus.pLCManagement.WriteFillingValveCacheSpeed(result))
                    {
                        fillingValveCacheSpeed = result;
                        if (oldValue != result)
                            FaultLog.RecordValueChangeMessage($"中转阀缓存速度从{oldValue}修改为{result}");
                    }
                    OnPropertyChanged("FillingValveCacheSpeed");
                }
            }
        }

        /// <summary>
        /// 中转阀缓存位置
        /// </summary>
        private double fillingValveCachePosition;
        public string FillingValveCachePosition
        {
            get { return fillingValveCachePosition.ToString("F2"); }
            set
            {
                if (float.TryParse(value, out float result))
                {
                    double oldValue = fillingValveCachePosition;
                    if (PlcSettingMessageBus.pLCManagement.WriteFillingValveCachePosition(result))
                    {
                        fillingValveCachePosition = result;
                        if (oldValue != result)
                            FaultLog.RecordValueChangeMessage($"中转阀缓存位置从{oldValue}修改为{result}");
                    }
                    OnPropertyChanged("FillingValveCachePosition");
                }
            }
        }

        /// <summary>
        /// 中转阀缓存位置
        /// </summary>
        private double fillingValveJogSpeed;
        public string FillingValveJogSpeed
        {
            get { return fillingValveJogSpeed.ToString("F2"); }
            set
            {
                if (float.TryParse(value, out float result))
                {
                    double oldValue = fillingValveJogSpeed;
                    if (PlcSettingMessageBus.pLCManagement.WriteFillingValveJogSpeed(result))
                    {
                        fillingValveJogSpeed = result;
                        if (oldValue != result)
                            FaultLog.RecordValueChangeMessage($"中转阀点动速度从{oldValue}修改为{result}");
                    }
                    OnPropertyChanged("FillingValveJogSpeed");
                }
            }
        }
        /// <summary>
        /// 漏斗下降延时
        /// </summary>
        private ushort machineDelayFunneDownTime;
        public ushort MachineDelayFunneDownTime
        {
            get { return machineDelayFunneDownTime; }
            set
            {
                float oldValue = machineDelayFunneDownTime;
                if (PlcSettingMessageBus.pLCManagement.WriteMachineDelayFunneDownTime(value))
                {
                    machineDelayFunneDownTime = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"漏斗下降延时从{oldValue}修改为{value}");
                }
                OnPropertyChanged("MachineDelayFunneDownTime");
            }
        }

        /// <summary>
        /// 漏斗上升延时
        /// </summary>
        private ushort machineDelayFunneUpTime;
        public ushort MachineDelayFunneUpTime
        {
            get { return machineDelayFunneUpTime; }
            set
            {
                float oldValue = machineDelayFunneUpTime;
                if (PlcSettingMessageBus.pLCManagement.WriteMachineDelayFunneUpTime(value))
                {
                    machineDelayFunneUpTime = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"漏斗上升延时从{oldValue}修改为{value}");
                }
                OnPropertyChanged("MachineDelayFunneUpTime");
            }
        }

        /// <summary>
        /// 中转阀打开延时
        /// </summary>
        private ushort machineDelayFillingValveOpenTime;
        public ushort MachineDelayFillingValveOpenTime
        {
            get { return machineDelayFillingValveOpenTime; }
            set
            {
                float oldValue = machineDelayFillingValveOpenTime;
                if (PlcSettingMessageBus.pLCManagement.WriteMachineDelayFillingValveOpenTime(value))
                {
                    machineDelayFillingValveOpenTime = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"中转阀打开延时从{oldValue}修改为{value}");
                }
                OnPropertyChanged("MachineDelayFillingValveOpenTime");
            }
        }

        /// <summary>
        /// 中转阀打开延时
        /// </summary>
        private ushort machineDelayFillingValveCloseTime;
        public ushort MachineDelayFillingValveCloseTime
        {
            get { return machineDelayFillingValveCloseTime; }
            set
            {
                float oldValue = machineDelayFillingValveCloseTime;
                if (PlcSettingMessageBus.pLCManagement.WriteMachineDelayFillingValveCloseTime(value))
                {
                    machineDelayFillingValveCloseTime = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"中转阀关闭延时从{oldValue}修改为{value}");
                }
                OnPropertyChanged("MachineDelayFillingValveCloseTime");
            }
        }

        /// <summary>
        /// 进瓶延时
        /// </summary>
        private ushort machineDelayInBottleTime;
        public ushort MachineDelayInBottleTime
        {
            get { return machineDelayInBottleTime; }
            set
            {
                float oldValue = machineDelayInBottleTime;
                if (PlcSettingMessageBus.pLCManagement.WriteMachineDelayInBottleTime(value))
                {
                    machineDelayInBottleTime = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"进瓶延时从{oldValue}修改为{value}");
                }
                OnPropertyChanged("MachineDelayInBottleTime");
            }
        }

        /// <summary>
        /// 气阀开延时
        /// </summary>
        private ushort valveDelytime;
        public ushort ValveDelytime
        {
            get { return valveDelytime; }
            set
            {
                ushort oldValue = valveDelytime;
                if (PlcSettingMessageBus.pLCManagement.WriteValveDelytime(value))
                {
                    valveDelytime = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"气阀开延时从{oldValue}修改为{value}");
                }
                OnPropertyChanged("ValveDelytime");
            }
        }

        /// <summary>
        /// 瓶装设定值
        /// </summary>
        private ushort bottValueSet;
        public ushort BottValueSet
        {
            get { return bottValueSet; }
            set
            {
                float oldValue = bottValueSet;
                if (PlcSettingMessageBus.pLCManagement.WriteBottValueSet(value))
                {
                    bottValueSet = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"瓶装设定值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("BottValueSet");
            }
        }

        /// <summary>
        /// 缓存停机值
        /// </summary>
        private ushort cacheShutdownValue;
        public ushort CacheShutdownValue
        {
            get { return cacheShutdownValue; }
            set
            {
                ushort oldValue = cacheShutdownValue;
                if (PlcSettingMessageBus.pLCManagement.WriteCacheShutdownValue(value))
                {
                    cacheShutdownValue = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"缓存停机值从{oldValue}修改为{value}");
                }
                OnPropertyChanged("CacheShutdownValue");
            }
        }

        /// <summary>
        /// 缺瓶检测时间
        /// </summary>
        private ushort missingDelaytime;
        public ushort MissingDelaytime
        {
            get { return missingDelaytime; }
            set
            {
                ushort oldValue = missingDelaytime;
                if (PlcSettingMessageBus.pLCManagement.WriteMissingDelaytime(value))
                {
                    missingDelaytime = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"缺瓶检测时间从{oldValue}修改为{value}");
                }
                OnPropertyChanged("MissingDelaytime");
            }
        }
        /// <summary>
        /// 堵瓶检测时间
        /// </summary>
        private ushort bottleJamDelaytime;
        public ushort BottleJamDelaytime
        {
            get { return bottleJamDelaytime; }
            set
            {
                ushort oldValue = bottleJamDelaytime;
                if (PlcSettingMessageBus.pLCManagement.WriteBottleJamDelaytime(value))
                {
                    bottleJamDelaytime = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"堵瓶检测时间从{oldValue}修改为{value}");
                }
                OnPropertyChanged("BottleJamDelaytime");
            }
        }

        /// <summary>
        /// 剔废气缸延时时间
        /// </summary>
        private ushort eliminateCylinderDelayTime;
        public ushort EliminateCylinderDelayTime
        {
            get { return eliminateCylinderDelayTime; }
            set
            {
                ushort oldValue = eliminateCylinderDelayTime;
                if (PlcSettingMessageBus.pLCManagement.WriteEliminateCylinderDelayTime(value))
                {
                    eliminateCylinderDelayTime = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"剔废气缸延时时间从{oldValue}修改为{value}");
                }
                OnPropertyChanged("EliminateCylinderDelayTime");
            }
        }

        /// <summary>
        /// 剔废气缸保持时间
        /// </summary>
        private ushort eliminateCylinderHoldingTime;
        public ushort EliminateCylinderHoldingTime
        {
            get { return eliminateCylinderHoldingTime; }
            set
            {
                ushort oldValue = eliminateCylinderHoldingTime;
                if (PlcSettingMessageBus.pLCManagement.WriteEliminateCylinderHoldingTime(value))
                {
                    eliminateCylinderHoldingTime = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"剔废气缸保持时间从{oldValue}修改为{value}");
                }
                OnPropertyChanged("EliminateCylinderHoldingTime");
            }
        }

        /// <summary>
        /// 料筒震台测试速度
        /// </summary>
        private ushort shakeTable1_TestSpeed;
        public ushort ShakeTable1_TestSpeed
        {
            get { return shakeTable1_TestSpeed; }
            set
            {
                ushort oldValue = shakeTable1_TestSpeed;
                if (PlcSettingMessageBus.pLCManagement.WriteShakeTable1_TestSpeed(value))
                {
                    shakeTable1_TestSpeed = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"料筒震台测试速度从{oldValue}修改为{value}");
                }
                OnPropertyChanged("ShakeTable1_TestSpeed");
            }
        }

        /// <summary>
        /// 缓存震台测试速度
        /// </summary>
        private ushort shakeTable2_TestSpeed;
        public ushort ShakeTable2_TestSpeed
        {
            get { return shakeTable2_TestSpeed; }
            set
            {
                ushort oldValue = shakeTable2_TestSpeed;
                if (PlcSettingMessageBus.pLCManagement.WriteShakeTable2_TestSpeed(value))
                {
                    shakeTable2_TestSpeed = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"缓存震台测试速度从{oldValue}修改为{value}");
                }
                OnPropertyChanged("ShakeTable2_TestSpeed");
            }
        }

        /// <summary>
        /// 计数震台测试速度
        /// </summary>
        private ushort shakeTable3_TestSpeed;
        public ushort ShakeTable3_TestSpeed
        {
            get { return shakeTable3_TestSpeed; }
            set
            {
                ushort oldValue = shakeTable3_TestSpeed;
                if (PlcSettingMessageBus.pLCManagement.WriteShakeTable3_TestSpeed(value))
                {
                    shakeTable3_TestSpeed = value;
                    if (oldValue != value)
                        FaultLog.RecordValueChangeMessage($"计数震台测试速度从{oldValue}修改为{value}");
                }
                OnPropertyChanged("ShakeTable3_TestSpeed");
            }
        }

        //数据绑定核心实现
        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
