Package com.quanser.quarc.target
Class QUARCTarget
java.lang.Object
com.quanser.quarc.target.QUARCTarget
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 Summary
ConstructorDescriptionConstructs an unconnectedQUARCTarget
object.QUARCTarget
(String uri) Creates aQUARCTarget
object and connects to the given target.QUARCTarget
(String uri, int sendBufferSize, int receiveBufferSize) Constructs aQUARCTarget
object and connects to the given target URI using the specified buffer sizes.QUARCTarget
(URI uri) Constructs aQUARCTarget
object and connects to the target.QUARCTarget
(URI uri, int sendBufferSize, int receiveBufferSize) Constructs aQUARCTarget
object and connects to the given target URI using the specified buffer sizes. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addModelOutputListener
(String name, ModelOutputListener listener) Add aModelOutputListener
to process model events such as the model being downloaded, loaded or terminated, as well as receiving console output from the specified model.void
Add a URI upon which the target should listen.void
Add a URI upon which the target should listen.void
close()
Close the connection to the target.void
Connect to the target.void
Connect to the target using the specified buffer sizes.void
Connect to the target.void
Connect to the target using the specified buffer sizes.int
downloadModel
(String name, String generator, String path, ModelDownload callback, Object context) Download a model to the target via a callback interface.void
downloadModelFile
(String generator, String path) Download a model file to the target.Get a list of the models that have been downloaded to the target.Get a list of the models that are loaded on the target.getLoadedModels
(boolean includeArguments) Get a list of the models that are currently loaded on the target and optionally show the command line.Get a list of the models that are loaded at boot on the target.getModelsLoadedAtBoot
(boolean includeArguments) Get a list of the models that are loaded at boot on the target and optionally show the command line.Returns the type of the target to which this object is connected.getURIs()
Get a map containing the URIs upon which the target is listening.boolean
isModelLoaded
(String name) Indicates whether a model is currently loaded on the target.void
Kill a model on the target.void
Load the model on the target.void
loadModelAtBoot
(String name, String arguments) Configure a model to load at boot on the target.void
removeDownloadedModel
(String name) Remove a model that has been downloaded to the target.void
Remove a model from the list of models loaded at boot on the target.boolean
removeModelOutputListener
(String name, ModelOutputListener listener) Remove aModelOutputListener
that was processing model events such as the model being downloaded, loaded or terminated, as well as receiving console output from the specified model.void
Remove a URI upon which the target is listening.void
Stop a model on the target.void
switchToModel
(String name, String arguments, int groupId) Switches to the specified model dynamically from the model currently running as a member of the given reconfiguration group.void
writeModelInput
(String name, String text) Write to the standard input (stdin
) of a loaded model.
-
Constructor Details
-
QUARCTarget
public QUARCTarget()Constructs an unconnectedQUARCTarget
object. One of theconnect
methods must be called before using the other methods of this object. -
QUARCTarget
Constructs aQUARCTarget
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 aQUARCTarget
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 targetURISyntaxException
- Invalid URI specified
-
QUARCTarget
Constructs aQUARCTarget
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
Creates aQUARCTarget
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 targetURISyntaxException
- Invalid URI specified
-
-
Method Details
-
connect
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 targetURISyntaxException
- Invalid URI specified
-
connect
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
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 targetURISyntaxException
- 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 modelgenerator
- 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
- AModelDownload
interface that is called to retrieve the code of the model.context
- An object to pass to theModelDownload
interface methods. This parameter is provided for convenience. It is not processed in any way by thedownloadModel
method.- Returns:
- The total number of bytes downloaded to the target.
- Throws:
IOException
- Failed to download the code to the target.
-
downloadModelFile
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
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
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
Load the model on the target. Thearguments
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
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
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
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
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 thestopModel(java.lang.String)
method instead.- Parameters:
name
- Name of the model to kill.- Throws:
IOException
- Failed to kill the code on the target.
-
isModelLoaded
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
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 switcharguments
- Arguments to pass to the model being loadedgroupId
- Reconfiguration group identifier of the model to switch out- Throws:
IOException
- Failed to switch models on the target.
-
loadModelAtBoot
Configure a model to load at boot on the target. Thearguments
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
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
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
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
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
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
Add a URI upon which the target should listen.- Parameters:
key
- A key used to identify the URIuri
- The URI upon which the target should listen- Throws:
IOException
- Failed to add the URI upon which the target should listen.
-
addURI
Add a URI upon which the target should listen.- Parameters:
key
- A key used to identify the URIuri
- 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
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 aModelOutputListener
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
- AModelOutputListener
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 aModelOutputListener
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
- TheModelOutputListener
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
Write to the standard input (stdin
) of a loaded model.- Parameters:
name
- Name of the model.text
- Text to write tostdin
.- Throws:
IOException
- Failed to write to the model's standard input.
-
close
Close the connection to the target. The other methods of this object should not be used until the one of theconnect
methods has been called to connect to another target.- Throws:
IOException
- Failed to close the connection to the target
-