JMRI is...

Scripting

Information on writing scripts to control JMRI in more detail:

Python and Jython (General Info)

JMRI scripts are in Jython, a version of Python, a popular general-purpose computer language

Tools

JMRI provides powerful tools for working with your layout.

Layout Automation

JMRI can be used to automate parts of your layout, from simply controlling a crossing gate to running trains in the background.

JMRI: "What...Where" of Jython Scripting with JMRI

Other interesting tidbits about scripting in JMRI with Jython

See the examples page for many sample scripts. Also, the introductory page shows some of the basic commands.

See also JMRI Scripting "How To..."

See also Jython/Python Language for general info about the language.

Where can I find more information on the JMRI classes?

The class documentation pages include automatically-built summary information on every class.

There are a lot of classes! To help you find things, it might be useful to look at the page on JMRI structure, which is part of the JMRI technical documentation. Note the references on the left-hand side.

What do the words "import", "class" mean?

They're part of the jython language used for the scripting.

"import" allow you to refer to things by shorter names, essentially telling jython "search the imported packages (e.g. jarray and jmri) packages and recognize all the names there". For somebody trying to understand this script, you can just treat them as "ensuring the program can find parts we want".

"class" means "start the definition of a group of things that go together" (all you other experts, please don't jump on me about this; I understand both intrinsic/extrinsic polymorphism, I'm just trying to get the general idea across).

For example, in the SigletExample.py file is a description of a "class" called SigletExample, which contains two routines/functions/members: A subroutine called "defineIO", and one called "setOutput"

This "class" is associated with another called "Siglet" (actually jmri.jmrit.automat.Siglet; that's that long naming thing again), which knows when to invoke routines by those two names to get done what you want.

Essentially, you're defining two parts ("defineIO" & "setOutput") that plug into a pre-existing structure to drive signals. That pre-existing structure is very powerful, and lets you do all sorts of things, but also provides this method to try to keep it simpler.

OK, at this point most people's eyes are fully glazed over. Your best bet when starting with this stuff is to use the "copy and modify" approach to software development. It's good to try to understand the entire content of the file, but don't worry about understanding it well enough to be able to recreate it from scratch. Instead, just modify little bits and play with it.

What's the difference between the "Siglet" and "AbstractAutomaton" classes?

(Maybe not a frequently asked question, but it needs to go somewhere)

Some examples use the AbstractAutomaton class as a base, while others use the Siglet class. This is because those are intended for two different purposes.

"Siglet" is meant to be used for driving signals. You provide two pieces of code:

defineIO
which defines the various sensors, turnouts and signals that the output signal depends on as input when calculating the appearance of the signal.
setOutout
which recalculates the signal appearance from the defined inputs.

The Siglet base class then handles all of the listening for changes, setting up for parallel execution, etc. Your defineIO routine will be called once at the beginning, and after than any time one or more of the inputs changes, your setOutput routine will be called to recalculate the signal appearance.

Of course, you can use this class to calculate other things than signal appearances. But the key element is that the calculation is redone when the inputs change, and only when the inputs change.

AbstractAutomaton is a more general class that's intended to allow more powerful operations (and Siglet actually uses that more powerful base). You define two functions:

init
which is called exactly once to do any one-time setup you need
handle
which is called over and over and over again until it returns FALSE.
Using AbstractAutomoton provides you with a number of tools: you can wait for a particular sensor to go active, do something, then wait for a different sensor to go inactive, etc. This allows you much more freedom to create complicated and powerful sequences than the Siglet class, because Siglets are limited to doing just one thing (they aren't intended to do sequences of operations).

For more info on the routines that AbstractAutomaton provides to help you, see the Javadocs for the class. (Scroll down to the section called "Method Summary")