Exemple #1
0
        private async void OnAddDeviceExecute(object obj)
        {
            IDeviceCreator deviceCreator = (obj as IDeviceDefinitionViewModel)?.Model as IDeviceCreator;

            if (deviceCreator == null)
            {
                return;
            }
            if (deviceCreator.AvailableConnection == null)
            {
                return;
            }
            _comConnectionManager.SetComPortConfigurationByName((deviceCreator.AvailableConnection as IModbusRtuConnection).ComPortConfiguration, (deviceCreator.AvailableConnection as IModbusRtuConnection).PortName);
            var device = deviceCreator.Create();

            device.DeviceSignature = device.Name;
            await _devicesContainerService.ConnectDeviceAsync(device, deviceCreator.AvailableConnection);

            if (!_devicesContainerService.ConnectableItems.Contains(device))
            {
                _devicesContainerService.AddConnectableItem(device);
            }
            //DeviceDefinitionViewModels.Remove(obj as IDeviceDefinitionViewModel);
            IsDevicesNotFound = false;
            (obj as IDeviceDefinitionViewModel).IsAddedToProject = true;
            await Task.Delay(300);

            _flyoutService.CloseFlyout();
        }
Exemple #2
0
        public async Task LoadProject(string path)
        {
            try
            {
                var deserialized = _serializerService.DeserializeFromFile <IUniconProject>(path);
                _uniconProject.ConnectableItems = deserialized.ConnectableItems;
                _uniconProject.LayoutString     = deserialized.LayoutString;
                _uniconProject.ProjectPath      = Path.GetDirectoryName(path);
                _uniconProject.Name             = Path.GetFileNameWithoutExtension(path);
                _devicesContainerService.Refresh();
                foreach (IConnectable connectableItem in _uniconProject.ConnectableItems)
                {
                    if (connectableItem.DeviceConnection != null)
                    {
                        var res = await _devicesContainerService.ConnectDeviceAsync(connectableItem as IDevice,
                                                                                    connectableItem.DeviceConnection);

                        if (!res.IsSuccess)
                        {
                            await _devicesContainerService.ConnectDeviceAsync(connectableItem as IDevice,
                                                                              _container.Resolve <IDeviceConnectionFactory>(ApplicationGlobalNames
                                                                                                                            .OFFLINE_CONNECTION_FACTORY_NAME).CreateDeviceConnection());
                        }

                        if (!_devicesContainerService.ConnectableItems.Contains(connectableItem as IDevice))
                        {
                            _devicesContainerService.AddConnectableItem(connectableItem as IDevice);
                        }
                    }
                }

                string message = string.Empty;
                message += _localizerService.GetLocalizedString(ServicesKeys.PROJECT_OPENED);
                message += " " + _uniconProject.ProjectPath + "\\" + _uniconProject.Name + ".uniproj";

                _logService.LogMessage(message);
                _applicationSettingsService.AddRecentProject(path);
            }
            catch (Exception ex)
            {
                _logService.LogMessage(ex.Message);
            }
        }