
 






Apogee Camera Control API
Programmer's Reference













Software Version 4.3


April 27, 2000

Disclaimer

Apogee Instruments Inc. and GKR Computer Consulting assume no liability for the use of the information 
contained in this document or the software which it describes. The user assumes all risks. There is no 
warranty of fitness for a particular purpose, either express or implied.

The information contained in this document is assumed to be correct, but in no event shall Apogee 
Instruments Inc. or GKR Computer Consulting be held responsible for typographical errors or changes in 
the software not reflected in this document.

The specifications contained in this document are subject to change without notice.


c Copyright 1998 Apogee Instruments Inc.
Portions c Copyright 1998 GKR Computer Consulting
All rights reserved.




All trademarks mentioned in this document are the property of their respective owners and are used 
herein solely for informational purposes only.




























Apogee Instruments Inc.
3340 North Country Club, Suite 103
Tucson, Arizona 85716

TEL (520) 326-3600
FAX (520) 326-0880

Introduction


The Apogee Camera Control API (Application Program Interface) consists of a set of functions written in 
the C programming language. The library was created using the Microsoft? Visual C++ version 1.52c and 
5.0 compilers. It has been compiled and tested under MS-DOS? 6.22, Windows? 3.1, Windows for 
Workgroups, Windows 95, Windows 98, Windows NT, Windows 2000, and the Linux operating systems.

The API functionality is organized as two levels of interaction with the camera interface hardware. The 
highest level of the API provides the programmer with functions to open a camera control channel, acquire 
an image, and close the camera channel without dealing with the low-level control bits and status flags 
from the camera interface itself. The low-level functions within the API provide direct access to the camera 
control registers for those who need additional functionality. The following figure shows the schematic 
organization of the library.
























Apogee Camera Control API Organization

Virtual Camera Channels


The API supports multiple camera controllers in a single computer through the use of virtual "channels". 
When a camera channel is opened, a control structure, also referred to as a control block, is allocated for 
that camera. This control block contains all the parameters necessary for camera operation. It is also 
possible to open multiple channels for a single camera. This would allow the application to change camera 
parameters "on-the-fly" without requiring a reload of the configuration data file. The figure on the following 
page illustrates the camera control channel scheme.

Camera parameters are initially loaded from an ASCII configuration file, which uses the common "INI" 
format. Parameters within the configuration file are grouped into named sections. The configuration file is 
a standard ASCII file and may be created and edited with any conventional text editor. The Apogee 
camera control API supports multiple configuration files. A single camera may have different configuration 
files for different situations, or each camera in a multi-camera system may have its own unique 
configuration file.


























Virtual Camera Control Channel Scheme

Camera Data Transfer


Apogee cameras are line-readout devices, not frame-capture cameras. This means that the CCD data is 
read from the camera one line at a time. Internal state control logic in the camera head and the ISA 
interface card handles camera status, exposure timing, row and column counting, flushing, and 
temperature control. The programmer is responsible for allocating memory to store camera data and 
organizing the resulting data for display and processing.

The API supports two basic modes of CCD data readout: Block Mode, Line Mode. Block Mode readout is 
the simplest form, wherein the API passes an entire image worth of data to a buffer designated by the 
caller. All operating systems that support large memory allocation should use Block Mode readout to take 
advantage of internal subroutine optimizations. However, under conventional DOS, only 64K of image data 
may be passed due to the 64K segment size limit of iAPX86 processors running in "real" mode. DOS 
applications should use Line Mode readout.

Line Mode readout is more complex, and requires some additional effort on the part of the programmer, 
but it allows the CCD data to be read one line at a time to acquire very large images with minimal 
overhead. This is advantageous when using DOS mode extended memory to store images. Image data 
may also be stored to a so-called "RAM disk", or to a physical disk if a high-speed caching system is 
installed in the computer. Because of the effects of dark current buildup during image readout, the use of a 
slow hard disk as an immediate storage medium is not recommended. Line Mode readout can also be 
used to perform equipment control tasks while camera data is being transferred to the host computer.

Dependent on the camera sensor, special slice mode acquisitions can be made during long camera 
exposures. Data collected using slice mode acquisitions can be used to perform telescope auto-guiding 
functions as well as other types of external equipment control.

Development Support


Apogee Instruments is not in the software business, so our ability to provide technical support must 
necessarily be limited to answering questions regarding the camera hardware and its interaction with the 
control software.

GKR Computer Consulting has agreed to provide technical assistance regarding the Apogee Camera 
Control API. You can contact GKRCC via email at apogee_support@gkrcc.com or by accessing their 
World Wide Web site at http://www.gkrcc.com. GKRCC can also provide efficient application development 
and professional consulting services if you require them. The latest version of the Apogee API DLLs will 
be permanently available to users and developers from one or more internet sites. Contact Apogee or 
GKRCC for details.

The Apogee Camera Control API is a set of functions designed to completely control camera systems 
produced by Apogee Instruments. You may not need or use all the high level functions in your application. 
The Apogee API is provided as a courtesy to our customers, and comes without warranty of fitness for any 
purpose or application. The user assumes all risk for the use of the information contained in this document 
and the software it describes.

Developing applications using the API


Normally application programmers need only to include the file APCCD.H in relevant source code 
modules and link in the appropriate library file APOGEE.LIB (APOGEE32.LIB for Win32 developers) in 
order to call the Apogee API functions. To access the low level API functions, the file APLOW.H must also 
be included in your source code modules. To identify extended error codes, the file APERR.H is also 
provided to developers.

Application developers must remember to install the appropriate combination of run-time components with 
their applications.

Application developers may not redistribute any API related files other than the Windows DLLs without the 
express written permission of GKR Computer Consulting.
File Manifest
DOS/Win16 Development
	APOGEE.LIB		Main library
	APCCD.H			High level include file
	APLOW.H			Low level include file
	APERR.H			Extended error code constants

	APITEST.EXE		Example application
	APITEST.C		Source for APITEST.EXE

	APITEST.MAK		makefile for APITEST
Win16 Run-Time
	APOGEE.DLL		Camera Control Library
	UTIL16.DLL		Win16 thunk DLL for Util32.DLL
	UTIL32.DLL		Win32 utility library (95/NT)
Win32 Development
	APOGEE32.LIB		Main library
	APCCD.H			High level include file
	APLOW.H			Low level include file
	APERR.H			Extended error code constants

	APITEST.EXE		Example application
	APITEST.C		Source for APITEST.EXE

	APITEST.DSW		project file for APITEST
Win32 Run-Time
	APOGEE32.DLL		Camera Control Library
	UTIL32.DLL		Win32 utility library (95/NT)


Library Organization


The Apogee Camera Control API consists of two levels of interface functions. The high-level functions 
should be the first choice for application development, since they provide all the functionality necessary to 
configure the camera and acquire images. This document describes the high-level API routines only. The 
low-level routines are described in a separate document, which also contains a more detailed description 
of the camera interface hardware.


High-Level API Functions


The high-level functions are prototyped in the file "APCCD.H", along with some useful macro definitions 
and type declarations unique to the Apogee API.
System routines and error reporting


get_error	Returns extended error value if any API routine returns CCD_ERROR.

get_open_error	Returns extended error information if open_camera() returns 0.

get_version	Returns library version number.

CCD controller access


open_camera	Opens a virtual camera channel and returns a handle to the CCD 
controller.

get_camdata	Returns copy of the camera characterization structure.

close_camera 	Closes a virtual camera channel and releases all its resources back to 
the system.


Image Acquisition and Readout


set_mask	Sets the global interrupt mask to be used during acquire_image data 
transfers.

set_gain	Sets the camera gain on dual gain systems.

set_shutter	Opens or closes the camera shutter.

config_camera	Passes acquisition and dynamic configuration parameters to the camera 
controller.

config_slice	Passes slice mode acquisition parameters to the camera controller.

start_exposure	Begins a camera exposure operation. Optionally, sets the shutter and 
trigger operation mode.

check_exposure	Tests the "exposure done" bit of the controller.

check_trigger	Tests the external "trigger" bit of the controller.

check_image	Tests the "frame done" bit of the controller. Although the Apogee CCD 
controller is not a frame readout device, the "frame done" bit indicates the 
completion of any previous flush operation.

acquire_image	Reads an entire image from the CCD into a caller-specified image buffer. 
This routine may be restricted depending on the active operating system. 
Refer to the section on readout modes for more information.

acquire_slice	Reads a single slice image from the CCD into a caller-specified image 
buffer.

check_line	Tests the "line done" bit of the controller. Used primarily in line mode 
readout routines.

acquire_line	Used with line mode readout to transfer a single line of image data from 
the controller to the host computer. Refer to the section on readout 
modes for more information on the usage of this function.

flush_image	Typically used in line mode readout routines to flush the remaining rows 
on the CCD after a complete image has been transferred to the host 
computer. Refer to the section on readout modes for more information.

get_acquire_priority_class	Control process priority class used during acquisition.
set_acquire_priority_class

get_acquire_thread_priority	Control process thread priority used during acquisition.
set_acquire_thread_priority


Control Functions


set_temp	Sets the target temperature of the internal CCD dewar. Allows the caller 
to specify the desired temperature in degrees Celsius and control the 
operation mode of the temperature control sub-system.

get_temp	Returns the status of the temperature control sub-system and the CCD 
temperature in degrees Celsius.

output_port	Writes an eight bit value to the auxiliary output control port on the CCD 
controller card. Used to control external devices such as relays or 
indicator lamps.

Apogee Camera Control API Function Reference


acquire_image



Syntax      :   STATUS acquire_image (HCCD   ccd_handle,
                                      USHORT caching,
                                      PIMAGE buffer,
                                      USHORT air_wait);



Parameters  :   ccd_handle      valid handle to open CCD device
                caching         use FIFO caching (T/F)
                buffer          pointer to image buffer
                air_wait        flush camera after transfer



Returns     :   CCD_OK if successful, else CCD_ERROR



Description :   This call returns an entire image from the CCD in one
                operation. The current binning and geometry values are
                used to determine the number of pixels to read. The
                caching parameter is used to enable or disable FIFO
                caching on those versions of the controller which support
                this mode of operation. The cached operation is totally
                transparent to the caller. If the air_wait parameter is
                TRUE, the routine waits for the normal "after image"
                flushing to complete and then initiates a continuous
                flushing operation. This routine will return CCD_ERROR
                if the internal frame done bit is not set within 20
                seconds of the exposure time set by the last call to
                config_camera().



Comments    :   Caching can significantly reduce the time required to
                transfer an image from the CCD. The caching parameter should
                always be TRUE unless the controller will not support it. To
                allow efficient internal use of the buffer parameter as a
                memory pointer, the allocated memory area should be at least
                one pixel larger than necessary.


acquire_line



Syntax      :   STATUS acquire_line (HCCD   ccd_handle,
                                     USHORT caching,
                                     PLINE  line_buffer,
                                     USHORT first_call);



Parameters  :   ccd_handle      handle to open CCD device
                caching         use FIFO caching (T/F)
                line_buffer     pointer to buffer to receive line data
                first_call      initial call to routine



Returns     :   CCD_OK if successful, else CCD_ERROR



Description :   Reads a single line of data from the CCD and stores it
                in the buffer pointed to by line_buffer. acquire_line() will
                return an error if the line done bit in the controller is not
                true. If the first_call parameter is TRUE, this routine will
                return CCD_ERROR if the internal frame done bit is not set
                within 20 seconds of the exposure time set by the last call
                to config_camera().





Comments    :   This function is intended for use in applications which use
                extended memory or a fast cached disk drive to store image
                data from the CCD. To allow efficient use of the line_buffer
                parameter as an internal memory pointer, the allocated memory
                area should be at least one pixel larger than necessary. The
                application is responsibile for maintaining consistent
                line-to-line readout timing.


acquire_slice



Syntax      :   STATUS acquire_slice (HCCD   ccd_handle,
                                      USHORT caching,
                                      PIMAGE buffer,
                                      USHORT reverse_enable,
                                      USHORT shutter_gate);
                                      USHORT overshoot);
                                      USHORT fast);



Parameters  :   ccd_handle      valid handle to open CCD device
                caching         use FIFO caching (T/F)
                buffer          pointer to image buffer
                reverse_enable  enable reverse direction charge transfer T/F
                shutter_gate    close/open shutter during charge transfer T/F
                overshoot       image columns to shift after slice
                fast            enable/disable fast mode bit T/F


Returns     :   CCD_OK if successful, else CCD_ERROR



Description :   This call returns a slice image from the CCD in one
                operation. The current slice binning and geometry values
                are used to determine the number of pixels to read. The
                caching parameter is used to enable or disable FIFO
                caching on those versions of the controller which support
                this mode of operation. The cached operation is totally
                transparent to the caller. If the reverse_enable parameter
                is TRUE, the non-slice portion of the sensor will be
                restored to its original position after slice data is
                transferred. If the shutter_gate parameter is TRUE, the
                shutter enable bit will be disabled before and enabled
                after the slice data transfer, this will close and reopen
                an already open shutter. If the overshoot parameter is
                non-zero, the indicated number of rows will be shifted
                out of the camera after the slice data has been
                transferred and the reverse charge transfer has been
                performed. If the fast parameter is TRUE, mode register
                bit 4 will be set during the slice mode acquisition.


Comments    :   Caching can significantly reduce the time required to
                transfer an image from the CCD. The caching parameter should
                always be TRUE unless the controller will not support it. To
                allow efficient internal use of the buffer parameter as a
                memory pointer, the allocated memory area should be at least
                one pixel larger than necessary. If slice mode acquisitions
                are made during a normal exposure, it is the application
                programmers responsibility to ensure that all slice mode
                operations are complete well before the exposure time is
                reached.


check_exposure



Syntax      :   STATUS check_exposure (HCCD ccd_handle);



Parameters  :   ccd_handle      valid handle to open CCD device



Returns     :   CCD_OK if exposure done bit is set, else CCD_ERROR or
                CCD_NOTRDY



Description :   Checks the status of the exposure done bit. If the bit
                is set, the function returns CCD_OK. If not, it returns
                CCD_NOTRDY or CCD_ERROR.



Comments    :   check_exposure() does not modify any of the control bits
                used by the controller, it only tests the exposure done
                bit state. It may be called as often as necessary.


check_image



Syntax      :   STATUS check_image (HCCD ccd_handle);



Parameters  :   ccd_handle      valid handle to open CCD device



Returns     :   CCD_OK if frame done bit is set, else CCD_ERROR or CCD_NOTRDY



Description :   Checks the status of the frame done bit. If there is image
                data available, the function returns CCD_OK. If no data
                is available, it returns CCD_NOTRDY.



Comments    :   check_image() does not modify any of the control bits used
                by the controller, it only tests the frame done bit state.
                It may be called as often as necessary.


check_line



Syntax      :   STATUS check_line (HCCD ccd_handle);



Parameters  :   ccd_handle      valid handle to open CCD device



Returns     :   CCD_OK if image line is ready, else CCD_ERROR or CCD_NOTRDY



Description :   Checks the status of the line done bit. If there is image
                data available, the function returns CCD_OK. If no data
                is available, it returns CCD_NOTRDY.



Comments    :   check_line() does not modify any of the control bits used
                by the controller, it only tests the line done bit state.
                It may be called as often as necessary.


check_trigger



Syntax      :   STATUS check_trigger (HCCD ccd_handle);



Parameters  :   ccd_handle      valid handle to open CCD device



Returns     :   CCD_OK if trigger bit is set, else CCD_ERROR or CCD_NOTRDY



Description :   Checks the status of the external trigger bit. If the bit is
                set, the function returns CCD_OK. If not, it returns CCD_ERROR
                or CCD_NOTRDY.



Comments    :   check_trigger() does not modify any of the control bits
                used by the controller, it only tests the trigger bit state.
                It may be called as often as necessary. It will return
                CCD_ERROR if the external trigger is not active, see
                start_exposure().


close_camera



Syntax      :   STATUS close_camera (HCCD ccd_handle);



Parameters  :   ccd_handle      valid handle to an open CCD device



Returns     :   CCD_OK if operation was successful, else CCD_ERROR



Description :   Removes a CCD handle from the list of active handles and
                releases the control data area for possible reuse.



Comments    :   Once this call is invoked, the old handle becomes invalid.
                The programmer should bear in mind that the handle value
                could be subsequently reassigned to another CCD/controller
                channel. Setting the CCD handle to 0 after the call to
                close_camera() guarantees that subsequent (illegal) API
                calls, using the now invalid handle, will produce errors.


config_camera



Syntax      :   STATUS config_camera (HCCD   ccd_handle,
                                      USHORT bic_count,
                                      USHORT bir_count,
                                      USHORT column_count,
                                      USHORT row_count,
                                      USHORT hbin,
                                      USHORT vbin,
                                      ULONG  timer,
                                      USHORT cable_length,
                                      USHORT use_config);



Parameters  :   ccd_handle      valid handle to an open CCD device
                bic_count       before image column count
                bir_count       before image row count
                column_count    number of columns to read
                row_count       number of rows to read
                hbin            horizontal binning factor
                vbin            vertical binning factor
                timer           exposure time in internal units
                cable_length    cable length adjustment
                use_config      reread configuration file (T/F)



Returns     :   CCD_OK if operation was successful, else CCD_ERROR



Description :   Modify the camera acquisition configuration. This routine is
                most commonly used to prepare the camera for subsequent
                exposure and data transfer operations.

                Any of the parameters may be skipped (that is, no new
                value will be written to the control data) if the IGNORE
                value is passed. If new values are present and use_config
                is TRUE, then the configuration file will be loaded
                before the new values are inserted into the control data
                structure. This effectively overrides the configuration
                values for those parameters which are not set to IGNORE.

                Timer values are defined in internal camera units, which
                are related to the camera initialization file [system]tscale
                value. The default value of tscale (1.0) sets timer units
                to .01 seconds. For shuttered cameras, the minimum timer
                value is 20 milliseconds. See the comments section for more
                information.



Comments    :   This function is capable of several different uses: (1) If
                all data parameters except use_config are set to IGNORE, then
                the configuration file will be reloaded from disk; (2) if
                use_config is false, then the internal structure values will
                be modified without the overhead of reloading the
                configuration file, and (3) the configuration data may be
                reloaded and then selectively modified with new parameter
                values.

                The bic_count and bir_count parameters are defined in units of
                camera pixels. The column_count and row_count parameters are
                defined in units of binned pixels, i.e. the acquire_image()
                routine will deliver exactly column_count*row_count pixels.

                The macro #defines SHORT and LONG are used to explicitly
                define the cable_length adjustment value.

                Note that use_config must be set to TRUE to reread the
                camera configuration file.

                To convert seconds to internal timer units, use the following
                "C" code or equivalent;

                double tscale;

                ULONG SecsToTimer (double seconds)
                {
                    return ((ULONG) (seconds * tscale * 100.0 + 0.5));
                }

                where the local variable tscale has been set by retrieving
                the identically named CAMDATA structure element.

                Similarly, an internal timer value can be converted to
                seconds using the following code or equivalent;

                double TimerToSecs(ULONG timer)
                {
                    return ((double) (timer / (100.0 * tscale)));
                }


config_slice



Syntax      :   STATUS config_slice	 (HCCD   ccd_handle,
                                      USHORT bic_count,
                                      USHORT bir_count,
                                      USHORT column_count,
                                      USHORT row_count,
                                      USHORT hbin,
                                      USHORT vbin);



Parameters  :   ccd_handle      valid handle to an open CCD device
                bic_count       before slice column count
                bir_count       before slice row count
                column_count    number of columns to read
                row_count       number of rows to read
                hbin            horizontal binning factor
                vbin            vertical binning factor



Returns     :   CCD_OK if operation was successful, else CCD_ERROR



Description :   Modify the slice mode acquisition configuration.

                Any of the parameters may be skipped (that is, no new
                value will be written to the control data) if the IGNORE
                value is passed.


Comments    :   This routine must be successfully called at least once before
                acquire_slice can be called.

                The bic_count and bir_count parameters are defined in units of
                camera pixels. The column_count and row_count parameters are
                defined in units of binned pixels, i.e. the acquire_slice()
                routine will deliver exactly column_count*row_count pixels.


flush_air



Syntax      :   STATUS flush_air (HCCD   ccd_handle,
                                  USHORT air_wait);



Parameters  :   ccd_handle      valid handle to open CCD device
                air_wait        continuous flush after operation



Returns     :   CCD_OK if successful, else CCD_ERROR



Description :   Flushes any remaining rows after the camera acquisition area
                has been completely transferred from the CCD. Used with Line
                Mode readout applications and internally by the
                acquire_image() function. If the air_wait parameter is TRUE,
                the routine will wait for the initial CAMDATA->air flush to
                complete and then initiate a continuous flushing operation.


flush_image



Syntax      :   STATUS flush_image (HCCD   ccd_handle,
                                    USHORT air_wait);



Parameters  :   ccd_handle      valid handle to open CCD device
                air_wait        continuous flush after operation



Returns     :   CCD_OK if successful, else CCD_ERROR



Description :   Flushes the entire sensor. This function should be called if a
                Line Mode readout is not completed, or if any exposure
                sequence is aborted. If the air_wait parameter is TRUE, the
                routine will wait for the inital CAMDATA->rows flush to
                complete and then initiate a continuous flushing operation.


get_acquire_thread_priority



Syntax      :   STATUS get_acquire_thread_priority (DWORD FAR *dwThread);



Parameters  :   dwThread       pointer to returned thread priority



Returns     :   CCD_OK if operation was successful, else CCD_ERROR



Description :   This routine returns the global thread priority used during
                camera acquisitions.



Comments    :   Application programs can use this routine to save the current
                thread priority. The default thread priority is NORMAL_THREAD,
                see also set_acquire_thread_priority.


get_acquire_priority_class



Syntax      :   STATUS get_acquire_priority_class (DWORD FAR *dwClass);



Parameters  :   dwClass       pointer to returned priority class



Returns     :   CCD_OK if operation was successful, else CCD_ERROR



Description :   This routine returns the global priority class used during
                camera acquisitions.



Comments    :   Application programs can use this routine to save the current
                priority class. The default process priority class is
                HIGH_CLASS, see also set_acquire_priority_class.


get_camdata



Syntax      :   STATUS get_camdata (HCCD     ccd_handle,
                                    PCAMDATA pcamdata);



Parameters  :   ccd_handle      valid handle to an open CCD device
                pcamdata        pointer to returned CAMDATA structure



Returns     :   CCD_OK if operation was successful, else CCD_ERROR



Description :   This routine copies the internal CAMDATA structure
                associated with the given CCD handle into the area
                pointed to by pcamdata.



Comments    :   Application programs should copy the CAMDATA structure after
                a successful call to open_camera() in order to characterize
                the sensor chip and camera hardware options. See the source
                code examples and CAMDATA structure documentation for more
                details.


get_error



Syntax      :   STATUS get_error (HCCD    ccd_handle,
                                  PUSHORT error);



Parameters  :   ccd_handle      valid handle to an open CCD device
                error           pointer to returned error value



Returns     :   CCD_OK if operation was successful, else CCD_ERROR



Description :   This routine returns and resets the error value stored in the
                internal structure corresponding to the indicated CCD handle.
                The error value provides extended error information and should
                be examined after any API routine returns an error. Returned
                error values (CCD_ERR_*) are defined and documented in the
                APCCD.H file.




Comments    :   The get_openerror() routine should be called to return
                extended error information if the open_camera() API routine
                returns zero.


get_openerror



Syntax      :   STATUS get_openerror (void);



Parameters  :   none



Returns     :   Extended error information after open_camera() error



Description :   This routine returns extended error information after the
                open_camera() routine returns zero. Returned error values
                (CCD_OPEN_*) are defined and documented in the APCCD.H file.



Comments    :   The get_error() routine should be called to return extended
                error information from all API routines except open_camera().


get_temp



Syntax      :   STATUS get_temp (HCCD    ccd_handle,
                                 PSHORT  temp_status,
                                 PDOUBLE temp_read);



Parameters  :   ccd_handle      valid handle to open CCD device
                temp_status     pointer to returned sub-system status
                temp_read       pointer to returned temperature



Returns     :   CCD_OK if successful, else CCD_ERROR



Description :   get_temp returns both a status code for the temperature
                control sub-system and the temperature of the CCD as
                measured by the on-board sensor. Before user display,
                temperature measurements should be averaged to increase their
                stability. The application should periodically monitor the
                sub-system status to ensure that the camera temperature is
                being correctly regulated. The following status values may be
                returned;
                CCD_TMP_OFF   - temperature sub-system is OFF
                CCD_TMP_DONE  - temperature sub-system is at ambient
                CCD_TMP_OK    - temperature is at or near desired_temp
                CCD_TMP_RUP   - temperature is increasing towards desired_temp
                CCD_TMP_RDN   - temperature is decreasing towards desired_temp
                CCD_TMP_STUCK - desired_temp was too low, backoff required
                CCD_TMP_MAX   - desired_temp was too high, backoff required



Comments    :   If the temperature control sub-system status is returned as
                CCD_TMP_STUCK or CCD_TMP_MAX, the application should
                quickly indicate this to the user and should optionally
                adjust the last desired temperature to ensure that the sub-
                system is correctly regulating. See the sample code section
                for an example of the correct adjustment.


get_version



Syntax      :   USHORT get_version (void);



Parameters  :   none



Returns     :   Apogee camera control library version number



Description :   This routine returns the library version number. It is very
                important for applications to be able to display this number
                to users. The version number provides important technical
                support information.



Comments    :   The library version number is currently coded as a 3 digit
                hexadecimal number in the form 0xABC, where;
                A - operating system code (0,3,5,9,A)
                    0 - DOS
                    3 - Windows 3.x
                    5 - Windows 95/98
                    9 - Windows NT/2000
                    A - Linux
                B - major version number
                C - minor version number

                In general, minor version number changes represent small
                improvements to internal routines that should not require
                application program modifications or recompilation.
                Applications should compare major version numbers when the
                library is first accessed and should not access any other API
                routines of libraries with different major version numbers.
                The application should be recompiled with updated development
                files to ensure binary compatibility.


open_camera



Syntax      :   HCCD open_camera (USHORT mode,
                                  USHORT test,
                                  PCHAR  cfgname);



Parameters  :   mode            mode bits
                test            test bits
                cfgname         configuration filename



Returns     :   HCCD handle value if successful, 0 if error



Description :   open_camera() initializes a control channel for a
                controller card, loads configuration data from
                the specified file and checks to verify that the
                controller is physically installed. If the specified
                file does not exist or a camera initialization error
                occurs, open_camera() will fail and return a value of
                zero.



Comments    :   This function must be called before any other function
                in the API set, since all other camera control functions
                require a valid CCD handle. If the mode and/or test
                parameters are set to IGNORE, the configuration file values
                will be sent to the camera during the open operation. If
                open_camera() returns zero, extended error information can be
                accessed by calling the get_open_error() routine.


output_port



Syntax      :   STATUS output_port (HCCD   ccd_handle,
                                    USHORT bits);



Parameters  :   ccd_handle      valid handle to open CCD device
                bits            bit pattern to write to port



Returns     :   CCD_OK if successful, else CCD_ERROR



Description :   This function is used to control the auxiliary output
                bits on the CCD controller. These bits may be used to
                operate TTL type relays, lamps, and so on. See the camera
                hardware manual for electronic details



Comments    :   There are a maximum of eight auxiliary output bits on the
                controller interface. The actual number of bits that are
                available to the application is defined by the
                [system]port_bits configuration file entry and stored in the
                CAMDATA structure element port_bits.


reset_flush



Syntax      :   STATUS reset_flush (HCCD ccd_handle);



Parameters  :   ccd_handle      valid handle to an open CCD device



Returns     :   CCD_OK if operation was successful, else CCD_ERROR



Description :   This routine resets the camera controller associated with the
                CCD handle parameter. After the reset operation is complete, a
                continuous flush operation is initiated.



Comments    :   This routine should be called after an application program
                aborts any camera operation. Note that the initiation of a
                continous flush operation does not necessarily guarantee that
                the sensor will be free of charge. Applications that initiate
                another exposure immediately after aborting a camera operation
                should call the flush_image() routine (with air_wait set to
                TRUE), after calling reset_flush() to make sure that residual
                charge is completely cleared from the sensor.


set_acquire_thread_priority



Syntax      :   STATUS set_acquire_thread_priority (DWORD dwThread);



Parameters  :   dwThread       thread priority



Returns     :   CCD_OK if operation was successful, else CCD_ERROR



Description :   This routine sets the global thread priority used during
                subsequent camera acquisitions.



Comments    :   Application programs can use this routine to modify the
                thread priority used in subsequent image acquisition
                routines. The default thread priority is NORMAL_THREAD.
                Valid thread priority constants are;
                    IDLE_THREAD
                    LOWEST_THREAD
                    BELOW_NORMAL_THREAD
                    NORMAL_THREAD
                    ABOVE_NORMAL_THREAD
                    HIGH_THREAD
                    REALTIME_THREAD
                The final process priority is derived from a combination of
                the priority class and the thread priority. The higher the
                priority class and/or thread priority, the more CPU time the
                process will receive to complete its tasks. Setting the
                priority class and/or the thread priority too high may
                adversely affect important system processes and degrade
                overall system performance.
                See also set_acquire_priority_class.


set_acquire_priority_class



Syntax      :   STATUS set_acquire_priority_class (DWORD dwClass);



Parameters  :   dwClass       priority class



Returns     :   CCD_OK if operation was successful, else CCD_ERROR



Description :   This routine sets the global priority class used during
                subsequent camera acquisitions.



Comments    :   Application programs can use this routine to modify the
                priority class used in subsequent image acquisition
                routines. The default process priority class is HIGH_CLASS.
                Valid priority class constants are;
                    IDLE_CLASS
                    NORMAL_CLASS
                    HIGH_CLASS
                    REALTIME_CLASS
                The final process priority is derived from a combination of
                the priority class and the thread priority. The higher the
                priority class and/or thread priority, the more CPU time the
                process will receive to complete its tasks. Setting the
                priority class and/or the thread priority too high may
                adversely affect important system processes and degrade
                overall system performance.
                See also set_acquire_thread_priority.


set_gain



Syntax      :   STATUS set_gain (HCCD   ccd_handle,
                                 USHORT high_gain);



Parameters  :   ccd_handle      valid handle to an open CCD device
                high_gain       activate high gain operations (T/F)



Returns     :   CCD_OK if operation was successful, else CCD_ERROR



Description :   Control the gain setting for subsequent camera operations.



Comments    :   Apogee produces dual gain camera systems that support high
                and normal gain operations. The camera initialization file
                entry [system]gain determines whether the camera hardware
                supports dual gain operation. The [camreg]gain entry
                determines the initial gain value after the camera is
                opened.

                This routine will produce an error if the camera hardware does
                not support dual gain operations.


set_mask



Syntax      :   USHORT set_mask (USHORT new_mask);



Parameters  :   new_mask        new interrupt mask during data transfer



Returns     :   Previous value of data transfer interrupt mask



Description :   This routine sets the internal interrupt mask to be used
                during subsequent image data transfer operations. Within
                operating system limitations, the device IRQ associated with
                any one bit in the new_mask parameter will be inactive during
                image data transfer.



Comments    :   Apogee camera systems are line transfer devices. In order to
                improve row to row timing during the image data transfer phase
                of the acquire_image() and acquire_line() routines, interrupts
                can be temporarily masked. This is nearly always harmless for
                serial interrupts (IRQ 3 and 4), parallel interrupts (IRQ 5
                and 7), and network interface card interrupts (IRQ 5).
                The internal mask value is initially zero, which means that no
                interrupt masking is done during normal data transfer
                operations. If an application program supports interrupt
                masking, the user should have ultimate control. This should
                prevent serious problems that may occur on machines with
                unusual or dynamic interrupt assignments.

                Note that this routine does not require a CCD handle
                parameter, because it affects all subsequent data transfer
                operations, regardless of which interface card or camera head
                is accessed.

                Some operating systems, including all forms of Windows, do not
                allow application programs to directly access the interrupt
                masking hardware. This implies that application programs
                should not rely on the fact that selected interrupts will be
                correctly masked.


set_shutter



Syntax      :   STATUS set_shutter (HCCD   ccd_handle,
                                    USHORT open);



Parameters  :   ccd_handle      valid handle to an open CCD device
                open            open/close the shutter (T/F)



Returns     :   CCD_OK if operation was successful, else CCD_ERROR



Description :   This routine opens or closes the shutter of the indicated
                camera. This allows an application to directly control the
                exposure time.



Comments    :   Application programs can transfer camera data without
                modifying data values by calling config_camera() with the
                minimum exposure time and start_exposure() with the shutter
                disabled.


set_temp



Syntax      :   STATUS set_temp (HCCD   ccd_handle,
                                 DOUBLE desired_temp,
                                 USHORT function);



Parameters  :   ccd_handle      valid handle to open CCD device
                desired_temp    desired temperature, in degrees C
                function        temperature control function



Returns     :   CCD_OK if successful, else CCD_ERROR



Description :   This routine allows the application to initiate a temperature
                sub-system control operation. The following operations are
                supported;
                CCD_TMP_SET - attempt to stabilize the CCD at desired_temp
                CCD_TMP_AMB - allow temperature sub-system to reach ambient
                CCD_TMP_OFF - turn temperature sub-system off



Comments    :   Applications that activate the temperature control sub-system
                should periodically monitor the sub-system status by calling
                get_temp() to ensure that the system is regulating properly.


start_exposure



Syntax      :   STATUS start_exposure (HCCD   ccd_handle,
                                       USHORT shutter_en,
                                       USHORT trigger_mode,
                                       USHORT block,
                                       USHORT flushwait);



Parameters  :   ccd_handle      valid handle to open CCD device
                shutter_en      shutter enable/disable (T/F)
                trigger_mode    trigger external/internal (T/F)
                block           use blocking mode (T/F)
                flushwait       wait for frame done state (T/F)



Returns     :   CCD_OK if operation was successful, else CCD_ERROR



Description :   This routine starts an exposure operation using the
                current control channel acquisition values. The shutter_en
                and trigger_mode parameters are used to control the
                operational mode of the shutter and the use of the
                external trigger.



Comments    :   This function may be used in either a blocking or non-
                blocking mode. If it is used in a blocking mode, then it
                will NOT return until the exposure is complete. In the non-
                blocking mode the controller must be checked to determine
                when the exposure is complete and the data is ready to be
                read from the camera. See check_exposure(), check_image()
                and check_trigger().

                If the parameter flushwait is TRUE, the routine will wait
                for the frame done state before starting the exposure.

Camera Control Code Examples


The following example source code is intended to illustrate the basic methods used to initialize the camera 
and transfer data from the camera to host memory. For information about the parameters used with the 
various API functions, refer to the function reference section of this document. The source code file 
APITEST.C contains a complete example program that illustrates the use of these functions.
Library Verification


	// Display library version
	version = get_version();
	system = (version & 0xf00) >> 8;
	major = (version & 0xf0) >> 4;
	minor = (version & 0xf);
	printf("Apogee API Version %x.%x.%x\n", system, major, minor);

	// Reject major version number changes
	if (major != 4) {
		puts("Incompatible library version");
		exit(0);
	}
Camera Initialization and characterization


	// Open camera
	hccd = open_camera(IGNORE, IGNORE, "APCCD.INI");
	if (hccd == 0)
		printf("Open error #%d\n", get_open_error());

	// Get camera structure for characterization
	if (get_camdata(hccd, &cdLocal) != CCD_OK)
		puts("Couldn't get CAMDATA structure");

	// Store camera characterization values
	max_cols = cdLocal.imgcols;
	max_rows = cdLocal.imgrows;
	cache_ok = cdLocal.caching;
	gain_ok = cdLocal.gain;
	tscale = cdLocal.tscale;

Block Mode Readout


	// Allocate single frame image memory, note extra pixel
	imgbuff = (PUSHORT) malloc ((max_cols * 2) * max_rows + 1);
	if (imgbuff == NULL)
		puts("Couldn't allocate image memory");

	// Set exposure time to 200 ms, see config_camera description
	timer = SecsToTimer(0.2);

	// Tell camera which image area to transfer
	ok = config_camera(hccd,
			cdLocal.bic, cdLocal.bir,	// columns, rows to skip
			max_cols, max_rows,		// columns, rows to read
			1, 1,				// column, row binning
			timer,				// exposure time
			IGNORE,				// cable length
			FALSE);				// reread configuration file
	if (ok != CCD_OK)
		puts("config_camera didn't work");

	// Start a normal shuttered exposure
	ok = start_exposure(hccd, TRUE, FALSE, FALSE, TRUE);
	if (ok != CCD_OK)
		puts("start_exposure didn't work");

	// Transfer image data, use caching if available, wait for flush
	ok = acquire_image(hccd, cdLocal.caching, imgbuff, TRUE);
	if (ok != CCD_OK)
		puts("acquire_image didn't work");


Inserting calls to check_exposure() and check_image() after the start_exposure() routine and before the 
acquire_data() routine can be used to allow application programs to perform other operations during long 
exposures. The acquire_image() routine has been internally optimized and is much more efficient than the 
Line Mode equivalent illustrated below.

Line Mode Readout


	// Allocate single line image memory, note extra pixel
	max_cols = cdLocal.imgcols;
	imgbuff = (PUSHORT) malloc (max_cols * 2 + 1);
	if (imgbuff == NULL)
		puts("Couldn't allocate image memory");

	// Set exposure time to 20 ms, see config_camera description
	timer = SecsToTimer(0.02);

	// Tell camera which image area to transfer
	ok = config_camera(hccd,
			cdLocal.bic, cdLocal.bir,	// columns, rows to skip
			max_cols, max_rows,		// columns, rows to read
			1, 1,				// column, row binning
			timer,				// exposure time
			IGNORE,				// cable length
			FALSE);				// reread configuration file
	if (ok != CCD_OK)
		puts("config_camera didn't work");

	// Start a normal shuttered exposure
	ok = start_exposure(hccd, TRUE, FALSE, FALSE, TRUE);
	if (ok != CCD_OK)
		puts("start_exposure didn't work");

	// Readout in line mode, note first call waits for exposure to complete
	max_rows = cdLocal.imgrows;
	for (i=0; i<max_rows; i++)
	if (acquire_line(hccd, cdLocal.caching, imgbuf, i==0) != CCD_OK)
		printf("Error reading row #%d\n", i);

// Clear rest of sensor of residual charge, wait for completion
if (flush_air(hccd, TRUE) != CCD_OK)
puts("Flush operation failed");;

In Line Mode, it is up to the programmer to start the post-acquisition camera flush operation. The 
check_exposure() routine can be used after start_exposure() to perform operations while the exposure 
time is being monitored by the camera. Significant delays in reading out the camera, either by performing 
time consuming operations after the exposure is complete or during data transfer phase of the operation, 
may cause higher or irregular dark current components in the image data. To guarantee data integrity, 
timing irregularities in calls to acquire_line() should be minimized.

Temperature Regulation


	// Get the current temp and status
	// Automatically adjust if range error
	if (get_temp(hccd, &status, &temp) == CCD_OK) {
		temp = rolling_average(temp);
		if (status == CCD_TMP_STUCK)
			set_temp(hccd, temp+cdLocal.temp_backoff, CCD_TMP_SET);
		else if (status == CCD_TMP_MAX)
			set_temp(hccd, temp-cdLocal.temp_backoff, CCD_TMP_SET);
	}


The rolling_average() routine stabilizes single reported temperature values by averaging. The details are 
left to the application programmer. If the CCD_TMP_STUCK or CCD_TMP_MAX status values are 
reported, the application should adjust the desired temperature to ensure that the temperature control 
sub-system is regulating properly.
Camera Closure


	// Close the camera channel
	if (close_camera(hccd) == CCD_OK)
		hccd = 0;


Setting the CCD handle to zero after successful closure makes sure that subsequent API calls using the 
now invalid handle will return errors.

Camera Control Block

The Apogee camera control API is based on the concept of virtual camera control channels, each of which 
has its own set of parameters. The control data structure, or control block, which holds the control 
parameters for a camera is defined in the file APCCD.H, and is shown below. Each open camera control 
channel is assigned one of these structures. Applications can get a binary copy of this structure by calling 
the get_camdata() routine.

typedef struct {
    USHORT      base;           /* base address of controller card          */
    HCCD        handle;         /* assigned channel handle value            */
    USHORT      mode;           /* mode bits                                */
    USHORT      test;           /* test bits                                */
    USHORT      rows;           /* chip geometry - total rows (lines)       */
    USHORT      cols;           /* chip geometry - total columns (pix/row)  */
    USHORT      imgrows;        /* imaging rows in ROI                      */
    USHORT      imgcols;        /* imaging columns in ROI                   */
    USHORT      bir;            /* before-image line count                  */
    USHORT      bic;            /* before-image columns to skip             */
    USHORT      skipr;          /* number of rows in interface pipeline     */
    USHORT      skipc;          /* number of pixels in interface pipeline   */
    USHORT      hbin;           /* horizontal binning factor                */
    USHORT      vbin;           /* vertical binning factor                  */
    USHORT      rowcnt;         /* binned rows in ROI                       */
    USHORT      colcnt;         /* binned columns in ROI                    */
    USHORT      hflush;         /* horizontal binning factor (flushing)     */
    USHORT      vflush;         /* vertical binning factor (flushing)       */
    USHORT      air;            /* after-image line count                   */
    USHORT      aic;            /* after-image columns to skip              */
    USHORT      shutter_en;     /* shutter mode, enable or disable          */
    USHORT      trigger_mode;   /* trigger mode, external or normal         */
    USHORT      caching;        /* FIFO caching on/off                      */
    USHORT      gain;           /* high gain available 1/0                  */
    ULONG       timer;          /* timer count value                        */
    USHORT      cable;          /* cable length mode, long or short         */
    USHORT      data_bits;      /* bit depth of camera pixels               */
    DOUBLE      tscale;         /* timer calibration scaling factor         */
    DOUBLE      target_temp;    /* desired final temp of dewar              */
    DOUBLE      temp_backoff;   /* suggested temp adjustment at max/min     */
    DOUBLE      temp_cal;       /* temp calibration factor                  */
    DOUBLE      temp_scale;     /* temp scaling factor                      */
    DOUBLE      temp_min;	      /* min desired temp                         */
    DOUBLE      temp_max;       /* max desired temp                         */
    USHORT      port_bits;      /* TTL port bits available to user <= 8     */
    USHORT      oflush;         /* vertical flush binning offset            */
    USHORT      frame_timeout;  /* frame done timeout                       */
    USHORT      line_timeout;   /* line done timeout                        */
    USHORT      slice;          /* slice acquisitions available 1/0         */
    USHORT      slice_time;     /* minimum slice shutter time               */
    USHORT      camreg;         /* Gdata for serial output to cam head      */
    SHORT       gotcfg;         /* T if cfg prev loaded, F otherwise        */
    CHAR        cfgname[128];   /* camera configuration file name           */
    USHORT      reg[12];        /* controller register mirrors              */
    USHORT      old_cam;        /* old camera interface mode=test=0         */
    USHORT      reg_offset;     /* PPI register offset                      */
    USHORT      error;          /* contains error bits for particular chan  */
    USHORT      errorx;         /* extended error information               */
    } CAMDATA;

The individual elements of the CAMDATA structure are described as follows:


USHORT base	The base address of the ISA controller card on the PC I/O bus. Each 
interface card occupies eight 16-bit register adresses on the bus, or 16 
bytes, ranging from base+0x00 to base+0x0f.

HCCD handle	When a virtual control channel is opened it is assigned a handle value. 
This value is used by almost all the API functions in order to locate the 
correct parameter data for a particular camera.

USHORT mode	The mode bits are passed directly to the CCD controller by the API 
without any intermediate processing. These bits are factory-defined. 
Refer to the camera technical discussion for additional information.

USHORT test	The test bits are passed directly to the CCD controller by the API without 
any intermediate processing. These bits are factory-defined. Refer to the 
camera technical discussion for additional information.

USHORT rows	The number of physical rows on the CCD device.

USHORT cols	The number of physical columns on the CCD device.

USHORT imgrows	The number of rows in the ROI, unbinned.

USHORT imgcols	The number of columns in the ROI, unbinned.

USHORT rowcnt	The number of binned rows in the ROI.

USHORT colcnt	The number of binned columns in the ROI.

USHORT aic	The number of unbinned columns to flush following the ROI. This value is 
calculated internally and should not be altered by user code.

USHORT bic	The number of unbinned columns to skip over prior to the start of the 
ROI.

USHORT hbin	The horizontal binning factor.

USHORT vbin	The vertical binning factor.

USHORT hflush	The horizontal binning factor used during flushing.

USHORT vflush	The vertical binning factor used during flushing.

USHORT bir	The number of rows to skip over prior to the start of the ROI.

USHORT air	The number of rows to flush from the CCD following the ROI. This value 
is calculated internally and should not be altered by user code.

USHORT skipc	If the camera controller supports caching, this value determines how 
many pixels are in the cache pipeline.

USHORT skipr	If the camera controller supports caching, this value determines how 
many rows are in the cache pipeline.

USHORT gain	This value is 1 if the camera hardware supports dual gain operation.

USHORT shutter_en	Sets the shutter operation mode. If FALSE, the shutter will not 
automatically open during an exposure, otherwise it will open for the 
duration of the exposure time.

USHORT trigger_mode	Determines the exposure trigger source, which is typically internal for 
most applications.

USHORT caching	This value is 1 if the camera interface hardware supports a readout 
cache.

ULONG timer	This is the default exposure time value.

DOUBLE tscale	The timer scaling factor. This is related to the internal clock rate of the 
CCD controller and is established at the factory. The value is provided 
with each camera. The default value of 1.0 implies that config_camera 
timer values are in units of .01 seconds.
	
USHORT cable	Determines the control signal timing compensation to be used with short 
or long control cable lengths.

USHORT data_bits	This value allows the application program to determine the bit depth of 
camera pixel data. This value is 12, 14, or 16.

USHORT port_bits	Determines the number of TTL output bits available on the camera output 
port. This value is less than or equal to 8.

DOUBLE target_temp	The default desired target temperature of the internal CCD dewar. The 
value is specified in degrees Celsius.

DOUBLE temp_backoff	The suggested temperature difference to be used to adjust the target 
temperature if either a minimum or maximum controller error is reported.

DOUBLE temp_cal	The temperature controller calibration factor. Established at the factory 
and provided with each camera.

DOUBLE temp_scale 	The temperature scaling factor for the internal CCD dewar. Established at 
the factory and provided with each camera.

DOUBLE temp_min 	The theoretical minimum temperature that this subsytem can reach.

DOUBLE temp_max 	The theoretical maximum temperature that this subsytem can reach.

USHORT oflush 	Temporary value used during pre-exposure flushing.

USHORT frame_timeout 	Timeout limit for frame done waits.

USHORT line_timeout 	Timeout limit for line done waits.

USHORT slice 	If this value is 1, the sensor supports slice mode acquisition.

USHORT slice_time 	Minimum shutter close time during slice mode acquisitions.

CHAR cfgname[]	The name of the current INI configuration file for this virtual camera 
control channel.

SHORT gotcfg	TRUE if the configuration file was opened and read successfully.

USHORT reg[12]	An array of "mirrors" of the camera control and status I/O registers. Used 
for read-modify-write operations.

USHORT old_cam	Previous camera interfaces required test and mode values of 0. These 
interfaces do not support readout caching or vertical and horizontal flush 
optimizations. This entry is set to one (1) if these internal restrictions 
apply.

USHORT reg_offset	This value is present to support multiple PPI cameras attached to a 
single the parallel port interface. It is the register offset added to the 
normal base register to access the associated camera registers. The 
default value is zero.

USHORT camreg	Data to be sent to the CCD camera head for special-purpose 
configurations.

USHORT error	A bit-mapped value containing error status bits. This number is returned 
by the get_error() subroutine to the application whenever an error is 
returned by an API function. The value can be used to help determine the 
cause of the error.

Using the INI Configuration File


The API reads camera characterization and initialization values from a common  INI format configuration 
file. This type of file is organized into sections and parameters. The format of the INI file is fixed and 
should not be modified in order to maintain compatibility with future version of Apogee products.

An initialization file is always opened and read during each call to the open_camera() API routine. The 
initialization file may also by opened and reread during subsequent config_camera() calls. An error occurs 
if the initialization file does not include all of the required entries. Optional entries have a default value if 
they are not present or the configuration file value is illegal.
INI Configuration File Structure

Initialization file section names are text lines with the section name enclosed in square brackets. Section 
names are case insensitive. All initialization entries must follow the section name to which they belong. If 
section names are duplicated in the INI file, only the first occurrence will be read.

Initialization entries are non-comment text lines of the form;

keyname=keyvalue ;comment

Keynames are case insensitive, space characters between the keyname and keyvalue strings are ignored. 
Keyvalue strings contain all characters up to an optional comment field or the end of the line. If keynames 
are duplicated in any section, only the first occurrence will be read. Keynames may appear in more than 
one section.

Comment lines start with a semi-colon ";" character. They may appear anywhere in the file.
Required entries

The following entries must be defined or a configuration file error will be reported;

[system]
base

[geometry]
rows
columns

[System] Section Entries


Entry Name :	base
Default value :	none
Value range :	none
Purpose :	This entry defines the hexadecimal base address of the camera interface card. 
open_camera() will return CCD_OPEN_LOOPTST if the base address is incorrect or the 
interface card is not installed.

Entry Name :	reg_offset
Default value:	0
Value range :	0..240
Purpose :	Define the register offset of the associated PPI camera.

Entry Name :	c0_repeat
Default value:	1
Value range :	1..64k-1
Purpose :	This parameter defines a repeat count to slow the parallel port phase transitions so the 
PPI cameras have time to react.

Entry Name :	mode
Default value:	0
Value range :	0..15
Purpose :	Define the default value of the mode parameter to the open_camera() API routine.

Entry Name :	test
Default value :	0
Value range :	0..15
Purpose :	Define the default value of the test parameter to the open_camera() API routine.

Entry Name :	shutter
Default value :	OFF = 0
Value range :	ON or TRUE = 1, else 0
Purpose :	Default value of the shutter_enable parameter to the start_exposure() API routine. Value 
string is case insensitive.

Entry Name :	trigger
Default value :	OFF = 0
Value range :	ON or TRUE = 1, else 0
Purpose :	Default value of the trigger_mode parameter to the start_exposure() API routine. Value 
string is case insensitive.

Entry Name :	slice
Default value :	OFF = 0
Value range :	ON or TRUE = 1, else 0
Purpose :	This entry controls whether slice mode acquisitions are supported by the sensor. If the 
value is 0, calls to config_slice() and acquire_slice() will return errors.

Entry Name :	slice_time
Default value :	200
Value range :	unsigned short integer greater than 0
Purpose :	This value determines the minimum time between shutter close and open commands in 
slice mode acquisitions that control the shutter. The value is defined in milliseconds.

Entry Name :	caching
Default value :	OFF = 0
Value range :	ON or TRUE = 1, else 0
Purpose :	This entry defines whether the camera interface supports cached image data transfers. If 
this value is ON and the cache parameter to the acquire_image() or acquire_line() API 
routine is also TRUE, caching will be used during the transfer. This entry will be reset to 
OFF if the mode and test entries are both 0.

Entry Name :	gain
Default value :	OFF = 0
Value range :	ON or TRUE = 1, else 0
Purpose :	This entry determines whether the camera hardware supports dual gain operation.

Entry Name :	frame_timeout
Default value :	20
Value range :	unsigned short integer greater than 0
Purpose :	This value determines the base timeout value used in internal routines when waiting for 
the frame done bit. The value is defined in seconds.

Entry Name :	line_timeout
Default value :	1
Value range :	unsigned short integer greater than 0
Purpose :	This value determines the timeout value used in internal routines when waiting for the line 
done bit. The value is defined in seconds.

Entry Name :	cable
Default value :	SHORT = 0
Value range :	LONG = 1, else 0
Purpose :	This entry determines whether the camera data cable delivered with your system requires 
special interface timing because of its length.

Entry Name :	data_bits
Default value :	16
Value range :	{12,14,16}
Purpose :	This entry defines the bit depth of camera pixel values.

Entry Name :	port_bits
Default value :	8
Value range :	0..8
Purpose :	This entry defines how many bits are available to be used by the output_port() API 
routine.

Entry Name :	tscale
Default value :	1.0
Value range :	double real
Purpose :	This value defines the exposure time constant used by the camera control library. It 
should not be modified by user software. Applications must retrieve this value to convert 
internal timer units to/from seconds. See the description of config_camera() for details.

[Geometry] Section Entries


Entry Name :	columns
Default value :	none
Value range :	1..4096
Purpose :	This entry defines the virtual number of pixel columns on the sensor surface. To get the 
largest possible image from caching controllers, read the geometry note below. This 
number may be larger than the physical number of sensor columns.

Entry Name :	rows
Default value :	none
Value range :	1..4096
Purpose :	This entry defines the virtual number of pixel rows on the sensor surface. To get the 
largest possible image from caching controllers, read the geometry note below. This 
number may be larger than the physical number of sensor rows.

Entry Name :	bic
Default value :	5
Value range :	1..4096
Purpose :	This entry defines the number of columns at the beginning of each pixel row that are non-
imaging (bic = before image columns).

Entry Name :	bir
Default value :	3
Value range :	1..4096
Purpose :	This entry defines the number of rows at the beginning of the CCD that are non-imaging 
(bir = before image rows).

Entry Name :	skipc
Default value :	4
Value range :	unsigned
Purpose :	This entry defines the number of pixels that must be read from the camera fifo to clear or 
stabilize the data transfer pipeline. To get the largest possible image from caching 
controllers, read the geometry note below.

Entry Name :	skipr
Default value :	2
Value range :	unsigned
Purpose :	This entry defines the number of rows that must be read from the camera fifo to clear or 
stabilize the data transfer pipeline. To get the largest possible image from caching 
controllers, read the geometry note below.

Entry Name :	imgcols
Default value :	columns - bic - skipc
Value range :	1..4096
Purpose :	This entry defines the number of imaging columns on the sensor surface.

Entry Name :	imgrows
Default value :	rows - bir - skipr
Value range :	1..4096
Purpose :	This entry defines the number of imaging rows on the sensor surface.


Entry Name :	hflush
Default value :	1
Value range :	1..8
Purpose :	This entry defines the value of the horizontal binning parameter used during camera pre-
exposure and intra-exposure flush operations. This entry will be reset to 1 if the mode and 
test entries are both 0.


Entry Name :	vflush
Default value :	1
Value range :	1..64
Purpose :	This entry defines the value of the vertical binning parameter used during camera pre-
exposure and intra-exposure flush operations. This entry will be reset to 1 if the mode and 
test entries are both 0.


[Temp] Section Entries


Entry Name :	target
Default value :	0.0
Value range :	-40.0..40.0
Purpose :	Define the default target temerature of the camera temperature sub-system. 

Entry Name :	backoff
Default value :	2.0
Value range :	double real
Purpose :	Define the suggested size to decrement or increment a target temperature that causes 
the cooling sub-system to return CCD_TMPSTUCK or CCD_TMPMAX status values.

Entry Name :	temp_cal
Default value :	0.0
Value range :	double real
Purpose :	Define the temperature calibration intercept value. Internal temperature control values are 
calculated using the formula; DacValue = desired_temp * temp_scale + temp_cal;

Entry Name :	temp_scale
Default value :	1.0
Value range :	double real
Purpose :	Define the temperature calibration slope value. Internal temperature control values are 
calculated using the formula; DacValue = desired_temp * temp_scale + temp_cal;


[CamReg] Section Entries


Entry Name :	gain
Default value :	0
Value range :	0..1
Purpose :	Define the initial value of the camera gain. If the camera system supports dual gain, see 
[system] gain, and this value is 1, the camera will initially acquire data using the "high" 
gain setting.

Entry Name :	opt1
Default value :	0
Value range :	0..1
Purpose :	Define the initial value of the camera option 1 setting. If this value is 1, the option will be 
active.

Entry Name :	opt2
Default value :	0
Value range :	0..1
Purpose :	Define the initial value of the camera option 2 setting. If this value is 1, the option will be 
active.


The values contained in the INI file are used as a starting point for CCD operation and must be defined to 
some set of rational values. The following values in the sample INI file may or may not be appropriate for 
the given application. Each Apogee camera is provided with a default INI file containing generic values. 
These values may be modified later by the user as experimental conditions warrant.

The initialization file [geometry] section entries are assumed to correctly define the total CCD imaging 
area. These values are used to determine the maximum imaging area as well as to determine legal 
combinations of binning and offset parameters to make sure they are in the imaging area of the sensor.

It is assumed that application programs may use the entries in the following way;

[geometry]
columns = virtual pixel column count on sensor
bic = non-imaging pixels at the beginning of each line > skipc
imgcols = maximum count of imaging pixels in any line
skipc = subimage discard column count >=2

therefore the initial aic = columns - imgcols - bic >= 1
this is the count of non-imaging pixels at the end of each line

rows = virtual pixel row count on sensor
bir = non-imaging lines at the top of the sensor > skipr
imgrows = maximum count of imaging rows
skipr = subimage discard row count >=2

therefore the initial air = rows - imgrows - bir >= 1
this is the count of non-imaging rows at the bottom of the sensor

For a more detailed discussion of the INI file settings, contact Apogee or GKR Computer Consulting.

Sample INI file


[system]
  base = 290			; CCD Controller card base address, in hex
  mode = 0				; Initial mode bits, determined by factory
  test = 0				; Initial test bits, determined by factory
  shutter = ON			; Shutter operation enabled
  trigger = OFF			; External trigger operation enabled
  caching = ON			; FIFO caching available
  gain = OFF			; Dual gain available
  slice = OFF			; slice mode supported by this sensor
  slice_time=200			; slice mode shutter operations require 200 ms
  frame_time=20			; frame timeout after exposure time + 20 secs
  line_time=1			; timeout after 1 sec waiting for line done
  cable = SHORT			; Cable length, LONG or SHORT (default)
  port_bits = 8			; TTL port bits available
  data_bits = 16			; Camera pixel bit depth
  tscale = 1.000000		; Timer scaling factor, determined at factory

[geometry]
  columns = 796			; Virtual columns on sensor
  rows = 522			; Virtual rows on sensor
  imgcols = 768			; Largest unbinned column count
  imgrows = 512			; Largest unbinned row count
  bic = 16				; Before image column count
  bir = 6				; Before image row count
  skipc = 4				; Column pipeline count
  skipr = 2				; Row pipeline count
  hflush = 4			; Horizontal flush binning factor
  vflush = 4			; Vertical flush binning factor

[temp]
  target = -10.0			Target CCD temperature
  cal = 155.0			Temperature calibration factor
  scale = 2.1			Temperature scaling factor
  backoff = 2.0			Temperature back-off

[camreg]
  gain = 0				Initial gain setting
  opt1 = 0				Factory defined option 1
  opt2 = 0				Factory defined option 2

Software Conversion To Other Platforms


Full source code for the Apogee API library may be provided to cross platform developers on request. The 
source code was designed to port easily to other application platforms. It was developed and has been 
tested under all forms of Windows as well as the Linux operating systems, but should be largely 
compatible with standard compilers under any modern operating system.

If you attempt to port the source code to another development environment, the key points to be aware of 
are the following;

1.	The macros INPW and OUTPW perform direct port I/O and may have to be redefined for your 
compiler environment.

2. Some operating systems require special permission to allow high-level application code to access 
low-level hardware directly. Refer to the operating system documentation and the SDK reference 
for additional information. The Apogee API uses a special system driver supplied be GKR 
Computer Consulting to run under Windows NT and Windows 2000.

3. Data types may have to be redefined based on the operating system or application development 
environment.
CAMERA CONTROL API SPECIFICATION                                              APOGEE INSTRUMENTS INC
58
