Ejemplo n.º 1
0
        public static _RegisterValue getRegisterValueFactory(EnumRegisterType registerType, int address, string name)
        {
            _RegisterValue registerValue = null;

            switch (registerType)
            {
            case EnumRegisterType.DiscreteInput:
            case EnumRegisterType.DiscreteOutput:
                registerValue = new RegisterValue <bool>()
                {
                    Address = address,
                    Name    = name,
                    Value   = false
                };
                break;

            case EnumRegisterType.AnalogInput:
            case EnumRegisterType.AnalogOutput:
                registerValue = new RegisterValue <short>()
                {
                    Address = address,
                    Name    = name,
                    Value   = 0
                };
                break;

            case EnumRegisterType.FloatInput:
            case EnumRegisterType.FloatOutput:
                registerValue = new RegisterValue <float>()
                {
                    Address = address,
                    Name    = name,
                    Value   = 0f
                };
                break;

            case EnumRegisterType.LongInput:
            case EnumRegisterType.LongOutput:
                registerValue = new RegisterValue <int>()
                {
                    Address = address,
                    Name    = name,
                    Value   = 0
                };
                break;
            }

            return(registerValue);
        }
Ejemplo n.º 2
0
        private void SaveCrudDevice()
        {
            CrudDeviceViewModel viewModel = null;
            CrudDeviceModel     model     = null;

            viewModel = this;

            if (viewModel != null && viewModel.CrudDeviceModel != null)
            {
                model = viewModel.CrudDeviceModel;
            }


            List <_RegisterValue> registerValueList = new List <_RegisterValue>();

            for (int i = 0; i < model.RegisterCount; i++)
            {
                //string name = (model.AutoGenerateName == true) ? model.DeviceName + "_reg_" + i : "";
                //TODO default considered to be checked
                string         name          = model.DeviceName + "_reg_" + i;
                int            address       = model.StartingAddress + i;
                _RegisterValue registerValue = _RegisterValue.getRegisterValueFactory((EnumRegisterType)model.RegisterType, address, name);
                registerValueList.Add(registerValue);
            }

            RegisterGroup registerGroup = RegisterGroup.getRegisterGroupFactory(model, registerValueList);

            DeviceTreeModel configuration = new DeviceTreeModel()
            {
                DeviceName        = model.DeviceName,
                ConfigurationType = EnumConfigurationType.RegisterGroup,
                RegisterGroup     = registerGroup
            };


            MainWindow.Instance.DeviceTree.SelectedTreeNode.ListDeviceTreeModel.Add(configuration);
            //ConfigurationStore.getInstance().addConfiguration(configuration);

            MainWindow.Instance.DeviceTree.updateTree();
            MainWindow.Instance.ShowCrudDevice = false;



            string message = "Device Created successfully";

            viewModel.FeedbackMessage = message;
        }