Example #1
0
 /// <summary> Constructor. </summary>
 /// <param name="owner">         The owner. </param>
 /// <param name="device">        The device. </param>
 /// <param name="motorCount">    Number of motors. </param>
 /// <param name="rotary">        true to rotary. </param>
 /// <param name="continuousJog"> true to continuous jog. </param>
 /// <param name="allowCleaning">      True if this object can clean. </param>
 public ELLStageViewModel(ELLDevicesViewModel owner, ELLDevice device, int motorCount, bool rotary, bool continuousJog, bool allowCleaning)
     : base(owner, rotary ? "Rotary Stage" : "Linear Stage", device, motorCount)
 {
     _allowCleaning   = allowCleaning;
     ELLDeviceStage   = device;
     UseHomeDirection = rotary;
     if (rotary)
     {
         AllowContinuousJog = continuousJog;
         IsContinuousJog    = false;
         HomeDirections     = new Dictionary <ELLBaseDevice.DeviceDirection, string>
         {
             { ELLBaseDevice.DeviceDirection.Clockwise, "Clockwise" },
             { ELLBaseDevice.DeviceDirection.AntiClockwise, "Anticlockwise" }
         };
         HomeDirection = ELLBaseDevice.DeviceDirection.AntiClockwise;
         Units         = "deg";
     }
     else
     {
         AllowContinuousJog = false;
         IsContinuousJog    = false;
         HomeDirections     = new Dictionary <ELLBaseDevice.DeviceDirection, string>
         {
             { ELLBaseDevice.DeviceDirection.Linear, "Linear" },
         };
         HomeDirection = ELLBaseDevice.DeviceDirection.Linear;
         Units         = Device.DeviceInfo.Units;
     }
     TargetAbsoluteMove             = 0;
     TargetRelativeMove             = 0.1m;
     ELLDeviceStage.CleaningUpdate += (sender, b) => IsCleaning = b;
 }
Example #2
0
        /// <summary> Creates a command. </summary>
        /// <param name="devices">	  The devices. </param>
        /// <param name="addresses">  The addresses. </param>
        /// <param name="command">    The command. </param>
        /// <param name="wait">		  The wait. </param>
        /// <param name="parameter1"> The first parameter. </param>
        /// <param name="parameter2"> The second parameter. </param>
        /// <returns> The new command. </returns>
        public SequenceItem CreateCommand(ELLDevices devices, List <char> addresses, ELLCommands command, TimeSpan wait, decimal parameter1, ELLBaseDevice.DeviceDirection parameter2)
        {
            if (!addresses.Any())
            {
                return(null);
            }
            ELLDevice device = devices.AddressedDevice(addresses.First()) as ELLDevice;

            if (device == null)
            {
                return(null);
            }
            if (addresses.Count == 1)
            {
                switch (command)
                {
                case ELLCommands.GetPosition:
                    return(new SequenceItem(command, device.Address, device.GetPosition, command.GetStringValue(), wait));

                case ELLCommands.Forward:
                    return(new SequenceItem(command, device.Address, device.JogForward, command.GetStringValue(), wait));

                case ELLCommands.Backward:
                    return(new SequenceItem(command, device.Address, device.JogBackward, command.GetStringValue(), wait));

                case ELLCommands.Home:
                    return(new SequenceItem(command, device.Address, () => device.Home(parameter2), command.GetStringValue(), wait));

                case ELLCommands.MoveRelative:
                    return(new SequenceItem(command, device.Address, () => device.MoveRelative(parameter1), command.GetStringValue(), wait));

                case ELLCommands.MoveAbsolute:
                    return(new SequenceItem(command, device.Address, () => device.MoveAbsolute(parameter1), command.GetStringValue(), wait));

                case ELLCommands.SetJogstepSize:
                    return(new SequenceItem(command, device.Address, () => device.SetJogstepSize(parameter1), command.GetStringValue(), wait));
                }
            }
            else
            {
                switch (command)
                {
                case ELLCommands.Forward:
                    return(new SequenceItem(command, device.Address, () => device.JogForward(addresses), command.GetStringValue(), wait));

                case ELLCommands.Backward:
                    return(new SequenceItem(command, device.Address, () => device.JogBackward(addresses), command.GetStringValue(), wait));

                case ELLCommands.Home:
                    return(new SequenceItem(command, device.Address, () => device.Home(addresses, parameter2), command.GetStringValue(), wait));

                case ELLCommands.MoveRelative:
                    return(new SequenceItem(command, device.Address, () => device.MoveRelative(addresses, parameter1), command.GetStringValue(), wait));

                case ELLCommands.MoveAbsolute:
                    return(new SequenceItem(command, device.Address, () => device.MoveAbsolute(addresses, parameter1), command.GetStringValue(), wait));
                }
            }
            return(null);
        }
        private void JogReverse()
        {
            ELLDevice ellDevice = Device as ELLDevice;

            if (Owner.IsConnected && (ellDevice != null))
            {
                Owner.BackgroundThreadManager.RunBackgroundFunction((s, e) => ellDevice.JogBackward());
            }
        }
        private void GetPosition()
        {
            ELLDevice ellDevice = Device as ELLDevice;

            if (Owner.IsConnected && (ellDevice != null))
            {
                Owner.BackgroundThreadManager.RunBackgroundFunction((s, e) => ellDevice.GetPosition());
            }
        }
Example #5
0
        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;
                            }
                        }
                    }
                }
            }
        }
Example #6
0
 /// <summary>   Constructor. </summary>
 /// <param name="owner">        The owner. </param>
 /// <param name="device">       The device. </param>
 /// <param name="positions">    The positions. </param>
 public ELLShutterViewModel(ELLDevicesViewModel owner, ELLDevice device, int positions)
     : base(owner, "Shutter", device, 1)
 {
     ELLDeviceShutter = device;
     _positions       = positions;
     if (ShowPositions)
     {
         List <ButtonRelayCommandViewModel> buttons = new List <ButtonRelayCommandViewModel>();
         for (int i = 0; i < _positions; i++)
         {
             int i1 = i;
             buttons.Add(new ButtonRelayCommandViewModel(() => { MoveToPosition(i1); }, $"Position {i}"));
         }
         Buttons = buttons;
     }
 }
 /// <summary> Constructor. </summary>
 /// <param name="owner">   The owner. </param>
 /// <param name="device">  The device. </param>
 public ELLActuatorViewModel(ELLDevicesViewModel owner, ELLDevice device)
     : base(owner, "Actuator", device, 1)
 {
 }
Example #8
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();
                }
            }
        }