private void connectToELLStageButton_Click(object sender, EventArgs e) { var args = new string[] { comPortComboBox1.SelectedItem.ToString(), "0" }; // get the communication portELLStage portELLStage = (args.Length > 0) ? args[0] : comPortComboBox1.SelectedItem.ToString(); // get the range of addresses used max range is '0' to 'F' char _minSearchLimit = (args.Length > 1 && ELLBaseDevice.IsValidAddress(char.ToUpper(args[1][0]))) ? char.ToUpper(args[1][0]) : '0'; char _maxSearchLimit = (args.Length > 2 && ELLBaseDevice.IsValidAddress(char.ToUpper(args[2][0]))) ? char.ToUpper(args[2][0]) : '1'; if (ELLDevicePort.Connect(portELLStage)) { textBox1.Text = "Discover devices"; // scan the portELLStage for connected devices using the given range of addresses List <string> devices = ellDevices.ScanAddresses(_minSearchLimit, _maxSearchLimit); foreach (string device in devices) { // configure each device found if (ellDevices.Configure(device)) { // test each device found textBox1.Text = "Identify device " + device[0]; textBox1.Text = "+++++++++++++++++++++++++"; addressedDevice = ellDevices.AddressedDevice(device[0]) as ELLDevice; if (addressedDevice != null) { DeviceID deviceInfo = addressedDevice.DeviceInfo; string sttr = ""; foreach (string str in deviceInfo.Description()) { sttr += str + Environment.NewLine; } textBox1.Text = sttr; switch (deviceInfo.DeviceType) { case DeviceID.DeviceTypes.OpticsRotator: //addressedDevice.SetHomeOffset((decimal)0.0); addressedDevice.Home(ELLBaseDevice.DeviceDirection.AntiClockwise); Thread.Sleep(250); homeOffset = addressedDevice.HomeOffset; break; default: break; } } } } } }
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; } }