Class ScriptDrivenScannableMotionUnits

java.lang.Object
gda.device.scannable.ScriptDrivenScannableMotionUnits
All Implemented Interfaces:
Device, Scannable, ScannableMotion, ScannableMotionUnits, Configurable, Findable, gda.observable.IObservable, org.springframework.beans.factory.InitializingBean

public class ScriptDrivenScannableMotionUnits extends Object implements ScannableMotionUnits, org.springframework.beans.factory.InitializingBean
Class to wrap a ScannableMotionUnits that is to be driven by a script. The command to be executed is generated by the code: String.format(commandFormat, (Object []) ScannableUtils.objectToArray(position)); This allows the position to have multiple parts providing the script command can accept them moveTo uses the evaluateCommand method of the ICommandRunner. If the script returns a string of length>0 then a DeviceException is raised Note moveTo is blocking so should not be called from the GUI thread asynchronousMoveTo uses the runCommand method of the ICommandRunner. No indication is given to the caller if the script fails. Note that runCommand in jython server always spawns a new thread to run the command so the source scannnable may not be busy as soon as runCommand is started. In fact as the script may be doing various other things before trying to move the scannable motor this will not be that case. e.g. scannableUnderTest.setCommandFormat("myscript(%5.5g)"); scannableUnderTest.setSource(scannableMotor); scannableUnderTest.setCommandRunner(InterfaceProvider.getCommandRunner()) scannableUnderTest.afterPropertiesSet(); where def myscript(new_position): ... scannableMotor.asynchronousMoveTo(newPos); ...
  • Constructor Details

    • ScriptDrivenScannableMotionUnits

      public ScriptDrivenScannableMotionUnits()
  • Method Details

    • getScannable

      public ScannableMotionUnits getScannable()
    • setScannable

      public void setScannable(ScannableMotionUnits scannable)
    • getCommandRunner

      public ICommandRunner getCommandRunner()
    • setCommandRunner

      public void setCommandRunner(ICommandRunner commandRunner)
    • getCommandFormat

      public String getCommandFormat()
    • setCommandFormat

      public void setCommandFormat(String commandFormat)
    • setName

      public void setName(String name)
      Description copied from interface: Findable
      Set or change the name of the object (as defined in XML).
      Specified by:
      setName in interface Findable
      Parameters:
      name - the object name
    • configure

      public void configure() throws FactoryException
      Description copied from interface: Configurable
      Perform operations that must be done after Spring initialisation i.e. anything that goes beyond setting member variables.
      Specified by:
      configure in interface Configurable
      Throws:
      FactoryException - if there is an error in configuration e.g. required variable not set or cannot connect to device
    • isConfigured

      public boolean isConfigured()
      Description copied from interface: Configurable
      Checks to see if the object is already configured.
      Specified by:
      isConfigured in interface Configurable
      Returns:
      return true if configured false otherwise
    • reconfigure

      public void reconfigure() throws FactoryException
      Description copied from interface: Configurable
      Re-initialisation of values and states.

      Moved from Reconfigurable which has been deleted

      Specified by:
      reconfigure in interface Configurable
      Throws:
      FactoryException
    • isConfigureAtStartup

      public boolean isConfigureAtStartup()
      Description copied from interface: Configurable
      Indicates whether this object should be configured at startup.

      Moved from ConditionallyConfigurable which has been deleted

      Specified by:
      isConfigureAtStartup in interface Configurable
    • getPosition

      public Object getPosition() throws DeviceException
      Description copied from interface: Scannable
      Returns the current position of the Scannable. Called by ConcurentScan at the end of the point.
      Specified by:
      getPosition in interface Scannable
      Returns:
      Current position with an element for each input and extra field. null if their are no fields.
      Throws:
      DeviceException
    • getName

      public String getName()
      Description copied from interface: Findable
      Get the object name. Used by Castor to check if the object name has been set before calling the Findable.setName(String) method.
      Specified by:
      getName in interface Findable
      Returns:
      a String containing the object name.
    • setAttribute

      public void setAttribute(String attributeName, Object value) throws DeviceException
      Description copied from interface: Device
      Set any attribute the implementing classes may provide
      Specified by:
      setAttribute in interface Device
      Parameters:
      attributeName - is the name of the attribute
      value - is the value of the attribute
      Throws:
      DeviceException - if an attribute cannot be set
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getUserUnits

      public String getUserUnits()
      Description copied from interface: ScannableMotionUnits
      Returns a string representation of the current reporting units
      Specified by:
      getUserUnits in interface ScannableMotionUnits
      Returns:
      Returns the reportingUnitsString.
    • checkPositionWithinGdaLimits

      public String checkPositionWithinGdaLimits(Double[] externalPosition)
      Description copied from interface: ScannableMotion
      Returns null if okay, or a descriptive error if not. Code only called if limits are set.
      Specified by:
      checkPositionWithinGdaLimits in interface ScannableMotion
      Parameters:
      externalPosition - position in external representation
      Returns:
      null if okay, or a descriptive error if not
    • setUserUnits

      public void setUserUnits(String userUnitsString) throws DeviceException
      Description copied from interface: ScannableMotionUnits
      Sets the user unit to userUnitString. If a hardware unit has not been explicitly set, then the hardware unit is also set to userUnitString. If a hardware unit has been set, and the userUnit is not compatible with this, then a DeviceException is thrown.
      Specified by:
      setUserUnits in interface ScannableMotionUnits
      Parameters:
      userUnitsString - The reportingUnitsString to set.
      Throws:
      DeviceException - if string not found in list of acceptable units
    • moveTo

      public void moveTo(Object position) throws DeviceException
      Description copied from interface: Scannable
      Trigger a move/operation and block until completion.
      Specified by:
      moveTo in interface Scannable
      Parameters:
      position -
      Throws:
      DeviceException
    • getAttribute

      public Object getAttribute(String attributeName) throws DeviceException
      Description copied from interface: Device
      Get the value of the specified attribute
      Specified by:
      getAttribute in interface Device
      Parameters:
      attributeName - is the name of the attribute
      Returns:
      the value of the attribute as an Object type
      Throws:
      DeviceException - if an attribute cannot be retrieved
    • asynchronousMoveTo

      public void asynchronousMoveTo(Object position) throws DeviceException
      Description copied from interface: Scannable
      Trigger a move/operation and return immediately. Implementations of this method should be non-blocking to allow concurrent motion; the isBusy method will be used to determine when the move has completed.
      Specified by:
      asynchronousMoveTo in interface Scannable
      Parameters:
      position - Position to move to should have an element for each input field.
      Throws:
      DeviceException
    • checkPositionWithinGdaLimits

      public String checkPositionWithinGdaLimits(Object externalPosition)
      Description copied from interface: ScannableMotion
      Returns null if okay, or a descriptive error if not. Code only called if limits are set.
      Specified by:
      checkPositionWithinGdaLimits in interface ScannableMotion
      Parameters:
      externalPosition - position in external representation
      Returns:
      null or description of any error
    • close

      public void close() throws DeviceException
      Description copied from interface: Device
      Close and unconfigure the device.
      Specified by:
      close in interface Device
      Throws:
      DeviceException
    • setProtectionLevel

      public void setProtectionLevel(int newLevel)
      Description copied from interface: Device
      Sets the permission level for this object. If this is not set then a default value will be applied.
      Specified by:
      setProtectionLevel in interface Device
      Parameters:
      newLevel -
    • getHardwareUnitString

      public String getHardwareUnitString()
      Specified by:
      getHardwareUnitString in interface ScannableMotionUnits
      Returns:
      Returns the motorUnitString.
    • setLowerGdaLimits

      public void setLowerGdaLimits(Double[] externalLowerLim) throws Exception
      Description copied from interface: ScannableMotion
      Set lower Scannable limits in external representation. Setting the input null will remove lower limits from the Scannable. Otherwise, any element can be null indicating that the corresponding field has no limit.
      Specified by:
      setLowerGdaLimits in interface ScannableMotion
      Parameters:
      externalLowerLim - limit in external representation
      Throws:
      Exception
    • setHardwareUnitString

      public void setHardwareUnitString(String hardwareUnitString) throws DeviceException
      Description copied from interface: ScannableMotionUnits
      Sets the hardware unit to hardwareUnitString. If a user unit has not been explicitly set then the user unit is also set to hardwareUnitString. If the user unit has been explicitly set and the new hardware unit would invalidate this then a DeviceException is thrown.

      Based on this string, this method will build a list of acceptable user-units. Afterwards, the acceptable units list can be added to via the addAcceptableUnits method if the defaults do not cover enough.

      Specified by:
      setHardwareUnitString in interface ScannableMotionUnits
      Parameters:
      hardwareUnitString - The motorUnitString to set.
      Throws:
      DeviceException
    • getProtectionLevel

      public int getProtectionLevel()
      Specified by:
      getProtectionLevel in interface Device
      Returns:
      int - the permission level for this object.
    • setLowerGdaLimits

      public void setLowerGdaLimits(Double externalLowerLim) throws Exception
      Description copied from interface: ScannableMotion
      Set lower Scannable limit in external representation. Setting the input null will remove the lower limit from the Scannable.
      Specified by:
      setLowerGdaLimits in interface ScannableMotion
      Parameters:
      externalLowerLim - limit in external representation
      Throws:
      Exception
    • stop

      public void stop() throws DeviceException
      Description copied from interface: Scannable
      Stop the current move/operation.
      Specified by:
      stop in interface Scannable
      Throws:
      DeviceException
    • isBusy

      public boolean isBusy() throws DeviceException
      Description copied from interface: Scannable
      Check if the Scannable is moving/operating.
      Specified by:
      isBusy in interface Scannable
      Returns:
      true - if operation carried out by moveTo has not completed yet
      Throws:
      DeviceException
    • getLowerGdaLimits

      public Double[] getLowerGdaLimits()
      Description copied from interface: ScannableMotion
      Get lower Scannable limits in external representation. Will be null if no lower limits are set. Otherwise, any element can be null indicating that the corresponding field has no limit.
      Specified by:
      getLowerGdaLimits in interface ScannableMotion
      Returns:
      Double[] limit in external representation
    • getAcceptableUnits

      public String[] getAcceptableUnits()
      Specified by:
      getAcceptableUnits in interface ScannableMotionUnits
      Returns:
      Returns the acceptableUnitStrings.
    • addAcceptableUnit

      public void addAcceptableUnit(String newUnit) throws DeviceException
      Description copied from interface: ScannableMotionUnits
      Adds a new unit to the list of acceptable units based on the supllied string
      Specified by:
      addAcceptableUnit in interface ScannableMotionUnits
      Parameters:
      newUnit - - string representation of the new acceptable unit
      Throws:
      DeviceException
    • waitWhileBusy

      public void waitWhileBusy() throws DeviceException, InterruptedException
      Description copied from interface: Scannable
      Returns when operation carried out by moveTo has completed
      Specified by:
      waitWhileBusy in interface Scannable
      Throws:
      DeviceException
      InterruptedException
    • setUpperGdaLimits

      public void setUpperGdaLimits(Double[] externalUpperLim) throws Exception
      Description copied from interface: ScannableMotion
      Set upper Scannable limits in external representation. Setting the input null will remove upper limits from the Scannable. Otherwise, any element can be null indicating that the corresponding field has no limit.
      Specified by:
      setUpperGdaLimits in interface ScannableMotion
      Parameters:
      externalUpperLim - limit in external representation
      Throws:
      Exception
    • isAt

      public boolean isAt(Object positionToTest) throws DeviceException
      Description copied from interface: Scannable
      Tests if the scannable is at (or if appropriate, close to) the value positionToTest.
      Specified by:
      isAt in interface Scannable
      Parameters:
      positionToTest - The position to compare the scannable's position to.
      Returns:
      true if scannable is at positionToTest
      Throws:
      DeviceException
    • setOffset

      public void setOffset(Object offsetPositionInExternalUnits)
      Description copied from interface: ScannableMotionUnits
      Set offset(s) in amounts of external quantities as ScannableMotion.setOffset(Double...), but allows any position container containing objects that may be quantities. ScannableMotion.setOffset(Double...)
      Specified by:
      setOffset in interface ScannableMotionUnits
      Parameters:
      offsetPositionInExternalUnits -
    • setUpperGdaLimits

      public void setUpperGdaLimits(Double externalUpperLim) throws Exception
      Description copied from interface: ScannableMotion
      Set upper Scannable limit in external representation. Setting the input null will remove the upper limit from the Scannable.
      Specified by:
      setUpperGdaLimits in interface ScannableMotion
      Parameters:
      externalUpperLim - limit in external representation
      Throws:
      Exception
    • setLevel

      public void setLevel(int level)
      Description copied from interface: Scannable
      Used for ordering the operations of Scannables during scans
      Specified by:
      setLevel in interface Scannable
      Parameters:
      level -
    • getLevel

      public int getLevel()
      Description copied from interface: Scannable
      get the operation level of this scannable.
      Specified by:
      getLevel in interface Scannable
      Returns:
      int - the level
    • getUpperGdaLimits

      public Double[] getUpperGdaLimits()
      Description copied from interface: ScannableMotion
      Get upper Scannable limits in external representation
      Specified by:
      getUpperGdaLimits in interface ScannableMotion
      Returns:
      Double[] limit in external representation
    • getInputNames

      public String[] getInputNames()
      Description copied from interface: Scannable
      gets a array of InputNames used by moveTo of this scannable.
      Specified by:
      getInputNames in interface Scannable
      Returns:
      array of the names of the elements of the object returned by getPosition
    • checkPositionValid

      public String checkPositionValid(Object position) throws DeviceException
      Description copied from interface: Scannable
      Tests if the given object is meaningful to this Scannable and so could be used by one of the move commands. May check limits and other things too. This is the method called by scans on all points before the scan is run.
      Specified by:
      checkPositionValid in interface Scannable
      Parameters:
      position -
      Returns:
      null if position is valid, or returns a description if not.
      Throws:
      DeviceException
    • setInputNames

      public void setInputNames(String[] names)
      Description copied from interface: Scannable
      sets the array of names returned by getInputNames method of this scannable.
      Specified by:
      setInputNames in interface Scannable
      Parameters:
      names -
    • getExtraNames

      public String[] getExtraNames()
      Description copied from interface: Scannable
      Additional names for extra values that returned by getPosition().
      Specified by:
      getExtraNames in interface Scannable
      Returns:
      array of names of the extra elements if the array returned by getPosition is larger than the array required by moveTo
    • setExtraNames

      public void setExtraNames(String[] names)
      Description copied from interface: Scannable
      Sets the array of names returned by getExtraNames of this scannable.
      Specified by:
      setExtraNames in interface Scannable
      Parameters:
      names -
    • getTolerances

      public Double[] getTolerances() throws DeviceException
      Description copied from interface: ScannableMotion
      Gets the scannables values of tolerance. If no values have been set then returns an array of zeros. This is for 'real world' motors which may not move to their desired location and do not throw an exception.
      Specified by:
      getTolerances in interface ScannableMotion
      Returns:
      Double[]
      Throws:
      DeviceException
    • setOutputFormat

      public void setOutputFormat(String[] names)
      Description copied from interface: Scannable
      Sets the array of strings describing how best to format the positions from this scannable
      Specified by:
      setOutputFormat in interface Scannable
      Parameters:
      names -
    • getOutputFormat

      public String[] getOutputFormat()
      Description copied from interface: Scannable
      Returns an array of strings which are the format strings to use when pretty printing parts of the output
      Specified by:
      getOutputFormat in interface Scannable
      Returns:
      string array
    • setTolerance

      public void setTolerance(Double tolerence) throws DeviceException
      Specified by:
      setTolerance in interface ScannableMotion
      Parameters:
      tolerence -
      Throws:
      DeviceException
    • setTolerances

      public void setTolerances(Double[] tolerence) throws DeviceException
      Specified by:
      setTolerances in interface ScannableMotion
      Parameters:
      tolerence -
      Throws:
      DeviceException
    • getNumberTries

      public int getNumberTries()
      Description copied from interface: ScannableMotion
      This is the number of times the Scannable should attempt to move to the target position. Useful when the underlying hardware is problematic and often fails or ignores calls without throwing an exception. This should be used in conjunction with setting the tolerance attribute.
      Specified by:
      getNumberTries in interface ScannableMotion
      Returns:
      the numberTries
    • atScanStart

      public void atScanStart() throws DeviceException
      Description copied from interface: Scannable
      Called for every Scannable at the start of a group of nested scans (or a single scan if that is the case)
      Specified by:
      atScanStart in interface Scannable
      Throws:
      DeviceException
    • atScanEnd

      public void atScanEnd() throws DeviceException
      Description copied from interface: Scannable
      Called for every Scannable at the end of a group of nested scans (or a single scan if that is the case).

      Note that this is only called if the Scan finishes normally, or has been requested to finish early. This will not be called if the scan finishes due to an exception of any kind. See Scannable.atCommandFailure()

      Specified by:
      atScanEnd in interface Scannable
      Throws:
      DeviceException
    • setNumberTries

      public void setNumberTries(int numberTries)
      Specified by:
      setNumberTries in interface ScannableMotion
      Parameters:
      numberTries - the numberTries to set
    • a

      public void a(Object position) throws DeviceException
      Specified by:
      a in interface ScannableMotion
      Throws:
      DeviceException
    • atScanLineStart

      public void atScanLineStart() throws DeviceException
      Description copied from interface: Scannable
      Called for every Scannable at the start of every scan
      Specified by:
      atScanLineStart in interface Scannable
      Throws:
      DeviceException
    • ar

      public void ar(Object position) throws DeviceException
      Specified by:
      ar in interface ScannableMotion
      Throws:
      DeviceException
    • r

      public void r(Object position) throws DeviceException
      Specified by:
      r in interface ScannableMotion
      Throws:
      DeviceException
    • setOffset

      public void setOffset(Double... offsetArray)
      Description copied from interface: ScannableMotion
      Set offset(s) in amounts of external quantities. May be null, or any element may be null, indicating no offset is to be applied/removed.
      Specified by:
      setOffset in interface ScannableMotion
      Parameters:
      offsetArray - must match number of input fields.
    • atScanLineEnd

      public void atScanLineEnd() throws DeviceException
      Description copied from interface: Scannable
      Called for every Scannable at the end of every scan
      Specified by:
      atScanLineEnd in interface Scannable
      Throws:
      DeviceException
    • atPointStart

      public void atPointStart() throws DeviceException
      Description copied from interface: Scannable
      Called on every Scannable at every data point, for scans which are broken down into individual points (i.e. non-continuous scans)
      Specified by:
      atPointStart in interface Scannable
      Throws:
      DeviceException
    • setScalingFactor

      public void setScalingFactor(Double... scaleArray)
      Description copied from interface: ScannableMotion
      Set scaling factor(s) as Doubles. May be null, or any element may be null, indicating no scale is to be applied/removed.
      Specified by:
      setScalingFactor in interface ScannableMotion
      Parameters:
      scaleArray - must match number of input fields.
    • atPointEnd

      public void atPointEnd() throws DeviceException
      Description copied from interface: Scannable
      Called on every Scannable at the end of every data point, for scans which are broken down into individual points (i.e. non-continous scans)
      Specified by:
      atPointEnd in interface Scannable
      Throws:
      DeviceException
    • getOffset

      public Double[] getOffset()
      Description copied from interface: ScannableMotion
      Returns offset(s) in amounts of external quantities. May be null, or any element may be null, indicating no offset is to be applied/removed.
      Specified by:
      getOffset in interface ScannableMotion
    • atLevelMoveStart

      public void atLevelMoveStart() throws DeviceException
      Description copied from interface: Scannable
      Called by both the pos and scan commands at the start of each subsequent level move only on Scannables that will be moved as part that level's movement.

      For example "pos a 1 b 2 c 3", will, if a and b have the same level and c a higher level will result in:

       a.atLevelMoveStart()   invalid input: '<'----
       b.atLevelMoveStart()   invalid input: '<'----
       a.asynchronousMoveTo()
       b.asynchronousMoveTo()
       a.waitWhileBusy()
       b.waitWhileBusy()
       c.atLevelMoveStart()   invalid input: '<'----
       c.asynchronousMoveTo()
       c.waitWhileBusy()
       
      This hook is used by CoordinatedMotionScannables.
      Specified by:
      atLevelMoveStart in interface Scannable
      Throws:
      DeviceException
    • atLevelStart

      public void atLevelStart() throws DeviceException
      Description copied from interface: Scannable
      Called by both the pos and scan commands at the start of each subsequent level move on all Scannables that are part that level's movement.

      This provides a useful mechanism for e.g. creating a Scannable that opens a shutter after motors have moved but before a detector is exposed.

      Specified by:
      atLevelStart in interface Scannable
      Throws:
      DeviceException
    • atLevelEnd

      public void atLevelEnd() throws DeviceException
      Specified by:
      atLevelEnd in interface Scannable
      Throws:
      DeviceException
    • getScalingFactor

      public Double[] getScalingFactor()
      Description copied from interface: ScannableMotion
      Returns scaling factor(s) as Doubles. May be null, or any element may be null, indicating no scale is to be applied/removed.
      Specified by:
      getScalingFactor in interface ScannableMotion
    • atCommandFailure

      public void atCommandFailure() throws DeviceException
      Description copied from interface: Scannable
      Hook to be used by Scan and pos commands to inform the Scannable that an exception, such as a DeviceExcpetion, has occurred. However not called when the command is aborted using an InterruptionException. If a Scan is aborted then only Scannable.stop() will be called by the Scan or pos command.

      Useful for telling Scannables which hold state during a scan for example, to reset themselves. Used for example by CoordinatedMotionScannables. This hook should be used not in the same way as the stop hook.

      Specified by:
      atCommandFailure in interface Scannable
      Throws:
      DeviceException
    • toFormattedString

      public String toFormattedString()
      Description copied from interface: Scannable
      Returns a string representation of the Scannable and its current position/value/status

      Typically should return:

      name : position

      or for detectors, name : status

      If the position/status cannot be determined, the function should return Scannable.VALUE_UNAVAILABLE in its place.

      Specified by:
      toFormattedString in interface Scannable
      Returns:
      string as defined above
    • addIObserver

      public void addIObserver(gda.observable.IObserver anIObserver)
      Specified by:
      addIObserver in interface gda.observable.IObservable
    • deleteIObserver

      public void deleteIObserver(gda.observable.IObserver anIObserver)
      Specified by:
      deleteIObserver in interface gda.observable.IObservable
    • deleteIObservers

      public void deleteIObservers()
      Specified by:
      deleteIObservers in interface gda.observable.IObservable
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      Exception