\chapter{Introduction}

MX is a data acquisition and control toolkit designed for both small
to large experimental systems.  It provides support for many different
kinds of devices such as motor, counter/timers, multichannel analyzers,
area detectors and more.  It also provides many different scanning
modes such as step scanning and slew/quick scanning.

First, let's give some examples of how you can use MX.

\section{Example 1: Single Process Mode}

Suppose you have this situation:

You are performing a powder diffraction measurement in a
university laboratory using an X-ray generator.
You have a quasi-monochromatic beam that has been created using an
appropriate set of filters.  This beam is aimed at your powder
sample and you want to mount a scintillation counter on a $2 \theta$ arm
to measure the intensity of the powder pattern reflections as a function
of angle.  You will move the your stepping motor using an Advanced Control
Systems MCU-2 motor controller and count the scintillation pulses using
an Ortec 974 NIM module.  The simplest possible way of supporting this
situation is to use a single process to handle both device control
and a text-mode user interface.

The following is an example MX database for this situation.  A copy of this
database file can be found in
the MX source code tree at \textit{mx/test/drivers/muser\_example1.dat}.
It can be run using the script \textit{mx/test/drivers/muser\_example1}
\textbf{if} you have an MCU-2 and an Ortec 974 connected to a Linux computer.
%
\begin{verbatim}
#
# Motion control
#
mcu2_rs232 interface rs232 tty "" "" 19200 8 N 1 N 0x0d 0x0d 5.0 0x0 /dev/ttyS0
theta  device motor mcu2 "" "" 0 0 -180000 180000 0 -1 -1 0.001 0 deg mcu2_rs232 1 0x0
2theta device motor mcu2 "" "" 0 0 -10000 160000 0 -1 -1 0.001 0 deg mcu2_rs232 2 0x0
#
# Counter/timer control
#
ortec_rs232 interface rs232 tty "" "" 9600 8 N 1 S 0xd 0xd 5.0 0x0 /dev/ttyS1
ortec      interface controller ortec974 "" "" ortec_rs232
scaler2    device scaler ortec974_scaler "" "" 0 0 1 timer1 ortec 2
scaler3    device scaler ortec974_scaler "" "" 0 0 1 timer1 ortec 3
scaler4    device scaler ortec974_scaler "" "" 0 0 1 timer1 ortec 4
timer1     device timer ortec974_timer "" "" ortec
\end{verbatim}

The first few lines of the file describe the interface to the motor
controller and the motors.
%
\begin{verbatim}
mcu2_rs232 interface rs232 tty "" "" 19200 8 N 1 N 0x0d 0x0d 5.0 0x0 /dev/ttyS0
\end{verbatim}

On a Linux or Unix computer, this line creates an MX RS-232 record named
\textit{mcu2\_rs232} that is used to communicate with the MCU-2 controller
via a Unix TTY interface.
It requests the following settings for this RS-232 interface.
\begin{itemize}
  \item{\texttt{19200 8 N 1 N}} - These set up the serial port using
	the traditional set of serial port parameters.
	\begin{itemize}
	    \item 19200 bits per second port speed
	    \item 8 bit characters.
	    \item No parity.
	    \item 1 stop bit.
	    \item No flow control.
	\end{itemize}
  \item{\texttt{0x0d 0x0d}} - This specifies that ASCII messages read from the
	MCU-2 will have a line terminator of a single carriage return
	character (ASCII 10, Hex 0xD).
	Similarly, ASCII commands sent to the MCU-2 will also be terminated
	with a carriage return character.
  \item{\texttt{5.0}} - This requests an RS-232 timeout of 5 seconds.
	If the driver software expects a response to a command that MX has
	sent and does not receive it within 5 seconds, the read in the MX
	driver would return an MXE\_TIMED\_OUT error to the user.

	If you do not want a timeout, then just set the timeout to a
	negative number.
  \item{\texttt{0x0}} - This is the \textit{rs232\_flags} field.  Setting
	this to 0x0 sets a number of internal MX RS-232 parameters to
	their default values.
  \item{\texttt{/dev/ttyS0}} - This is the name of the Linux or Unix TTY
	port used to communicate with the MCU-2 controller.
\end{itemize}

On a Windows computer, you would replace the above record definition with
this slightly different one.
%
\begin{verbatim}
mcu2_rs232 interface rs232 win32_com "" "" 19200 8 N 1 N 0x0d 0x0d 5.0 0x0 COM1
\end{verbatim}

If you were using a TCP/IP socket to connect to a remote serial port on
TCP port 5002 at host 192.168.150.3, then this line would become
%
\begin{verbatim}
mcu2_rs232 interface rs232 tcp232 "" "" 19200 8 N 1 N 0x0d 0x0d 5.0 0x0 192.168.150.3 5002 0x0
\end{verbatim}

There are many other kinds of RS-232 drivers in MX which we do not describe
at this point.

\ \newline
\textit{... more stuff to go here ...}
\ \newline

The current syntax for the database files is relatively terse.
There is a plan to add support for a Windows-INI file style syntax has
not happened yet.

\section{Example 2: MX Client/Server Mode}

\section{Example 3: Using a Foreign Control System}

