Class QUARCTarget

java.lang.Object
com.quanser.quarc.target.QUARCTarget

public class QUARCTarget extends Object
The QUARCTarget class is the main interface to a QUARC Target. It communicates with the QUARC Target Manager running on the target, allowing the models running on the target to be controlled and monitored.
  • Constructor Details

    • QUARCTarget

      public QUARCTarget()
      Constructs an unconnected QUARCTarget object. One of the connect methods must be called before using the other methods of this object.
    • QUARCTarget

      public QUARCTarget(URI uri, int sendBufferSize, int receiveBufferSize) throws IOException
      Constructs a QUARCTarget object and connects to the given target URI using the specified buffer sizes.
      Parameters:
      uri - A URI identifying the target.
      sendBufferSize - The size of the send buffer to use for communications with the target.
      receiveBufferSize - The size of the receive buffer to use for communications with the target.
      Throws:
      IOException - Failed to connect to target
    • QUARCTarget

      public QUARCTarget(String uri, int sendBufferSize, int receiveBufferSize) throws IOException, URISyntaxException
      Constructs a QUARCTarget object and connects to the given target URI using the specified buffer sizes.
      Parameters:
      uri - A URI string identifying the target.
      sendBufferSize - The size of the send buffer to use for communications with the target.
      receiveBufferSize - The size of the receive buffer to use for communications with the target.
      Throws:
      IOException - Failed to connect to target
      URISyntaxException - Invalid URI specified
    • QUARCTarget

      public QUARCTarget(URI uri) throws IOException
      Constructs a QUARCTarget object and connects to the target. Default buffer sizes will be used for communications with the target.
      Parameters:
      uri - A URI identifying the target.
      Throws:
      IOException - Failed to connect to target
    • QUARCTarget

      public QUARCTarget(String uri) throws URISyntaxException, IOException
      Creates a QUARCTarget object and connects to the given target. Default buffer sizes will be used for communications with the target.
      Parameters:
      uri - A URI string identifying the target.
      Throws:
      IOException - Failed to connect to target
      URISyntaxException - Invalid URI specified
  • Method Details

    • connect

      public void connect(URI uri, int sendBufferSize, int receiveBufferSize) throws IOException
      Connect to the target using the specified buffer sizes.
      Parameters:
      uri - A URI identifying the target.
      sendBufferSize - The size of the send buffer to use for communications with the target.
      receiveBufferSize - The size of the receive buffer to use for communications with the target.
      Throws:
      IOException - Failed to connect to target
    • connect

      public void connect(String uri, int sendBufferSize, int receiveBufferSize) throws IOException, URISyntaxException
      Connect to the target using the specified buffer sizes.
      Parameters:
      uri - A URI string identifying the target.
      sendBufferSize - The size of the send buffer to use for communications with the target.
      receiveBufferSize - The size of the receive buffer to use for communications with the target.
      Throws:
      IOException - Failed to connect to target
      URISyntaxException - Invalid URI specified
    • connect

      public void connect(URI uri) throws IOException
      Connect to the target. Default buffer sizes will be used for communications with the target.
      Parameters:
      uri - A URI identifying the target.
      Throws:
      IOException - Failed to connect to target
    • connect

      public void connect(String uri) throws URISyntaxException, IOException
      Connect to the target. Default buffer sizes will be used for communications with the target.
      Parameters:
      uri - A URI string identifying the target.
      Throws:
      IOException - Failed to connect to target
      URISyntaxException - Invalid URI specified
    • downloadModel

      public int downloadModel(String name, String generator, String path, ModelDownload callback, Object context) throws IOException
      Download a model to the target via a callback interface. This method may be used to provide a progress dialog showing the progress of the download, or it may be used to download code from other sources, such as a web site or socket connection.
      Parameters:
      name - Name of the model
      generator - Application which generated the model. e.g. "simulink"
      path - Path to the model. This string need may be a virtual path that does not reside on a file system, but it typically does. This path is not used to load the code.
      callback - A ModelDownload interface that is called to retrieve the code of the model.
      context - An object to pass to the ModelDownload interface methods. This parameter is provided for convenience. It is not processed in any way by the downloadModel method.
      Returns:
      The total number of bytes downloaded to the target.
      Throws:
      IOException - Failed to download the code to the target.
    • downloadModelFile

      public void downloadModelFile(String generator, String path) throws IOException
      Download a model file to the target.
      Parameters:
      generator - Application which generated the model. e.g. "simulink"
      path - Full path to the model executable. If the extension is omitted then the extension will be deduced from the type of target to which this object is connected. The model name is extracted from the path.
      Throws:
      IOException - Failed to download the code to the target.
    • getDownloadedModels

      public List<String> getDownloadedModels() throws IOException
      Get a list of the models that have been downloaded to the target.
      Returns:
      Returns a list of strings containing the names of the models.
      Throws:
      IOException - Failed to get a list of the models that have been downloaded to the target.
    • removeDownloadedModel

      public void removeDownloadedModel(String name) throws IOException
      Remove a model that has been downloaded to the target.
      Parameters:
      name - Name of the model to remove.
      Throws:
      IOException - Failed to remove the code from the target.
    • loadModel

      public void loadModel(String name, String arguments) throws IOException
      Load the model on the target. The arguments are passed to the model via the command line.
      Parameters:
      name - Name of the model to load.
      arguments - Arguments to pass to the model.
      Throws:
      IOException - Failed to load the code on the target.
    • getLoadedModels

      public List<String> getLoadedModels(boolean includeArguments) throws IOException
      Get a list of the models that are currently loaded on the target and optionally show the command line.
      Parameters:
      includeArguments - Set to true to include the model arguments in the returned strings.
      Returns:
      Returns a list of strings containing the names of and optionally the arguments to the models.
      Throws:
      IOException - Failed to get a list of the models loaded on the target.
    • getLoadedModels

      public List<String> getLoadedModels() throws IOException
      Get a list of the models that are loaded on the target.
      Returns:
      Returns a list of strings containing the names of the models.
      Throws:
      IOException - Failed to get a list of the models loaded on the target.
    • stopModel

      public void stopModel(String name) throws IOException
      Stop a model on the target. If the model is not loaded on the target then an exception is thrown.
      Parameters:
      name - Name of the model to stop.
      Throws:
      IOException - Failed to stop the code on the target.
    • killModel

      public void killModel(String name) throws IOException
      Kill a model on the target. This method should generally not be used because it forcefully terminates the model on the target and resources may be lost. Use the stopModel(java.lang.String) method instead.
      Parameters:
      name - Name of the model to kill.
      Throws:
      IOException - Failed to kill the code on the target.
    • isModelLoaded

      public boolean isModelLoaded(String name) throws IOException
      Indicates whether a model is currently loaded on the target.
      Parameters:
      name - Name of the model to check.
      Returns:
      True if the model is currently loaded and false otherwise.
      Throws:
      IOException - Failed to check whether the model is loaded on the target.
    • switchToModel

      public void switchToModel(String name, String arguments, int groupId) throws IOException
      Switches to the specified model dynamically from the model currently running as a member of the given reconfiguration group.
      Parameters:
      name - Name of the model to which to switch
      arguments - Arguments to pass to the model being loaded
      groupId - Reconfiguration group identifier of the model to switch out
      Throws:
      IOException - Failed to switch models on the target.
    • loadModelAtBoot

      public void loadModelAtBoot(String name, String arguments) throws IOException
      Configure a model to load at boot on the target. The arguments are passed to the model via the command line.
      Parameters:
      name - Name of the model to load at boot.
      arguments - Arguments to pass to the model when it is loaded.
      Throws:
      IOException - Failed to configure model to load at boot on a target.
    • getModelsLoadedAtBoot

      public List<String> getModelsLoadedAtBoot(boolean includeArguments) throws IOException
      Get a list of the models that are loaded at boot on the target and optionally show the command line.
      Parameters:
      includeArguments - Set to true to include the model arguments in the returned strings.
      Returns:
      Returns a list of strings containing the names of the models.
      Throws:
      IOException - Failed to retrieve a list of the model is loaded at boot.
    • getModelsLoadedAtBoot

      public List<String> getModelsLoadedAtBoot() throws IOException
      Get a list of the models that are loaded at boot on the target.
      Returns:
      Returns a list of strings containing the names of the models.
      Throws:
      IOException - Failed to retrieve a list of the model is loaded at boot.
    • removeModelLoadedAtBoot

      public void removeModelLoadedAtBoot(String name) throws IOException
      Remove a model from the list of models loaded at boot on the target.
      Parameters:
      name - Name of the model to no longer load at boot.
      Throws:
      IOException - Failed to remove model from the list of models configured to load at boot on a target.
    • getTargetType

      public String getTargetType() throws IOException
      Returns the type of the target to which this object is connected.
      Returns:
      The type of the target
      Throws:
      IOException - Failed to remove model from the list of models configured to load at boot on a target.
    • getURIs

      public Map<String,URI> getURIs() throws IOException
      Get a map containing the URIs upon which the target is listening. URIs used by the target are associated with a key, which is typically a short string such as "TCPIP". The value associated with each key is the URI itself, such as "tcpip://localhost:18000".
      Returns:
      Returns a map containing the URIs. Each URI is associated with a string (the key). To get a list of the URIs only, call the Map.values() method.
      Throws:
      IOException - Failed to retrieve the list of URIs upon which the target is listening.
    • addURI

      public void addURI(String key, URI uri) throws IOException
      Add a URI upon which the target should listen.
      Parameters:
      key - A key used to identify the URI
      uri - The URI upon which the target should listen
      Throws:
      IOException - Failed to add the URI upon which the target should listen.
    • addURI

      public void addURI(String key, String uri) throws IOException, URISyntaxException
      Add a URI upon which the target should listen.
      Parameters:
      key - A key used to identify the URI
      uri - The URI upon which the target should listen
      Throws:
      IOException - Failed to add the URI upon which the target should listen.
      URISyntaxException - Invalid URI specified
    • removeURI

      public void removeURI(String key) throws IOException
      Remove a URI upon which the target is listening.
      Parameters:
      key - The key used to identify the URI
      Throws:
      IOException - Failed to remove the URI upon which the target is listening.
    • addModelOutputListener

      public void addModelOutputListener(String name, ModelOutputListener listener) throws IOException, InterruptedException
      Add a ModelOutputListener to process model events such as the model being downloaded, loaded or terminated, as well as receiving console output from the specified model.
      Parameters:
      name - The name of the model for which events are to be reported. Use "*" to receive notifications for any model.
      listener - A ModelOutputListener whose methods are called as events occur for the given model.
      Throws:
      IOException - Failed to add model output notifications.
      InterruptedException - The operation was interrupted while waiting for model notifications to be established.
    • removeModelOutputListener

      public boolean removeModelOutputListener(String name, ModelOutputListener listener) throws IOException
      Remove a ModelOutputListener that was processing model events such as the model being downloaded, loaded or terminated, as well as receiving console output from the specified model.
      Parameters:
      name - The name of the model for which events are no longer to be reported. Use "*" for notifications received for any model.
      listener - The ModelOutputListener whose methods were being called as events occurred for the given model.
      Returns:
      True if the listener was in the list associated with the given model
      Throws:
      IOException - Failed to shut down model output notifications from the target.
    • writeModelInput

      public void writeModelInput(String name, String text) throws IOException
      Write to the standard input (stdin) of a loaded model.
      Parameters:
      name - Name of the model.
      text - Text to write to stdin.
      Throws:
      IOException - Failed to write to the model's standard input.
    • close

      public void close() throws IOException
      Close the connection to the target. The other methods of this object should not be used until the one of the connect methods has been called to connect to another target.
      Throws:
      IOException - Failed to close the connection to the target