コード例 #1
0
        public ModbusValueTypeSelectionView(ushort length, NModbusWrapper.ValueType valueType, ValueTypeMode mode)
        {
            InitializeComponent();

            lvItems.SelectionChanged += (o, e) => {
                btOk.IsEnabled = lvItems.SelectedItem != null;
                if (lvItems.SelectedItem != null && ((ItemView)lvItems.SelectedItem).Tag.ToString().Equals("String"))
                {
                    spStringLength.Visibility = Visibility.Visible;
                }
                else
                {
                    spStringLength.Visibility = Visibility.Collapsed;
                }
            };

            if (mode == ValueTypeMode.String)
            {
                lvItems.GetItems().Where(x => ((ItemView)x).Tag.ToString() != "String").ToList()
                .ForEach(x => ((ItemView)x).IsEnabled = false);
            }
            else if (mode == ValueTypeMode.Numeric)
            {
                lvItems.GetItems().Where(x => ((ItemView)x).Tag.ToString() == "String").ToList()
                .ForEach(x => ((ItemView)x).IsEnabled = false);
            }

            tbLength.Validation = EntryViewValidation.UShortValidation(min: 1);

            btCancel.Click += (o, e) => CancelPressed?.Invoke();
            btOk.Click     += (o, e) => OkPressed?.Invoke();
        }
コード例 #2
0
        private object Parse(NModbusWrapper.ValueType type, string value)
        {
            switch (type)
            {
            case NModbusWrapper.ValueType.Double:
                return(double.Parse(value));

            case NModbusWrapper.ValueType.Float:
                return(float.Parse(value));

            case NModbusWrapper.ValueType.Int:
                return(int.Parse(value));

            case NModbusWrapper.ValueType.Long:
                return(long.Parse(value));

            case NModbusWrapper.ValueType.Short:
                return(short.Parse(value));

            case NModbusWrapper.ValueType.String:
                return(value);

            case NModbusWrapper.ValueType.UInt:
                return(uint.Parse(value));

            case NModbusWrapper.ValueType.ULong:
                return(ulong.Parse(value));

            case NModbusWrapper.ValueType.UShort:
                return(ushort.Parse(value));

            default:
                throw new NotSupportedException("type [" + type + "] not supported");
            }
        }
コード例 #3
0
        private Type GetTypeByEnum(NModbusWrapper.ValueType type)
        {
            switch (type)
            {
            case NModbusWrapper.ValueType.Double:
                return(typeof(double));

            case NModbusWrapper.ValueType.Float:
                return(typeof(float));

            case NModbusWrapper.ValueType.Int:
                return(typeof(int));

            case NModbusWrapper.ValueType.Long:
                return(typeof(long));

            case NModbusWrapper.ValueType.Short:
                return(typeof(short));

            case NModbusWrapper.ValueType.String:
                return(typeof(string));

            case NModbusWrapper.ValueType.UInt:
                return(typeof(uint));

            case NModbusWrapper.ValueType.ULong:
                return(typeof(ulong));

            case NModbusWrapper.ValueType.UShort:
                return(typeof(ushort));

            default:
                throw new NotSupportedException("type [" + type + "] not supported");
            }
        }
コード例 #4
0
 public void RefreshWith(NModbusWrapper.ValueType valueType, ushort length, ValueTypeMode mode)
 {
     lblDescription.Content = Enum.GetName(typeof(NModbusWrapper.ValueType), valueType);
     if (valueType == NModbusWrapper.ValueType.String)
     {
         lblDescription.Content = lblDescription.Content.ToString() + ", " + length.ToString() + " символов";
     }
     ValueType = valueType;
     Length    = length;
     _mode     = mode;
 }
コード例 #5
0
        public static void Show(Grid parent, NModbusWrapper.ValueType valueType, ushort length, Action <NModbusWrapper.ValueType, ushort> callback, ValueTypeMode mode)
        {
            var control = new ModbusValueTypeSelectionView(length, valueType, mode);
            var dialog  = new DialogView(control);

            control.OkPressed += () => {
                callback?.Invoke(control.GetValueType(), control.GetValueLength());
                dialog.Close();
            };
            control.SetValueType(valueType);
            control.SetValueLength(length);
            control.CancelPressed += () => dialog.Close();
            dialog.Show(parent);
        }
コード例 #6
0
        public void SetValueType(NModbusWrapper.ValueType valueType)
        {
            var name = Enum.GetName(typeof(NModbusWrapper.ValueType), valueType);

            lvItems.GetItems().FirstOrDefault(x => ((ItemView)x).Tag.ToString().Equals(name)).Selected = true;
        }