Пример #1
0
        /// <summary>   Process the device status. </summary>
        /// <param name="deviceStatus"> The device status. </param>
        /// <param name="resendCmd">    The resend command. </param>
        /// <param name="getter">       True to getter. </param>
        /// <returns>   A StatusResult. </returns>
        protected override StatusResult ProcessDeviceStatus(DeviceStatus deviceStatus, string resendCmd, bool getter)
        {
            switch (deviceStatus.Status)
            {
            case DeviceStatus.DeviceStatusValues.Busy:
                UpdateDeviceStatus(deviceStatus);
                if (getter)
                {
                    ELLDevicePort.SendString(Address, resendCmd);
                }
                return(StatusResult.Busy);

            case DeviceStatus.DeviceStatusValues.OK:
                //_isThermalLocked = false;
                UpdateDeviceStatus(deviceStatus);
                if (getter)
                {
                    ELLDevicePort.SendString(Address, resendCmd);
                }
                return(StatusResult.OK);

            case DeviceStatus.DeviceStatusValues.ModuleIsolated:
                UpdateDeviceStatus(deviceStatus);
                return(StatusResult.Fail);

            default:
                UpdateDeviceStatus(deviceStatus);
                Thread.Sleep(500);
                ELLDevicePort.SendString(Address, resendCmd);
                break;
            }
            return(StatusResult.Error);
        }
Пример #2
0
 /// <summary> Get the device MotorInfo structure. </summary>
 /// <returns> Success if the motor info retrieved succesfully. </returns>
 public bool GetMotorInfo(char motorID)
 {
     if (!IsMotorIdValid(motorID))
     {
         return(false);
     }
     UpdateOutput(string.Format("Requesting Motor{0} info...", motorID));
     ELLDevicePort.SendString(Address, "i" + motorID);
     try
     {
         string msg = ELLDevicePort.WaitForResponse(Address, "I" + motorID, MoveTimeout);
         if (!string.IsNullOrEmpty(msg))
         {
             MotorInfo info = new MotorInfo(msg);
             _motorInfo[motorID] = info;
             UpdateOutput("Get Device Status: ", info.Description());
             UpdateParameter(MessageUpdater.UpdateTypes.MotorInfo, Address, info);
             return(true);
         }
     }
     catch (ELLException)
     {
         UpdateOutput(string.Format("Requesting Motor{0}: FAILED", motorID));
     }
     return(false);
 }
Пример #3
0
        /// <summary> Move the current stage by a relative distance. </summary>
        /// <param name="addresses"> The addresses of the stages to be moved. </param>
        /// <param name="step"> The relative step distance. </param>
        /// <returns> True if the stage was moved succesfully. </returns>
        /// <seealso cref="Home(List<char>, ELLBaseDevice.DeviceDirection)"/>
        /// <seealso cref="MoveAbsolute(List<char>, decimal)"/>
        /// <seealso cref="MoveRelative(List<char>, decimal)"/>
        /// <seealso cref="JogForward(List<char>)"/>
        /// <seealso cref="JogBackward(List<char>)"/>
        public bool MoveRelative(List <char> addresses, decimal step)
        {
            if (IsDeviceBusy())
            {
                return(false);
            }
            if (!addresses.Any())
            {
                return(MoveRelative(step));
            }
            SetToGroupAddress(addresses);
            UpdateOutput(string.Format("Move device by {0}...", DeviceInfo.FormatPosition(step, true, true)));
            int pulses = DeviceInfo.UnitToPulse(step);

            if (pulses == 0)
            {
                return(true);
            }
            ELLDevicePort.SendStringI32(Address, "mr", pulses);
            if (!WaitForPositions(addresses))
            {
                return(false);
            }
            return(true);
        }
Пример #4
0
        /// <summary>	Scans the addresses. </summary>
        /// <param name="minDeviceAddress">	The minimum device address. </param>
        /// <param name="maxDeviceAddress">	The maximum device address. </param>
        /// <returns>	Returns a list of available device addresses. </returns>
        public List <string> ScanAddresses(char minDeviceAddress, char maxDeviceAddress)
        {
            List <string> connections = new List <string>();

            if (!ELLDevicePort.IsConnected)
            {
                return(connections);
            }

            _messageUpdater.UpdateOutput("Scanning for devices");
            foreach (char address in ELLBaseDevice.ValidAddresses.Where(item => item >= minDeviceAddress && item <= maxDeviceAddress))
            {
                ELLDevicePort.SendString(address, "in");
                try
                {
                    string msg = ELLDevicePort.WaitForResponse(address, "IN", ELLBaseDevice.StatusTimeout);
                    if (!string.IsNullOrEmpty(msg))
                    {
                        connections.Add(msg);
                    }
                }
                catch (ELLException e)
                {
                    Debug.WriteLine(e.Message);
                    // device address not used
                }
            }
            _messageUpdater.UpdateOutput(connections.Count < 2
                                ? string.Format("{0} device found", connections.Count)
                                : string.Format("{0} devices found", connections.Count));
            return(connections);
        }
Пример #5
0
 private void StartJogging(string command, string message)
 {
     _isJogging = true;
     UpdateOutput(message);
     ELLDevicePort.SendString(Address, command);
     if (_jogTimer == null)
     {
         _jogTimer = new Timer(JogTimeUpdate, 0, 100, 0);
     }
 }
Пример #6
0
 /// <summary> Sets the new device address. </summary>
 /// <param name="newAddress"> The new device address. </param>
 /// <returns> True if the device address is changed. </returns>
 public bool SetAddress(char newAddress)
 {
     if (newAddress == Address)
     {
         return(true);
     }
     UpdateOutput(string.Format("changing address to {0}...", newAddress));
     ELLDevicePort.SendStringB(Address, "ca", (byte)newAddress);
     Address = newAddress;
     return(WaitForStatus());
 }
Пример #7
0
 /// <summary>	Starts a forward jog and returns after position value is returned. </summary>
 /// <returns> True if the device was jogged succesfully. </returns>
 public bool JogStop()
 {
     if (!_isJogging)
     {
         return(false);
     }
     JogStopInternal();
     //Debug.WriteLine($"Stop Set false {_isJogging}");
     UpdateOutput("Jog Stop");
     ELLDevicePort.SendString(Address, "ms");
     return(GetPosition());
 }
Пример #8
0
 /// <summary>	Saves the user data. </summary>
 /// <returns>	True if the UserData is saved by the device. </returns>
 public bool SendStopCleaning()
 {
     if (!_isCleaning)
     {
         return(false);
     }
     UpdateOutput("Stop cleaning...");
     ELLDevicePort.SendString(Address, "st");
     SetSleepDelayCounter(2);
     ELLDevicePort.SendString(Address, "gs");
     return(true);
 }
Пример #9
0
        /// <summary> Sets the home offset for the current stage. </summary>
        /// <param name="offset"> The stage offset. </param>
        /// <returns> True if the Offset were set. </returns>
        /// <seealso cref="HomeOffset"/>
        /// <seealso cref="GetHomeOffset()"/>
        public bool SetHomeOffset(decimal offset)
        {
            UpdateOutput(string.Format("Set Home Offset to {0}...", DeviceInfo.FormatPosition(offset, true, true)));
            int pulses = DeviceInfo.UnitToPulse(offset);

            ELLDevicePort.SendStringI32(Address, "so", pulses);
            if (!WaitForHomeOffset("gs", false))
            {
                return(false);
            }
            _homeOffset = offset;
            return(true);
        }
Пример #10
0
        /// <summary> Sets the current device jogstep size. </summary>
        /// <param name="jogstepSize"> The size of the jogstep. </param>
        /// <returns> True if the jog step were set succesfully. </returns>
        public bool SetJogstepSize(decimal jogstepSize)
        {
            UpdateOutput(string.Format("Set Jog Step to {0}...", DeviceInfo.FormatPosition(jogstepSize)));
            int pulses = DeviceInfo.UnitToPulse(jogstepSize);

            ELLDevicePort.SendStringI32(Address, "sj", pulses);
            if (!WaitForJogstepSize("gs", false))
            {
                return(false);
            }
            _jogstepSize = jogstepSize;
            return(true);
        }
Пример #11
0
 /// <summary> Jog the current device backward. </summary>
 /// <returns> True if the device was jogged succesfully. </returns>
 /// <seealso cref="JogBackward()"/>
 /// <seealso cref="SetJogstepSize(decimal)"/>
 /// <seealso cref="GetJogstepSize()"/>
 /// <seealso cref="JogForward(List<char>)"/>
 /// <seealso cref="JogBackward(List<char>)"/>
 public bool JogBackward()
 {
     if (IsDeviceBusy())
     {
         return(false);
     }
     UpdateOutput(string.Format("Jog Backward {0}", DeviceInfo.FormatPosition(_jogstepSize, true, true)));
     ELLDevicePort.SendString(Address, "bw");
     if (!WaitForPosition())
     {
         return(false);
     }
     return(true);
 }
Пример #12
0
        /// <summary>	Saves the user data. </summary>
        /// <returns>	True if the UserData is saved by the device. </returns>
        public bool SendCleanAndOptimize()
        {
            if (IsDeviceBusy())
            {
                return(false);
            }
            SetCleaningState(true);;
            UpdateOutput("Performing clean & optimize...");
            ELLDevicePort.SendString(Address, "om");
            bool retval = WaitForCleaning();

            SetCleaningState(false);;
            return(retval);
        }
Пример #13
0
 /// <summary> Homes the current stage. </summary>
 /// <param name="direction"> The home direction. </param>
 /// <returns> True if the device was homed succesfully. </returns>
 /// <seealso cref="Home(List<char>, ELLDevice.DeviceDirection)"/>
 public bool Home(DeviceDirection direction = DeviceDirection.Linear)
 {
     if (IsDeviceBusy())
     {
         return(false);
     }
     UpdateOutput("Homing device ...");
     ELLDevicePort.SendString(Address, "ho" + (char)direction);
     if (!WaitForPosition())
     {
         return(false);
     }
     return(true);
 }
Пример #14
0
        /// <summary>	Saves the user data. </summary>
        /// <returns>	True if the UserData is saved by the device. </returns>
        public bool SendCleanMachine()
        {
            if (IsDeviceBusy())
            {
                return(false);
            }
            SetCleaningState(true);
            UpdateOutput("Performing clean mechanics...");
            ELLDevicePort.SendString(Address, "cm");
            bool retval = WaitForCleaning();

            SetCleaningState(false);;
            return(retval);
        }
Пример #15
0
 /// <summary>  Homes the given paddles. </summary>
 /// <param name="paddles"> (Optional) The paddles. </param>
 /// <returns>  True if it succeeds, false if it fails. </returns>
 public bool Home(PaddleHomeMask paddles = PaddleHomeMask.All)
 {
     if (paddles == PaddleHomeMask.None)
     {
         return(false);
     }
     UpdateOutput("Homing paddles ...");
     ELLDevicePort.SendString(Address, "ho" + (char)('0' + paddles));
     if (!WaitForPositions())
     {
         return(false);
     }
     return(true);
 }
Пример #16
0
 public bool MoveAbsolute(PaddlePosition position)
 {
     try
     {
         short pulses = (short)(UnitToPulse(position.Position, 0, 0x3FF));
         UpdateOutput(string.Format("Move paddle {0} to {1}...", (char)position.PaddleId, position.PaddleId));
         ELLDevicePort.SendStringI16(Address, $"a{(char)position.PaddleId}", pulses);
         return(WaitForPosition(position.PaddleId));
     }
     catch (OverflowException)
     {
         UpdateOutput(string.Format("Parameter out of range {0}...", position.Position));
     }
     return(false);
 }
Пример #17
0
 public bool MoveAbsolute(PolarizerPaddlePositions positions)
 {
     try
     {
         int encodedPosition = GetEncodedPosition(positions, false);
         UpdateOutput(string.Format("Move paddles to {0},{1},{2}...", positions.Paddle1, positions.Paddle2, positions.Paddle3));
         ELLDevicePort.SendStringI32(Address, "ma", encodedPosition);
         return(WaitForPositions());
     }
     catch (OverflowException)
     {
         UpdateOutput(string.Format("Parameter out of range {0},{1},{2}...", positions.Paddle1, positions.Paddle2, positions.Paddle3));
     }
     return(false);
 }
Пример #18
0
 public bool MoveRelative(PaddlePosition displacement)
 {
     try
     {
         short pulses = (short)(UnitToPulse(displacement.Position, -0x3FF, 0x3FF));
         UpdateOutput(string.Format("Move paddle {0} by {1}...", (char)displacement.PaddleId, displacement.PaddleId));
         ELLDevicePort.SendStringI16(Address, $"r{(char)displacement.PaddleId}", pulses);
         return(WaitForPosition(displacement.PaddleId));
     }
     catch (OverflowException)
     {
         UpdateOutput(string.Format("Parameter out of range {0}...", displacement.Position));
     }
     return(false);
 }
Пример #19
0
 /// <summary> Scan current Curve. </summary>
 /// <param name="motorID">   Identifier for the motor. </param>
 /// <returns> True if the function was performed succesfully. </returns>
 public bool ScanCurrentCurve(char motorID)
 {
     if (!IsMotorIdValid(motorID))
     {
         return(false);
     }
     UpdateOutput(string.Format("Motor{0} - Scan Current ...", motorID));
     ELLDevicePort.SendString(Address, "c" + motorID);
     if (!WaitForStatus(6000))
     {
         return(false);
     }
     GetMotorInfo(motorID);
     return(true);
 }
Пример #20
0
 /// <summary> Jog the given stages forward. </summary>
 /// <param name="addresses"> The addresses of the devices to be jogged. </param>
 /// <returns> True if the device was jogged succesfully. </returns>
 /// <seealso cref="Home(List<char>, ELLBaseDevice.DeviceDirection)"/>
 /// <seealso cref="MoveAbsolute(List<char>, decimal)"/>
 /// <seealso cref="MoveRelative(List<char>, decimal)"/>
 /// <seealso cref="JogForward(List<char>)"/>
 /// <seealso cref="JogBackward(List<char>)"/>
 public bool JogForward(List <char> addresses)
 {
     if (!addresses.Any())
     {
         return(JogForward());
     }
     SetToGroupAddress(addresses);
     UpdateOutput(string.Format("Jog Forward {0}", DeviceInfo.FormatPosition(_jogstepSize, true, true)));
     ELLDevicePort.SendString(Address, "fw");
     if (!WaitForPositions(addresses))
     {
         return(false);
     }
     return(true);
 }
Пример #21
0
 public bool MoveRelative(PolarizerPaddlePositions displacements)
 {
     try
     {
         int encodedPosition = GetEncodedPosition(displacements, true);
         UpdateOutput(string.Format("Move paddles by {0},{1},{2}...", displacements.Paddle1, displacements.Paddle2, displacements.Paddle3));
         ELLDevicePort.SendStringI32(Address, "mr", encodedPosition);
         return(WaitForPositions());
     }
     catch (OverflowException)
     {
         UpdateOutput(string.Format("Parameter out of range {0},{1},{2}...", displacements.Paddle1, displacements.Paddle2, displacements.Paddle3));
     }
     return(false);
 }
Пример #22
0
        /// <summary> Move the current stage to an absolute position. </summary>
        /// <param name="position"> The required position. </param>
        /// <returns> True if the stage was moved succesfully. </returns>
        /// <seealso cref="Position"/>
        /// <seealso cref="GetPosition()"/>
        /// <seealso cref="MoveRelative(decimal)"/>
        /// <seealso cref="MoveAbsolute(List<char>, decimal)"/>
        /// <seealso cref="MoveRelative(List<char>, decimal)"/>
        public bool MoveAbsolute(decimal position)
        {
            if (IsDeviceBusy())
            {
                return(false);
            }
            UpdateOutput(string.Format("Move device to {0}...", DeviceInfo.FormatPosition(position, true, true)));
            int pulses = DeviceInfo.UnitToPulse(position);

            ELLDevicePort.SendStringI32(Address, "ma", pulses);
            if (!WaitForPosition())
            {
                return(false);
            }
            return(true);
        }
Пример #23
0
 /// <summary> Sets the group address for the given devices. </summary>
 /// <param name="addresses"> The addresses of devices to join the group. </param>
 /// <returns> True if the function completed succesfully. </returns>
 public bool SetToGroupAddress(IEnumerable <char> addresses)
 {
     foreach (char address in addresses)
     {
         if (address != Address)
         {
             UpdateOutput(string.Format("Set GroupAddress {0}->{1}...", address, Address));
             ELLDevicePort.SendStringB(address, "ga", (byte)Address);
             if (!WaitForStatus(Address))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Пример #24
0
 /// <summary> Search for the device period. </summary>
 /// <param name="motorID">   Identifier for the motor. </param>
 /// <param name="permanent"> True to change the period permanently. </param>
 /// <returns> True if the period is set. </returns>
 public bool SearchPeriod(char motorID, bool permanent)
 {
     if (!IsMotorIdValid(motorID))
     {
         return(false);
     }
     UpdateOutput(string.Format("Motor{0} - Search period ...", motorID));
     ELLDevicePort.SendString(Address, "s" + motorID);
     if (!WaitForStatus(SearchTimeout))
     {
         return(false);
     }
     GetMotorInfo(motorID);
     if (permanent)
     {
         SaveUserData();
     }
     return(true);
 }
Пример #25
0
 private bool WaitForPositions(List <char> addresses, int msTimeout = MoveTimeout)
 {
     try
     {
         Dictionary <char, bool> _isCompletedList = addresses.ToDictionary(c => c, c => false);
         List <string>           responses        = new List <string> {
             "GS", "PO"
         };
         int counter = 10 * addresses.Count;
         while (true)
         {
             string msg = ELLDevicePort.WaitForResponse(addresses, responses, msTimeout);
             if (!string.IsNullOrEmpty(msg))
             {
                 bool returnValue;
                 if (TestStatus(msg, "gp", true, ref counter, out returnValue))
                 {
                     return(returnValue);
                 }
                 char address = msg[0];
                 if ((msg.Substring(1, 2) == "PO") && addresses.Contains(address))
                 {
                     if (msg.Length != 11)
                     {
                         return(false);
                     }
                     _position = DeviceInfo.PulseToUnit(msg.Substring(3).ToBytes(8).ToInt(true));
                     UpdateParameter(MessageUpdater.UpdateTypes.Position, address, _position);
                     _isCompletedList[address] = true;
                     if (_isCompletedList.All(item => item.Value))
                     {
                         return(true);
                     }
                 }
             }
         }
     }
     catch (ELLException ex)
     {
         UpdateOutput($"Get Device Status: {ex.Message}", true);
     }
     return(false);
 }
Пример #26
0
 /// <summary> Homes the given stages. </summary>
 /// <param name="addresses"> The list of addresses of devices to be homed. </param>
 /// <param name="direction"> The home direction. </param>
 /// <returns> Success. </returns>
 /// <seealso cref="Home(ELLBaseDevice.DeviceDirection)"/>
 /// <seealso cref="MoveAbsolute(List<char>, decimal)"/>
 /// <seealso cref="MoveRelative(List<char>, decimal)"/>
 /// <seealso cref="JogForward(List<char>)"/>
 /// <seealso cref="JogBackward(List<char>)"/>
 public bool Home(List <char> addresses, DeviceDirection direction = DeviceDirection.Linear)
 {
     if (IsDeviceBusy())
     {
         return(false);
     }
     if (!addresses.Any())
     {
         return(Home(direction));
     }
     SetToGroupAddress(addresses);
     UpdateOutput("Homing device ...");
     ELLDevicePort.SendString(Address, "ho" + (int)direction);
     if (!WaitForPositions(addresses))
     {
         return(false);
     }
     return(true);
 }
Пример #27
0
        /// <summary> Move the given stages to an absolute position. </summary>
        /// <param name="addresses"> The addresses of the devices to be moved. </param>
        /// <param name="position"> The required position. </param>
        /// <returns> True if the stages were moved succesfully. </returns>
        /// <seealso cref="Home(List<char>, ELLBaseDevice.DeviceDirection)"/>
        /// <seealso cref="MoveAbsolute(List<char>, decimal)"/>
        /// <seealso cref="MoveRelative(List<char>, decimal)"/>
        /// <seealso cref="JogForward(List<char>)"/>
        /// <seealso cref="JogBackward(List<char>)"/>
        public bool MoveAbsolute(List <char> addresses, decimal position)
        {
            if (IsDeviceBusy())
            {
                return(false);
            }
            if (!addresses.Any())
            {
                return(MoveAbsolute(position));
            }
            SetToGroupAddress(addresses);
            UpdateOutput(string.Format("Move device to {0}...", DeviceInfo.FormatPosition(position, true, true)));
            int pulses = DeviceInfo.UnitToPulse(position);

            ELLDevicePort.SendStringI32(Address, "ma", pulses);
            if (!WaitForPositions(addresses))
            {
                return(false);
            }
            return(true);
        }
Пример #28
0
 private bool WaitForPosition(PaddleIDs paddleID, int msTimeout = MoveTimeout)
 {
     try
     {
         string        command   = $"p{(char)paddleID}";
         string        response  = $"P{(char)paddleID}";
         List <string> responses = new List <string> {
             "GS", response
         };
         int counter = 10;
         while (true)
         {
             string msg = ELLDevicePort.WaitForResponse(Address, responses, msTimeout);
             if (!string.IsNullOrEmpty(msg))
             {
                 bool returnValue;
                 if (TestStatus(msg, command, true, ref counter, out returnValue))
                 {
                     return(returnValue);
                 }
                 if (msg.Substring(1, 2) == response)
                 {
                     if (msg.Length != 7)
                     {
                         return(false);
                     }
                     PaddlePosition position = GetPosition(msg.Substring(3).ToBytes(4).ToInt(true), paddleID);
                     UpdateParameter(MessageUpdater.UpdateTypes.PaddlePosition, Address, position);
                     return(true);
                 }
             }
         }
     }
     catch (ELLException ex)
     {
         UpdateOutput($"Get Device Status: {ex.Message}", true);
     }
     return(false);
 }
Пример #29
0
 /// <summary>   Move microsecond steps. </summary>
 /// <param name="paddleID"> Identifier for the paddle. </param>
 /// <param name="timeMS">   The time in milliseconds. </param>
 /// <param name="backward"> True to backward. </param>
 /// <returns>   True if it succeeds, false if it fails. </returns>
 public bool MoveMicrosecondSteps(PaddleIDs paddleID, short timeMS, bool backward)
 {
     try
     {
         if (timeMS < 0 || timeMS > 8000)
         {
             throw new ArgumentOutOfRangeException($"Range 0 to 8000");
         }
         if (backward)
         {
             timeMS = (short)((timeMS & 0x1FFF) | 0x8000);
         }
         UpdateOutput(string.Format("Move paddle {0} for {1} ms...", (char)paddleID, timeMS));
         ELLDevicePort.SendStringI16(Address, $"t{(char)paddleID}", timeMS);
         return(WaitForPosition(paddleID));
     }
     catch (OverflowException)
     {
         UpdateOutput(string.Format("Parameter out of range {0}...", timeMS));
     }
     return(false);
 }
Пример #30
0
        public bool ResetPeriod()
        {
            List <char> _motors = _motorInfo.Where(kvp => (kvp.Value != null) && (kvp.Value.IsValid)).Select(kvp => kvp.Key).ToList();

            foreach (char motorID in _motors)
            {
                UpdateOutput(string.Format("Motor{0} - Reset default period ...", motorID));
                UInt16 period = (Int16)(14740 / 100) | 0x8000;
                ELLDevicePort.SendStringI16(Address, "f" + motorID, period);
                if (!WaitForStatus(SearchTimeout))
                {
                    return(false);
                }
                ELLDevicePort.SendStringI16(Address, "b" + motorID, period);
                if (!WaitForStatus(SearchTimeout))
                {
                    return(false);
                }
                GetMotorInfo(motorID);
            }
            SaveUserData();
            return(true);
        }