public RegistersActionWindow(IModbusRegistersAction action, ValueTypeMode mode)
 {
     InitializeComponent();
     actionView.RefreshWith(action, mode);
     actionView.OkPressed += (a) => {
         this.DialogResult = true;
     };
     actionView.CancelPressed += () => {
         this.DialogResult = false;
     };
 }
        public void RefreshWith(IModbusRegistersAction action, ValueTypeMode mode)
        {
            _mode   = mode;
            _action = action;

            transportView.RefreshWith(action.Manager.Transport);

            if (mode == ValueTypeMode.All)
            {
                valueTypeView.RefreshWith(action.ModbusValueType, action.WriteReadLength, mode);
            }
            else if (mode == ValueTypeMode.String && action.ModbusValueType != NModbusWrapper.ValueType.String)
            {
                valueTypeView.RefreshWith(NModbusWrapper.ValueType.String, action.WriteReadLength, mode);
            }
            else if (mode == ValueTypeMode.Numeric && action.ModbusValueType == NModbusWrapper.ValueType.String)
            {
                valueTypeView.RefreshWith(NModbusWrapper.ValueType.Double, action.WriteReadLength, mode);
            }
            else
            {
                valueTypeView.RefreshWith(action.ModbusValueType, action.WriteReadLength, mode);
            }

            tbAddress.Text = action.SlaveAddress.ToString();
            tbCoil.Text    = action.RegisterAddress.ToString();

            _selectedRegistersMode = action.RegistersMode;
            if (_selectedRegistersMode == RegistersMode.Holding)
            {
                btRegistersModeHolding.Selected = true;
            }
            else
            {
                btRegistersModeInput.Selected = true;
            }

            ReInitializeMaxAndMin();

            if (valueTypeView.ValueType != NModbusWrapper.ValueType.String &&
                _mode != ValueTypeMode.String &&
                action.ValueType is FloatValueType floatValueType)
            {
                tbMax.Text = floatValueType.Max.ToString();
                tbMin.Text = floatValueType.Min.ToString();
            }
        }