Devices
Scripts define which devices will be used in the experiment. Each device that will be
used has to be registered with the Task. Registration requires three
parameters:
displayHandle = task.addDevice("Display", "nemo.pdi.GraphicalDisplay",
fromDisplay)
Task returns a handle to the device that can be used to send commands
to the device. In the example above displayHandle is the device handle.
The device handle has access to the commands listed in the Script Interface section for
each device below.
GraphicalDisplay
Fully qualified class name: nemo.pdi.GraphicalDisplay
This device handles output to a video component, typically a screen (monitor or
projector). The display is composed of a background color and any number of
Graphics drawn over the background. A Graphic is a basic
building block for drawing on the display (see the list of available
Graphics below). Each Graphic is drawn in the order in which
it was added to the display.
Creating Graphics
NEMO provides a means of creating Graphics through the
GraphicFactory. This class takes as an argument the id for a
Graphic type and returns the Graphic object. Here is an
example using the GraphicFactory:
aRectangle = GraphicFactory.createGraphic(GraphicFactory.FILL_RECTANGLE)
The type ID that is passed in tells the factory which type of Graphic to
create. The available type IDs are:
GraphicFactory.DRAW_OVAL
Oval with no fill
(outline only).
GraphicFactory.FILL_OVAL
Oval.
GraphicFactory.DRAW_ARC
Arc with no fill (outline
only).
GraphicFactory.FILL_ARC
Arc.
GraphicFactory.DRAW_IMAGE
Picture object.
GraphicFactory.DRAW_LINE
Line.
GraphicFactory.DRAW_POLYGON
Polygon with no fill
(outline only).
GraphicFactory.FILL_POLYGON
Polygon.
GraphicFactory.DRAW_POLYLINE
Polyline with no fill
(outline only).
GraphicFactory.DRAW_RECTANGLE
Rectangle with no
fill (outline only).
GraphicFactory.FILL_RECTANGLE
Rectangle.
GraphicFactory.DRAW_ROUND_RECTANGLE
RoundRectangle
with no fill (outline only). A rounded rectangle is a rectangle with rounded
corners.
GraphicFactory.FILL_ROUND_RECTANGLE
RoundRectangle.
GraphicFactory.DRAW_STRING
Text object.
GraphicFactory.DRAW_CIRCLE
Circle with no fill
(outline only).
GraphicFactory.FILL_CIRCLE
Circle.
Graphic called a
GraphicGroup cannot not be created
using the GraphicFactory. A
GraphicGroup is a composition of other
Graphics. It is created with a statement like this:
aGraphicGroup = GraphicGroup()
GraphicGroups below.Graphic object has been created, certain values must be set before
it can be diplayed. Each Graphic requires a name and description as well as
various values for location, size, and color. The specific requirements for each type of
Graphic are listed here:
Oval
Draws an oval, using the color specified, within the specified rectangular
area (bounding box). The result is a circle or ellipse that fits within the
rectangle specified by the x, y, w, and h arguments.
| Field | Description | Type |
|---|---|---|
| name |
a unique name identifying this Graphic
|
string
|
| description |
a brief description of this Graphic
|
string
|
| red |
the red component of this Graphic's color (in the range [0-255])
|
integer
|
| green |
the green component of this Graphic's color (in the range [0-255])
|
integer
|
| blue |
the blue component of this Graphic's color (in the range [0-255])
|
integer
|
| x |
the X-coordinate of the top left
position of this
Graphic's bounding box
|
string
|
| y |
the Y-coordinate of the top left
position of this
Graphic's bounding box
|
string
|
| w |
the width of this
Graphic's bounding box
|
string
|
| h |
the height of this
Graphic's bounding box
|
string
|
Arc
Draws a circular or elliptical arc within the specified rectangular area.
The resulting arc begins at startAngle and extends for arcAngle degrees,
using the color specified. Angles are interpreted such that 0 degrees is at
the 3 o'clock position. A positive value indicates a counter-clockwise
rotation while a negative value indicates a clockwise rotation. The center
of the arc is the center of the rectangle whose origin is (x, y) and whose
size is specified by the w and h arguments.
| Field | Description | Type |
|---|---|---|
| name |
a unique name identifying this Graphic
|
string
|
| description |
a brief description of this Graphic
|
string
|
| red |
the red component of this Graphic's color (in the range [0-255])
|
integer
|
| green |
the green component of this Graphic's color (in the range [0-255])
|
integer
|
| blue |
the blue component of this Graphic's color (in the range [0-255])
|
integer
|
| x |
the X-coordinate of the top left
position of this
Graphic's bounding box
|
string
|
| y |
the Y-coordinate of the top left
position of this
Graphic's bounding box
|
string
|
| w |
the width of this
Graphic's bounding box
|
string
|
| h |
the height of this
Graphic's bounding box
|
string
|
| startAngle | the starting angle of the arc |
integer
|
| arcAngle | the angular extent of the arc, relative to the start angle |
integer
|
Picture
Draws an image using the preloaded resource name or the bytes provided.
The position (x,y) and
dimension (w,h) values are used to create a
bounding box for the image. The image will be scaled to fit inside the
bounding box.
| Field | Description | Type |
|---|---|---|
| name |
a unique name identifying this Graphic
|
string
|
| description |
a brief description of this Graphic
|
string
|
| isResource | a marker identifying this image as a Resource that has been preloaded to the client (non-zero <=> True <=> preloaded) |
integer
|
| imageName | the name of this image, which is used if isResource is non-zero (if isResource is 0 then imageName is ignored and imageBytes is used) |
string
|
| imageBytes | if isResource is 0, then the actual bytes of the image must be set in this field-- bytes can be obtained using Task.getResource(fileName) |
string
|
| x |
the X-coordinate of the top left
position of this
Graphic's bounding box
|
string
|
| y |
the Y-coordinate of the top left
position of this
Graphic's bounding box
|
string
|
| w |
the width of this
Graphic's bounding box
|
string
|
| h |
the height of this
Graphic's bounding box
|
string
|
Line
Draws a line, using the specified color, between the points (x1, y1) and
(x2, y2).
| Field | Description | Type |
|---|---|---|
| name |
a unique name identifying this Graphic
|
string
|
| description |
a brief description of this Graphic
|
string
|
| red |
the red component of this Graphic's color (in the range [0-255])
|
integer
|
| green |
the green component of this Graphic's color (in the range [0-255])
|
integer
|
| blue |
the blue component of this Graphic's color (in the range [0-255])
|
integer
|
| x1 | the X-coordinate of the first endpoint of the line |
string
|
| y1 | the Y-coordinate of the first endpoint of the line |
string
|
| x2 | the X-coordinate of the second endpoint of the line |
string
|
| y2 | the Y-coordinate of the second endpoint of the line |
string
|
Polygon
Draws the closed polygon which is defined by the specified arrays of
coordinates, using the specified color. The coordinates defined in xPoints
and yPoints are considered to represent points which are the vertices of the
polygon (xPoints[i] and yPoints[i] form the ith point). Lines are drawn
between each point, and between the first point and last point in the
arrays.
| Field | Description | Type |
|---|---|---|
| name |
a unique name identifying this Graphic
|
string
|
| description |
a brief description of this Graphic
|
string
|
| red |
the red component of this Graphic's color (in the range [0-255])
|
integer
|
| green |
the green component of this Graphic's color (in the range [0-255])
|
integer
|
| blue |
the blue component of this Graphic's color (in the range [0-255])
|
integer
|
| xPoints | an array of the X-coordinates of the points forming the polygon |
string[]
|
| yPoints | an array of the Y-coordinates of the points forming the polygon |
string[]
|
Polyline
Draws the polyline which is defined by the specified arrays of
coordinates, using the specified color. The coordinates defined in xPoints
and yPoints are considered to represent points which are the vertices of the
polyline (xPoints[i] and yPoints[i] form the ith point). Lines are drawn
between each point, but not between the first point and last point in the
arrays.
| Field | Description | Type |
|---|---|---|
| name |
a unique name identifying this Graphic
|
string
|
| description |
a brief description of this Graphic
|
string
|
| red |
the red component of this Graphic's color (in the range [0-255])
|
integer
|
| green |
the green component of this Graphic's color (in the range [0-255])
|
integer
|
| blue |
the blue component of this Graphic's color (in the range [0-255])
|
integer
|
| xPoints | an array of the X-coordinates of the points forming the polyline |
string[]
|
| yPoints | an array of the Y-coordinates of the points forming the polyline |
string[]
|
Rectangle
Draws a rectangle specified by the arguments, using the specified color. The
left and right edges of the rectangle are at x and x + w. The top and
bottom edges are at y and y + h.
| Field | Description | Type |
|---|---|---|
| name |
a unique name identifying this Graphic
|
string
|
| description |
a brief description of this Graphic
|
string
|
| red |
the red component of this Graphic's color (in the range [0-255])
|
integer
|
| green |
the green component of this Graphic's color (in the range [0-255])
|
integer
|
| blue |
the blue component of this Graphic's color (in the range [0-255])
|
integer
|
| x | the X-coordinate of the top left corner of this rectangle |
string
|
| y | the Y-coordinate of the top left corner of this rectangle |
string
|
| w | the width of this rectangle |
string
|
| h | the height of this rectangle |
string
|
RoundRectangle
Draws a round-cornered rectangle specified by the arguments, using the
specified color. The left and right edges of the rectangle are at x and x +
w. The top and bottom edges are at y and y + h. The roundness of the corners
is specified by the arcWidth and arcHeight arguments, which are respectively
the width and height of the ellipse used to draw the corners.
| Field | Description | Type |
|---|---|---|
| name |
a unique name identifying this Graphic
|
string
|
| description |
a brief description of this Graphic
|
string
|
| red |
the red component of this Graphic's color (in the range [0-255])
|
integer
|
| green |
the green component of this Graphic's color (in the range [0-255])
|
integer
|
| blue |
the blue component of this Graphic's color (in the range [0-255])
|
integer
|
| x | the X-coordinate of the top left corner of this rectangle |
string
|
| y | the Y-coordinate of the top left corner of this rectangle |
string
|
| w | the width of this rectangle |
string
|
| h | the height of this rectangle |
string
|
| arcWidth | the width of the arc for the rounded corners |
string
|
| arcHeight | the height of the arc for the rounded corners |
string
|
Text
Draws the given string, using the specified font and color. The size of the
text is determined by the textWidth and textHeight values, which, together
with the x and y values, form a bounding box. The text size is maximized to
fill the bounding box as closely as possible without going over its edges.
| Field | Description | Type |
|---|---|---|
| name |
a unique name identifying this Graphic
|
string
|
| description |
a brief description of this Graphic
|
string
|
| red |
the red component of this Graphic's color (in the range [0-255])
|
integer
|
| green |
the green component of this Graphic's color (in the range [0-255])
|
integer
|
| blue |
the blue component of this Graphic's color (in the range [0-255])
|
integer
|
| x | the X-coordinate of the top left corner of the bounding box |
string
|
| y | the Y-coordinate of the top left corner of the bounding box |
string
|
| fontWidth | the width of the bounding box |
string
|
| fontHeight | the height of the bounding box |
string
|
| text | the text to display |
string
|
| fontName | the name of the font family ("Arial", "Courier", etc) |
string
|
| fontStyle |
the style of the font (can be Text.NORMAL,
Text.BOLD, Text.ITALIC, or any bitwise-OR
combination from the list)
|
integer
|
| alignment |
the alignment of the text within the bounding box (cen be
Text.ALIGN_CENTER, Text.ALIGN_LEFT, or
Text.ALIGN_RIGHT)
|
integer
|
Circle
Draws a circle, using the specified color, within the specified rectangular
area (bounding box). The result is a circle that fits within the rectangle
specified by the x, y, and diameter arguments (the diameter is used as the
width and height for the bounding box).
| Field | Description | Type |
|---|---|---|
| name |
a unique name identifying this Graphic
|
string
|
| description |
a brief description of this Graphic
|
string
|
| red |
the red component of this Graphic's color (in the range [0-255])
|
integer
|
| green |
the green component of this Graphic's color (in the range [0-255])
|
integer
|
| blue |
the blue component of this Graphic's color (in the range [0-255])
|
integer
|
| x |
the X-coordinate of the top left
position of this
Graphic's bounding box
|
string
|
| y |
the Y-coordinate of the top left
position of this
Graphic's bounding box
|
string
|
| diameter | the diameter of the circle (width/height of the bounding box) |
string
|
GraphicGroup
Draws each Graphic in the group. Graphics are
added to the group using the addGraphic function, like this:
# Note: Lines that begin with a pound sign are comments and are
disregarded.
# Make a GraphicGroup
aGraphicGroup = GraphicGroup()
# Make a Circle Graphic
aCircle = GraphicFactory.createGraphic(GraphicFactory.DRAW_CIRCLE)
aCircle.name = "my circle"
aCircle.description = "it is round"
aCircle.x = "50"
aCircle.y = "50"
aCircle.diameter = "5"
aCircle.red = 255
aCircle.green = 0
aCircle.blue = 0
# Add the Circle to the GraphicGroup
aGraphicGroup.addGraphic(aCircle)
Now, when the GraphicGroup is sent to the client for display it will draw
the circle as well as any other Graphic that has been added to
the group.
Note: For reporting purposes, the name and description of
the GraphicGroup are reported, but the Graphics in
the group are not.
| Field | Description | Type |
|---|---|---|
| name |
a unique name identifying this GraphicGroup
|
string
|
| description |
a brief description of this GraphicGroup
|
string
|
Graphic in the center of the display). Alternatively, you can
express the value in absolute coordinates by appending an "a" to the end of the value
(for example, x="50a", y="50" will place the top left corner 50 pixels from the left
edge of the display and half way down from the top of the display). Percentage
coordinates are recommended, because the size of the display is not known and may differ
across clients. Using absolute coordinates may lead to Graphics that hang
off the egde of the display.
Script Interface
The script can send commands to the display of each client using the following functions:
addGraphic(aClientID, aGraphic)
Graphic aGraphic to the display of the client
with ID aClientID.
addGraphics(aClientID, aGraphicsList)
Graphics in the list aGraphicsList to
the display of the client with id aClientID.
addGraphicGroup(aClientID, aGraphicGroup)
GraphicGroup aGraphicGroup to the display of
the client with ID aClientID.
showGraphics(aClientID)
aClientID to draw any
Graphics that have been added (and not removed).
hideGraphics(aClientID)
aClientID to stop drawing
any Graphics that have been added (and not removed). It is
sometimes useful to hide Graphics, then add several new
Graphics while the display is in hidden mode. Then when the
Graphics are set to show again, they all appear at the same time.
If you make several calls to addGraphics with the mode set to show,
then the Graphics will not necessarily appear at the same time,
since they have to travel through the network to the clients.
clearGraphics(aClientID)
Graphics from the display of the client with ID
aClientID.
removeGraphic(aClientID, aName)
Graphic with name aName from the display
of the client with ID aClientID.
setBackground(aClientID, colorData)
colorData on
the display of the client with ID aClientID. (Note: The
ColorData class contains fields for the red, green, and blue
components of a given color. The ColorData class is used like
this:
myColorData = ColorData(255, 128, 0)
...or...
myColorData = ColorData()
myColorData.red = 255
myColorData.green = 128
myColorData.blue = 0
ColorData object represents an orange color.)
GraphicalDisplay responds to commands from the script by sending a
DisplayEvent to the script. Each DisplayEvent contains
information about the type of event that happened, the time it occurred, and any
Graphics that were in the drawing list at the time. This event is sent to
the handler method that was used in the device registration. A
DisplayEvent has the following functions available:
getGraphics()
Graphic in
the drawing list. Each element in the list is of the form
name:description.
getClient()
getTime()
getType()
GraphicalDisplay.CLEAR_GRAPHICS
Graphics were all removed.
GraphicalDisplay.DRAW
Graphic was added to the drawing list.
GraphicalDisplay.HIDE
Graphics in the drawing
list.
GraphicalDisplay.SHOW
Graphics in the drawing list.
GraphicalDisplay.CREATE_GROUP
GraphicGroup was added to the drawing list.
GraphicalDisplay.REMOVE
Graphic was removed.
GraphicalDisplay.ADD_GRAPHICS
Graphics was added to the drawing list.
GraphicalDisplay.SET_BACKGROUND
ButtonBox
Fully qualified class name: nemo.pdi.ButtonBox
This device handles input from a device used by subjects to make decisions. An example
of a common ButtonBox is a standard keyboard. As a user presses keys, NEMO
sends data to the script for processing, and depending on the content of the input, the
script can take alternate paths.
Some primitive ButtonBoxes may have limited input options (such as only
providing 4 buttons with the values "1", "2", "3", and "4"). If your script expects
input to be in the set ["A", "B", "C", "D"], then the primitive ButtonBox
will never work with the script. To get around this type of problem, NEMO provides a
method to map input values to new values. For example:
1
# Register the device with NEMO.
2
aButtonBox = task.addDevice("MyButtonBox", "nemo.pdi.ButtonBox", fromButtonBox)
3
4
# The following lines of code tell NEMO to ask each client to
provide a mapping to the given values.
5
task.addDeviceProperty("MyButtonBox", ButtonBox.PROP_OUT_VAL_BASE + String.valueOf("0"), "A")
6
task.addDeviceProperty("MyButtonBox", ButtonBox.PROP_OUT_VAL_BASE + String.valueOf("1"), "B")
7
task.addDeviceProperty("MyButtonBox", ButtonBox.PROP_OUT_VAL_BASE + String.valueOf("2"), "C")
In the above example, a ButtonBox is registered with the name
"MyButtonBox" (line 1). The following lines (5-7) tell NEMO that input values should be
mapped to "A", "B", and "C". This means that the client will need to pick valid values
from their ButtonBox and map them to the requested values. If the box has
values "1", "2", and "3" then the client could just map "1" to "A", "2" to "B", and "3"
to "C". Now whenever the ButtonBox recieves a "1" from the subject, it will
be mapped to an "A" and sent to the script. This mapping scheme allows the script to
act as if all ButtonBoxes can provide the same input.
Script Interface
Scripts do not send commands to ButtonBoxes, since they exists only to
take input from subjects.
However, when a subject sends input through the ButtonBox, data is sent to
the script for processing. The data arrives as a standard Event. Each
Event stores information about the type of the event, the time it occurred,
and the button pressed. This event is sent to the handler method that was used in the
device registration. A standard Event has the following functions
available:
getClient()
Event originated.
getTime()
Event occurred (in milliseconds since
midnight, January 1, 1970 UTC).getType()
Event. For ButtonBoxes, every event will have the
type ButtonBox.MESSAGE_BUTTON_PRESS.
getData()
Scanner
Fully qualified class name: nemo.pdi.Scanner
The Scanner device controls communication between the NEMO client and an
MRI scanner. This device is used to start and stop the scanner and to retrieve
images from the scanner. This device will require special setup on the scanner to work
properly.
Script Interface
The script can send commands to the Scanner of each client using the
following functions:
startScanning(aClientID)
Scanner of the client with ID aClientID to
start the scanning sequence.
stopScanning(aClientID)
Scanner of the client with ID aClientID
to stop the scanning sequence.
getImages(aClientID)
Scanner of the client with id aClientID
to send the images for the current subject.Scanner responds to a command from the script, it sends an
Event. Each Event stores information about the type of the
event and the time it occurred. This Event is sent to the handler method
that was used in the device registration. A standard Event has the
following functions available:
getClient()
Event originated.
getTime()
Event occurred (in milliseconds since
midnight, January 1, 1970 UTC).getType()
Event. For ButtonBoxes, every event will have the
type ButtonBox.MESSAGE_BUTTON_PRESS.
SyringePump
Fully qualified class name: nemo.pdi.SyringePump
The SyringePump device squirts liquid. It can be used to squirt soda in
subject's mouths, as in the study linked
here, or it can
be used to squirt water and juice as in the study linked
here.
The SyringePump allows you to control which syringe (the pump may have more
than one), the rate of the squirt, and the duration of the squirt.
Script Interface
The script can send commands to the SyringePump of each client using the
following functions:
squirt(aClientID, squirtData)
SyringePump of the client with ID aClientID
to squirt using the data from squirtData. The squirt data should
be a string with the following form:
syringeID rate time
syringeID is the ID of the syringe, rate is a floating
point value with form XX.XXX where each X is a digit from 0-9, and
time is a millisecond value greater than zero.
SyringePump recieves a command from the script, it responds with
an Event. Each Event stores information about the type of the
event, the time it occurred, and the syringe that was pumped. This Event is
sent to the handler method that was used in the device registration. A standard
Event has the following functions available:
getClient()
Event originated.
getTime()
Event occurred (in milliseconds since
midnight, January 1, 1970 UTC).getType()
Event. For SyringePumps, every event will have the
type SyringePump.SQUIRT_COMPLETE.
getData()
SYRINGE A").
Movie
Fully qualified class name: nemo.pdi.Movie
The Movie device plays a movie clip in the center of the display. This
device requires the installation of the Java Media Framework (which may be packaged with
NEMO, but is also available
here from
Sun).
Script Interface
The script can send commands to the Movie device of each client using the
following functions:
createMessage(aClientID, aType, aMovieName)
Message for the Movie of the client with ID
aClientID. The name of the clip is aMovieName. The
type of the Message, given by aType, determines what
the device will do when this message is received. Valid types are:
-
Movie.LOAD
-
Movie.SHOW
-
Movie.START
-
Movie.STOP
-
Movie.HIDE
-
Movie.CLOSE
Movie display.createMessage will return a Message object
(to be used with send below).
send(aMessage, 0)
Message created from a call to createMessage.
The second argument should always be 0.
Movie acts on a command from the script or as a result of a movie
clip event, it sends an Event to the script. Each Event stores
information about the type of the event, the time it occurred, and a string describing
the event and the name of the clip. This Event is sent to the handler
method that was used in the device registration. A standard Event has the
following functions available:
getClient()
Event originated.
getTime()
Event occurred (in milliseconds since
midnight, January 1, 1970 UTC).getType()
Event. The possible types are:
Movie.LOADED
Movie.STARTED
Movie.STOPPED
Movie.END_OF_MEDIA
Movie.SHOW
Movie display is visible.
Movie.HIDE
Movie display is hidden.
getData()
STARTED: myMovieClip.mpg").
All documentation ©2005 Human Neuroimaging Laboratory