Exemple #1
0
        private void ParameterUpdate(MessageUpdater.UpdateTypes type, char address, object data)
        {
            switch (type)
            {
            case MessageUpdater.UpdateTypes.DeviceInfo:
            {
                DeviceID info = data as DeviceID;
                if ((info != null) && _deviceViewModels.ContainsKey(address))
                {
                    _dispatcher.BeginInvoke(() => _deviceViewModels[address].Description = info.Description());
                }
            }
            break;

            case MessageUpdater.UpdateTypes.MotorInfo:
            {
                MotorInfo info = data as MotorInfo;
                if ((info != null) && _deviceViewModels.ContainsKey(address))
                {
                    ELLMotorViewModel first = _deviceViewModels[address].Motors.FirstOrDefault(motor => motor.MotorID == info.MotorID);
                    if (first != null)
                    {
                        _dispatcher.BeginInvoke(() => first.UpdateInfo(info));
                    }
                }
            }
            break;

            case MessageUpdater.UpdateTypes.Status:
            {
                DeviceStatus status = data as DeviceStatus;
                if (status != null)
                {
                    switch (status.Status)
                    {
                    case DeviceStatus.DeviceStatusValues.OK:
                        break;

                    case DeviceStatus.DeviceStatusValues.Busy:
                        break;

                    default:
                        MessageBox.Show(string.Format("Device error: {0}", status.Status.GetStringValue()), "Device Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        break;
                    }
                }
            }
            break;

            case MessageUpdater.UpdateTypes.Position:
            {
                try
                {
                    decimal position = (decimal)data;
                    if (_deviceViewModels.ContainsKey(address))
                    {
                        _dispatcher.BeginInvoke(() => _deviceViewModels[address].UpdatePosition(position));
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(string.Format("Device error: status {0}", e.Message), "Device Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            break;

            case MessageUpdater.UpdateTypes.PolarizerPositions:
            {
                try
                {
                    ELLPaddlePolariser.PolarizerPaddlePositions positions = (ELLPaddlePolariser.PolarizerPaddlePositions)data;
                    if (_deviceViewModels.ContainsKey(address))
                    {
                        ELLPaddlePolariserViewModel paddleViewModel = _deviceViewModels[address] as ELLPaddlePolariserViewModel;
                        if (paddleViewModel != null)
                        {
                            _dispatcher.BeginInvoke(() => paddleViewModel.UpdatePaddlePosition(positions));
                        }
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(string.Format("Device error: status {0}", e.Message), "Device Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            break;

            case MessageUpdater.UpdateTypes.PaddlePosition:
            {
                try
                {
                    ELLPaddlePolariser.PaddlePosition position = (ELLPaddlePolariser.PaddlePosition)data;
                    if (_deviceViewModels.ContainsKey(address))
                    {
                        ELLPaddlePolariserViewModel paddleViewModel = _deviceViewModels[address] as ELLPaddlePolariserViewModel;
                        if (paddleViewModel != null)
                        {
                            _dispatcher.BeginInvoke(() => paddleViewModel.UpdatePaddlePosition(position));
                        }
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(string.Format("Device error: status {0}", e.Message), "Device Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            break;

            case MessageUpdater.UpdateTypes.HomeOffset:
            {
                try
                {
                    decimal homeOffset = (decimal)data;
                    if (_deviceViewModels.ContainsKey(address))
                    {
                        _dispatcher.BeginInvoke(() => _deviceViewModels[address].UpdateHomeOffset(homeOffset));
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(string.Format("Device error: status {0}", e.Message), "Device Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            break;

            case MessageUpdater.UpdateTypes.JogstepSize:
            {
                try
                {
                    decimal jogStep = (decimal)data;
                    if (_deviceViewModels.ContainsKey(address))
                    {
                        _dispatcher.BeginInvoke(() => _deviceViewModels[address].UpdateJogstepSize(jogStep));
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show(string.Format("Device error: status {0}", e.Message), "Device Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            break;
            }
        }
Exemple #2
0
        private void ConnectEx()
        {
            if (ELLDevicePort.IsConnected)
            {
                DisconnectEx();
            }
            else
            {
                bool connected;
                try
                {
                    connected = ELLDevicePort.Connect(SelectedPort);
                }
                catch (Exception ex)
                {
                    OutputUpdate(ex.Message, OutputItem.OutputItemType.Error);
                    connected = false;
                }
                IsConnected = ELLDevicePort.IsConnected;
                if (!connected)
                {
                    return;
                }
                if (MinSearchLimit > MaxSearchLimit)
                {
                    MaxSearchLimit = MinSearchLimit;
                }
                ELLDevicePort.DataSent     = DataSent;
                ELLDevicePort.DataReceived = DataReceived;
                _deviceViewModels.Clear();
                _ellDevice.ClearDevices();
                List <string> devices = _ellDevice.ScanAddresses(MinSearchLimit, MaxSearchLimit);
                if (devices.Count > 0)
                {
                    foreach (string deviceID in devices)
                    {
                        _ellDevice.Configure(deviceID);
                        _ellDevice.Connect();
                        char address = deviceID[0];
                        ELLDeviceBaseViewModel vm         = null;
                        DeviceID.DeviceTypes   deviceType = _ellDevice.AddressedDevice(address).DeviceInfo.DeviceType;
                        if (deviceType == DeviceID.DeviceTypes.Paddle)
                        {
                            ELLPaddlePolariser device = _ellDevice.AddressedDevice(address) as ELLPaddlePolariser;
                            vm = new ELLPaddlePolariserViewModel(this, device);
                        }
                        else
                        {
                            ELLDevice device = _ellDevice.AddressedDevice(address) as ELLDevice;
                            switch (deviceType)
                            {
                            case DeviceID.DeviceTypes.Actuator:
                                vm = new ELLActuatorViewModel(this, device);
                                break;

                            case DeviceID.DeviceTypes.Shutter:
                                vm = new ELLShutterViewModel(this, device, 2);
                                break;

                            case DeviceID.DeviceTypes.Shutter4:
                                vm = new ELLShutterViewModel(this, device, 4);
                                break;

                            case DeviceID.DeviceTypes.Rotator:
                                vm = new ELLStageViewModel(this, device, 2, true, true, false);
                                break;

                            case DeviceID.DeviceTypes.OpticsRotator:
                                vm = new ELLStageViewModel(this, device, 2, true, true, true);
                                break;

                            case DeviceID.DeviceTypes.RotaryStage18:
                                vm = new ELLStageViewModel(this, device, 2, true, false, true);
                                break;

                            case DeviceID.DeviceTypes.RotaryStage:
                                vm = new ELLStageViewModel(this, device, 2, true, false, false);
                                break;

                            case DeviceID.DeviceTypes.LinearStage:
                            case DeviceID.DeviceTypes.LinearStage2:
                                vm = new ELLStageViewModel(this, device, 2, false, false, false);
                                break;

                            case DeviceID.DeviceTypes.LinearStage17:
                            case DeviceID.DeviceTypes.LinearStage20:
                                vm = new ELLStageViewModel(this, device, 2, false, false, true);
                                break;
                            }
                        }
                        if (vm != null)
                        {
                            _deviceViewModels[address] = vm;
                            foreach (ELLMotorViewModel motor in vm.Motors)
                            {
                                motor.GetMotorInfoDirect();
                            }
                            vm.InitializeViewModel();
                        }
                        _sequenceViewModel.DeviceTypes = _deviceViewModels.ToDictionary(item => item.Key, item => item.Value.Device.DeviceInfo.DeviceType);
                    }
                }
                else
                {
                    DisconnectEx();
                }
            }
        }