This software has been developed with OpenSUSE and tested most recently with
its rolling Tumbleweed distribution.  

The protocol files in drvsbig directory are for use with scientific and
astronomical CCD cameras manufactured by Diffraction Limited (formerly by
Santa Barbara Instruments Group or SBIG). The legacy cameras  depend on the 
proprietary library that is in the libsbig directory of this version of xmccd.

The software has been tested with several different models of SBIG cameras
including the ST7, ST8, ST9, ST10, STL1001, STL6303, and STX16803.  It supports
the SBIG filter wheels for these cameras.  We expect that the software will work
with any legacy USB SBIG camera that is supported by the driver but we
cannot test all of them since we have had only have these camera types at our
facilities.

The new line of USB SBIG cameras have a different API interface
requirement and are not included.  However, most of the new cameras also offer
a platform-independent  Ethernet or wireless option which is under review for
support within XmCCD, Python, and AstroImageJ.

For research uses, the cameras with  back-illuminated sensors, and the legacy
STX camera with the large 4kx4k On-Semi (Kodak) sensor are our focus for 
continued support.  Suggestions are welcome.

The CFW and CFWL series of built-in filter wheels are supported, as is the Optec
IFW external filter wheel.  It may be necessary to change the filter wheel
choice in the protocol.h file for each camera.  Check the protocol file to see
what is currently the default and change it according to your needs.




Installation Instructions for XmCCD with the SBIG Library
=========================================================

This is a recipe for installing XmCCD and auxiliary software especially for
those who may not have experience with Linux system management.  If you try
this and find I have left out something, please let me know and I will 
include your suggestion here.  There are few differences between SBIG and Apogee
because of the available options in their camera systems, and the requirements
of the USB interface.  For Apogee cameras, follow the instructions in APOGEE.

  
I. Required Resources
---------------------

First, you will need the software sources.  It is best to compile xmccd from the
source to be sure that it will work with your system.  XmCCD has been tested
most recently with Opensuse Leap 14.  

Download and install the install the default Linux distribution of your choice,
and include "development" versions of gcc, libusb and similar system software
used to build applications.  After installation you must add
packages for

  -- Motif development (for the user interface)
  -- fxload (required to load firmware to the camera)

and you should be ready to install and run the software.
  

1.  XmCCD
---------

Our website

http://www.astro.louisville.edu/software  

provides:

xmccd-#.#.tar.gz

As root or superuser, copy this to /usr/local/src.  Untar the archive with
the command

tar xvzf xmccd-#.#.tar.gz

where "#.#" here will be a version number.  


2.  Motif libraries
-------------------

XmCCD uses a Motif user interface.  Your system will need a "development" 
package for Motif (or LessTif) to provide libraries and header files needed to
compile xmccd.  In Opensuse  the easiest way is to use the system software
management program to search Suse archives for Motif and install from their
package.  Other distributions should have similar services, or may already have
Motif installed.  

If you are unsure whether your system has Motif, look for library files such as 
libXm.a, libXm.la, and libXm.so in /usr/lib and  /usr/lib64 for Opensuse, or
perhaps /usr/X11R6/lib for other distributions.  The makefiles for xmccd and
xmccd1 require links to these libraries, and expect them in /usr/lib.  You may
need to edit the makefiles for distributions other than Opensuse if the
libraries are not in /usr/lib.

You might also simply try to compile xmccd (see below) before you proceed to 
install Motif, and if there is an error message that a library is missing, 
that is a good indication that you need to install Motif, or make changes 
described below.


3. FITS libraries
-----------------

Astronomical images are stored as Flexible Image Transport (FITS) files and we
use the cfitsio libraries in building xmccd.  We recommend installing the
libraries system-wide as root user.  Note that if your system already has
libcfitsio installed this step is not necessary.  

cd libcfitsio
./install_cfitsio


4. FITS utilities
-----------------

A set of fits utilites is available in our Alsvid package.  See our website
for details. The latest version of Alsvid is based on Python and is easily
extensible for those familiar with the language.


5. ds9
------

This is the powerful image display software from the Harvard-Smithsonian Center
for Astrophysics . XmCCD uses it to display the images and to provide image
analysis and file handling. 

A copy of the most recent binary at the time this version of XmCCD was built is
included.  

cd ds9
./install_ds9


It is also simple to install the binary for ds9 by downloading it from
the developer's website if you want another version,


http://hea-www.harvard.edu/RD/ds9/

and copy it to /usr/local/bin/

It may also be compiled from source although the complexities of the software
make compiling likely to fail on "cutting edge" versions of Linux.  We 
recommend using the binary.


SAO_ds9 stores your preferences in a .ds9 file in the your home directory. 
You may want to read the manual to understand all the features, but one of them
is that it communicates with other software through an "XPA" protocol.  We use
this to inform ds9 each time there is a new image, and to obtain region
coordinates so that subframes can be read quickly if desired.  XPA is built into
xmccd1 and ccd, and it may also be used externally if you have scripts that are
interacting with the images and the telescope control system.


6. XPA
------

SAO_ds9 uses the XPA communication library and utilities.  A recent version 
of the source is included in XmCCD and must be compiled and installed:

cd xpa-#.#
./configure
make clean
make
make install
ldconfig

The ldconfig command will assure that the new fits and xpa libraries are 
recognized  by the system.

The XPA website has more information and updates: 

http://hea-www.harvard.edu/RD/xpa/index.html


7. SBIG Library
---------------

There is a version of the driver library in the sbig subdirectory of the
XmCCD package. You should use the included version.  The libsbig directory
in the XmCCD distribution also includes a script for installing the library,
include file, and the usb firmware.  

cd libsbig
./install_sbig

Some older versions of Linux may not work with this library, or may not work
with the rules script that prompts the system to upload firmware to the camera.
The best solution in this case is to update the operating system. Older 
versions of the library are still available in archived xmccd tarfiles 
if you are running an older Linux OS and cannot update it.


8. Edit the protocol.h file
---------------------------

Some options are fixed in the protocol.h file.  Most cameras will work with the
default selections, but look at the file and change it as needed for your use:

Binning is turned off.  Change this from 1 to 2 or 3 if you want to use the
camera with larger virtual pixels.  This option is experimental and may not work
with all cameras.

* #define BINNING 1


Look at protocol.h and select the efaults for the filter wheel settings that are
appropriate, for example this is the setup for an STX camera

#ifndef FILTER_WHEEL
#define FILTER_WHEEL CFWSEL_AUTO
#define FILTER_START 1
#define FILTER_MAX 7


With an external wheel the choice would be "EXT_FILTER_WHEEL".



II.  Compile and install the XPA interface
------------------------------------------

cd xpaccd
setup_sbig
make clean
make
make install


Before the first "make", check the contents of protocol.h to see if it has youpreference for the filter wheel and camera.  You may need to change the default
from the STL internal filter wheel to an external system, or to another SBIG
option.  

If you also have an Apogee camera, you should rename xmccd1 and xpaccd
to be unique, for example, xmccd1_sbig and xmccd1_apogee.

The xmccd program talks only to xpaccd and is  not
specific to the choice of camera.



III. Compile and install the user interfaces
--------------------------------------------

cd xmccd
make clean
make install

cd xmccd1
./setup_sbig
make clean
make
make install

The binary xmccd does not depend on the camera type, but xmccd1 does.  If you
also have an Apogee camera, or use different camera and filter combinations,
create unique executables for each one and rename them.



IV. Test that the USB system recognizes the camera and uploads firmware
-----------------------------------------------------------------------

With the camera power off, plug the camera's usb cable into a usb port on your 
computer.  Apply power and after a brief delay the fan on the camera should
start and its indicator LED should come on.  If the fan and light are on, then
the camera is ready to use.


For a diagnostic you could try 

  lsusb

On our system this is the response when the camera is running:


Bus 004 Device 001: ID 0000:0000  
Bus 005 Device 001: ID 0000:0000  
Bus 001 Device 010: ID 0d97:0101 Santa Barbara Instrument Group SBIG Astronomy 
  Camera (with firmware)
Bus 001 Device 008: ID 04b0:0410 Nikon Corp. 
Bus 001 Device 004: ID 05e3:0606 Genesys Logic, Inc. 
Bus 001 Device 002: ID 05e3:0606 Genesys Logic, Inc. 
Bus 001 Device 001: ID 0000:0000  
Bus 003 Device 001: ID 0000:0000  
Bus 002 Device 002: ID 06c2:0031 Phidgets Inc. (formerly GLAB) 
Bus 002 Device 001: ID 0000:0000  


The identification 0d97:0101 is the one for a camera after the firmware has been
uploaded.  If the upload was not successful, you will see an identification 
such as 0d97:0001, where the second hex number depends on the camera model. 
Other items here are for different devices attached to the USB bus -- in this
case a Nikon camera used for wide field imaging and an RFID tag reader that is
used to encode dome rotation.

In some cases, as root, you may need to upload the firmware from the command
line.  To do this, first find the device address using lsusb.  Then issue a
command similar to this one:

fxload -D /dev/bus/usb/001/002 -I /lib/firmware/sbigucam.hex

where the numbers 001 and 002 identify the USB device found in lsusb, and the
hex file to be uploaded is the one corresponding to your camera (lcam for STL 
cameras and ucam for others like the ST7,8,9, and 10).  


V.  Install a configuration file for the user software
------------------------------------------------------

Copy a configuration file in xmccd-#.#/prefs/ to 
/usr/local/observatory/prefs/prefs.ccd and edit it to suit your camera.  
The prefs file is used to name the filters in your camera filterwheel and 
record tracking defaults for autoguiding on your telescope.  If the file 
is not found, the compiled-in defaults will be used.  

Note some special cases are still handled on compilation by
settings in the protocol.h file (see above).  

Also create a subdirectory

/usr/local/observatory/status

As root user --

cd /usr/local
mkdir observatory
mkdir observatory/prefs
mkdir observatory/status

Change the ownership to a convenient user if you want to easily alter
configurations without root priviledges --

chown -R observer.users observatory 

where the last command would give ownership to the user who is 
running the camera.  Alternatively (although less secure) allow any user
to read and write to the tree.

The programs xmccd1 and ccd read prefs files and write status files in this
tree, as do the companion programs xmtel1 and tel.  Some of our specialized
scripts which are offered as examples here also use files under "observatory"
to control flow.


VI. Start the XPA server 
-------------------------

We recommend starting the xpaccd server in the directory where your image
files will be stored.  In routine use, where the camera is turned off except
during the period of use, first be sure that xpaccd is not already running.  One
way to do this is 

killall xpaccd

Once an SBIG camera is connected and has uploaded its firmware, start the
server with the this sequence

cd data
xpaccd

where "data" is the directory into which you will store your image files.  
On a given night, start with an empty directory to be sure you do not
overwrite older images with new ones since the default naming sequence will
begin again with a new start for xpaccd.  

This operation should be done as a user.  It should not be 
necessary and is not desirable to do this as root.  When the server starts 
the ccd driver, the driver will read a configuration file that is by default 
in /usr/local/observatory/prefs . Images acquired will be saved in the 
directory in which the server is started.  

The xpa server is compatible with  XmTel, our telescope control software, but
telescope and other controls are through their own servers, for example  

cd data
xpatel

In this case you may have "queue" files for data acquisition ready for xmtel
in the data directory.  Both xpaccd and xpatel will access scripts that are
conveniently kept in /usr/local/bin, or in your own $HOME/bin directories.



VII. Start the user interface
-----------------------------

The camera fan and the "on" light will indicate that it has loaded firmware.  
Once the xpaccd server is running with the camera driver you may control  the
camera using the xmccd GUI interface or from command line through setxpa and
getxpa.  

The command 

xmccd

will spawn ds9 for image display and open a window to control the 
camera. Images will not be available unless you start xmccd in the same
directory where xpaccd is running, or provide a script that moves images into
the current working directory of xmccd.  

While xmccd can work outside the local host, for remote operation it is best to
run it on the same computer that xpaccd is running on, that is on the same
computer to which the camera is attached. These programs work very well under a
VNC server with TightVNC as a client for an "on-site" experience at remote
observing.


VIII.  Run the camera from the command line
-------------------------------------------

Use the command line with setxpa to run the camera without a user interface. 


IX.  Alternative direct camera control interface without XPA
------------------------------------------------------------

The command

xmccd1

will run the camera without an XPA server.  You should not start xpaccd
if you want to use xmccd1.  The xmccd program  requires that xpaccd is running.


X. Filter wheels
----------------

XmCCD is designed to control a filter wheel, and with SBIG cameras it will
detect and use the internal filterwheel if it is available.  You should
select the filter wheel by setting it in protocol.h.  The header file is 
annotated and it is simple to make your choice before compiling the
executable files for your camera.

XmCCD also allows you to select an external filter wheel option on compiling. 
With this, XmCCD will call an external routine and pass a filter number
argument to it, supporting in principle any hardware. 



XII. Scripts
-----------

There are several scripts given in the the xmccd distribution as examples.
Two of them --

transfer_image
set_camera_filter

should be edited installed in your computer's /usr/local/bin/.  The first one
is called by ccd to initiate an image transfer to ds9.  The script provided
does this by running setxpa locally.  If your instance of ds9 is on another
computer, you may need to use this to copy files or handle other tasks following
the acquisition of an image. The second one is used to run an external filter
wheel.  A dummy version should probably be installed even if you are using an
internal filter wheel to help the software start up smoothly before it knows
your system configuration.

There is also a program "ccd_monitor.sh" which may be started as a daemon
and allowed to run during the entire data acquisition if you want to process
images with a script after they are stored. It looks for a short timestamp
file ccdnewimage in /usr/local/observatory/status as a flag that there is 
new data to work on.  The file ccdnewimage is written by another script
ccd_process.sh that runs (when the option is selected) every time the camera
stores an image.  The purpose of the two scripts is to separate the work done
post-processing from the actual exposures and to avoide threading conflicts 
in Python.   

One very useful result is that the ccd_process.py script that is called by
ccd_monitor.sh can make guiding corrections based on stars selected in ds9.
Instructions on how to do this will be in the documentation on the XmCCD
wiki. With this feature, if the telescope can take images without guiding 
that are  of high quality in a cadence, for example, of 100 seconds, you can
effectively run on a single target unattended for hours with feedback from
the images you acquire to keep the telescope on target.  We use this for
real-time photometry with AstroImageJ.


XIII.  Send your comments
----------------------

Please let me know how this is working for you and what features you would like
to see added. There is a short TODO list in the main directory.


John Kielkopf (kielkopf@louisville.edu)
22 December 2020






  
