Example #1
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;
        }
        public static RegisterGroup getRegisterGroupFactory(CrudDeviceModel model, List <_RegisterValue> registerValueList)
        {
            RegisterGroup registerGroup = null;

            switch ((EnumRegisterType)model.RegisterType)
            {
            case EnumRegisterType.DiscreteInput:
                registerGroup = new DIRegisterGroup()
                {
                    RegisterValueList = registerValueList
                };
                break;

            case EnumRegisterType.DiscreteOutput:
                registerGroup = new DORegisterGroup()
                {
                    RegisterValueList = registerValueList
                };
                break;

            case EnumRegisterType.AnalogInput:
                registerGroup = new AIRegisterGroup()
                {
                    RegisterValueList = registerValueList
                };
                break;

            case EnumRegisterType.AnalogOutput:
                registerGroup = new AORegisterGroup()
                {
                    RegisterValueList = registerValueList
                };
                break;

            case EnumRegisterType.FloatInput:
                registerGroup = new FIRegisterGroup()
                {
                    RegisterValueList = registerValueList
                };
                break;

            case EnumRegisterType.FloatOutput:
                registerGroup = new FORegisterGroup()
                {
                    RegisterValueList = registerValueList
                };
                break;

            case EnumRegisterType.LongInput:
                registerGroup = new LIRegisterGroup()
                {
                    RegisterValueList = registerValueList
                };
                break;

            case EnumRegisterType.LongOutput:
                registerGroup = new LORegisterGroup()
                {
                    RegisterValueList = registerValueList
                };
                break;
            }

            registerGroup.IpAddress    = model.DeviceAddress;
            registerGroup.Port         = model.DevicePort;
            registerGroup.RegisterType = (EnumRegisterType)model.RegisterType;

            return(registerGroup);
        }
Example #3
0
 public CrudDeviceViewModel()
 {
     _crudDeviceModel = new CrudDeviceModel();
 }