/****************************************************************************/
/* Copyright 1995 MBARI                                                     */
/****************************************************************************/
/* Summary  : Camera Microcontroller Interface Module for VxWorks           */
/* Filename : camera.c                                                      */
/* Author   : Douglas Au                                                    */
/* Project  : New ROV                                                       */
/* Version  : Version 1.0                                                   */
/* Created  : 03/21/95                                                      */
/* Modified : 03/21/95                                                      */
/* Archived :                                                               */
/****************************************************************************/
/* Modification History:                                                    */
/* $Header$
 * $Log$
 */
/****************************************************************************/

#include <vxWorks.h>                /* vxWorks system declarations          */
#include <semLib.h>                 /* vxWorks semaphore functions          */
#include <taskLib.h>                /* vxWorks task library functions       */
#include <lstLib.h>                 /* vxWorks linked list library          */
#include <wdLib.h>                  /* vxWorks watch dog timer functions    */
#include <systime.h>                /* vxWorks time and date functions      */
#include <msgQLib.h>                /* vxWorks Message Queue Library        */

#include <mbariTypes.h>             /* MBARI style guide type declarations  */
#include <mbariConst.h>             /* Miscellaneous constants              */

#include <rovPriority.h>            /* MBARI Rov Application Priorities     */
#include <usrTime.h>                /* MBARI time and date functions        */

#include <datamgr.h>                /* Data Manager declarations            */
#include <dm_errno.h>               /* Data Manager error declarations      */
#include "console.h"                /* Topside Console Data Manager Items   */

#include "sio32.h"             	    /* SIO32 hardware and driver information*/
#include "sio32Server.h"            /* Sio32 server communication services  */
#include "sio32Client.h"            /* Sio32 client communication services  */
#include "microCmd.h"               /* Microcontoller command functions     */
#include "tiburon.h"	            /* Tiburon definitions                  */
#include "camera.h"                 /* Camera Can Definitions               */
#include "microDm.h"                /* Micro Data Manager Items & Functions */
#include "microdef.h"
#include "powerDM.h"                /* Power Manager DM Interface           */
#include "powerTypes.h"	     	    /* Power management Data Types          */

#define   Boolean MBool             /* Map microcontroller Boolean to MBool */

#include "applic.h"                 /* Microcontroller applications         */
#include "microcmd.h"               /* Microcontroller commands             */
#include "cam.h"                    /* Camera Microcontroller defines       */
#include "microTask.h"              /* Microcontroller Task IO definitions  */                                    /* Camera Device Name                   */
MLocal char* const cameraMicroName = "STBD_CAMERA";
                                    /* CAMERA Data Mgr Item Name Prefix     */
MLocal char* const cameraAppPrefix  = STBD_CAMERA_DM_PREFIX;

                                    /* Data Manager Item Name Prefix*/

#define CAMERA_DM_PERIOD   100000   /* Camera Data Updatep period 10Hz      */
#define HUMIDITY_DM_PERIOD 10000000 /* Humidity sensor period .1Hz          */
                           
#define CAMERA_IN_STACKSIZE  2000   /* Camera Input Task size & TCB         */
#define CAMERA_OUT_STACKSIZE 3000   /* Camera Output Task size & TCB        */
   
#define LINE_FEED       0x0a        /* Line feed character                  */

#define NUM_TASKS          3	    /* Number of co-operating tasks         */

typedef struct
{
    DM_Item stbdTiltAxis;
    DM_Item portTiltAxis;
}joystickDmItems;

typedef struct
{
    DM_Item focusSetPoint;
    DM_Item focusVelocityGain;
    DM_Item focusPosition;
    DM_Item focusControlMode;
    DM_Item zoomSetPoint;
    DM_Item zoomRate;
    DM_Item zoomVelocityGain;
    DM_Item zoomPosition;
    DM_Item zoomControlMode;
    DM_Item PWMRate;

    DM_Item colorBarsMode;
    DM_Item menuMode;
    DM_Item pageState;
    DM_Item itemState;
    DM_Item upState;
    DM_Item downState;
    DM_Item irisMode;
    DM_Item irisValue;
    DM_Item gainMode;
    DM_Item gainValue;
    DM_Item detailMode;
    DM_Item shutterSpeed;
    DM_Item sceneFile;
    DM_Item whiteBalMode;
    DM_Item autoWhiteBalMode;
    DM_Item totalPedstal;
    DM_Item redPedstal;
    DM_Item bluePedstal;
    DM_Item redGain;
    DM_Item blueGain;
} cameraItems;


typedef struct                      /* Camera Data Manager Item Handles     */
{
    microDmItems microDm;           /* Microcontroller Data Manager Items   */

    DM_Item canWaterAlarm;          /* Housing Water Alarm Detected         */

    DM_Item microHumidity;          /* Humidity Sensor Value % RH           */
    DM_Item humidityAlarm;          /* Humidity Alarm Status                */
    DM_Item humidityWarnThresh;     /* Humidity Warn Threshold              */
    DM_Item humidityAlarmThresh;    /* Humidity Alarm Threshold             */

    DM_Item microTemperature;       /* Temperature sensor value deg C       */
    DM_Item temperatureAlarm;       /* Temperature Alarm Status             */
    DM_Item tempWarnThresh;         /* Temperature Warn Threshold           */
    DM_Item tempAlarmThresh;        /* Temperature Alarm Threshold          */

    cameraItems camItems;

    joystickDmItems joystickItems;    

} cameraDmItems;

/****************************************************************************/

Void stbdCameraInTask(Reg cameraDmItems *dmItems, microIOControl *microIOCtrl);

Void stbdCameraOutTask(Reg cameraDmItems* dmItems, microIOControl *microIOCtrl);

MLocal Word processCameraSRQ( Reg cameraDmItems* dmItems,
                microIOControl *microIOCtrl );

MLocal STATUS cameraDmItemInit( cameraDmItems* dmItems,
    sio32Chan* cameraDataChan );

MLocal STATUS createCameraDmItems (  Nat16 camera, cameraItems *dmItems,
    const char* cameraAppPrefix, const char* cameraName );

MLocal STATUS createCameraAppDmItems( cameraDmItems *dmItems,
    const char* cameraAppPrefix, const char* cameraName );

MLocal STATUS writeCamCtrlString(sio32Chan *camDataChan, Nat16 camera,
     DM_Item ctrlStringDm);

MLocal STATUS sendCameraCommand( sio32Chan *sio32DataChan, Nat16 camera,
      char *camCommand );

MLocal STATUS writeZoomSetPoint( sio32Chan *sio32DataChan, DM_Item setPointDm);
MLocal STATUS writeFocusSetPoint( sio32Chan *sio32DataChan, DM_Item setPointDm);

MLocal STATUS writeZoomRate( sio32Chan *sio32DataChan, DM_Item zoomRateDm);

MLocal STATUS writePWMRate( sio32Chan *sio32DataChan, DM_Item PWMRateDm);
MLocal STATUS writeZoomVelocityGain( sio32Chan *sio32DataChan, 
				        DM_Item velocityGainDm);
MLocal STATUS writeFocusVelocityGain( sio32Chan *sio32DataChan, 
				        DM_Item velocityGainDm);
MLocal STATUS writeZoomControlMode( sio32Chan *sio32DataChan, 
				        DM_Item controlModeDm);
MLocal STATUS writeFocusControlMode( sio32Chan *sio32DataChan, 
				        DM_Item controlModeDm);

MLocal STATUS writeColorBarsMode( sio32Chan *sio32DataChan,
                                        DM_Item controlModeDm);

MLocal STATUS writeMenuMode( sio32Chan *sio32DataChan,
                                        DM_Item controlModeDm);

MLocal STATUS writePageState( sio32Chan *sio32DataChan,
                                        DM_Item controlStateDm);

MLocal STATUS writeItemState( sio32Chan *sio32DataChan,
                                        DM_Item controlStateDm);

MLocal STATUS writeUpState( sio32Chan *sio32DataChan,
                                        DM_Item controlStateDm);

MLocal STATUS writeDownState( sio32Chan *sio32DataChan,
                                        DM_Item controlStateDm);

MLocal STATUS writeIrisMode( sio32Chan *sio32DataChan,
                                        DM_Item controlModeDm);

MLocal STATUS writeIrisValue( sio32Chan *sio32DataChan,
                                        DM_Item irisValueDm);

MLocal STATUS writeGainMode( sio32Chan *sio32DataChan,
                                        DM_Item gainModeDm);

MLocal STATUS writeGainValue( sio32Chan *sio32DataChan,
                                        DM_Item gainValueDm);

MLocal STATUS writeDetailMode( sio32Chan *sio32DataChan,
                                        DM_Item detailModeDm);

MLocal STATUS writeShutterSpeed( sio32Chan *sio32DataChan,
                                        DM_Item shutterSpeedDm);

MLocal STATUS writeSceneFile( sio32Chan *sio32DataChan,
                                        DM_Item sceneFileDm);

MLocal STATUS writeWhiteBalMode( sio32Chan *sio32DataChan,
                                        DM_Item whiteBalModeDm);

MLocal STATUS writeAutoWhiteBalMode( sio32Chan *sio32DataChan,
                                        DM_Item autoWhiteBalModeDm);

MLocal STATUS writeTotalPedstal( sio32Chan *sio32DataChan,
                                        DM_Item totalPedstalDm);

MLocal STATUS writeRedPedstal( sio32Chan *sio32DataChan,
                                        DM_Item redPedstalDm);

MLocal STATUS writeBluePedstal( sio32Chan *sio32DataChan,
                                        DM_Item bluePedstalDm);

MLocal STATUS writeRedGain( sio32Chan *sio32DataChan,
                                        DM_Item redGainDm);

MLocal STATUS writeBlueGain( sio32Chan *sio32DataChan,
                                        DM_Item blueGainDm);

/****************************************************************************/
/* Function    : updateWaterAlarmDm                                         */
/* Purpose     : Reads micro Water Alarm status & updates dmgr items        */
/* Inputs      : Sio32 chan & water alarm status data manager item handles  */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateWaterAlarmDm( sio32Chan *camDataChan, DM_Item canWaterAlarmDm )
{
    Word waterAlarmStatus;          /* Microcontroller Water Alarm Status   */

                                    /* Read Water Alarm Status              */
    if ( (microCommand(camDataChan, CAMERA_APP | GET_WATER_ALARM,
                        &waterAlarmStatus) ) == ERROR)
        return (ERROR);

                                    /* Map from a word to a boolean         */
    waterAlarmStatus = (waterAlarmStatus ? TRUE : FALSE);

                                    /* Write water alarm status to Dmgr     */
    return (writeDmItem(canWaterAlarmDm, &waterAlarmStatus,
             sizeof(waterAlarmStatus)));
} /* updateWaterAlarmDm() */

/****************************************************************************/
/* Function    : initHumidityThreshDm                                       */
/* Purpose     : Read Humidity Thresholds and update data manager item      */
/* Inputs      : Sio32 channel, humidity alarm threshold dm item handles    */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initHumidityThreshDm( sio32Chan *cameraDataChan, DM_Item humidityWarnDm,
    DM_Item humidityAlarmDm )
{
    Int16   warnThresh;             /* Humidity warning threshold           */
    Int16   alarmThresh;            /* Humidity alarm Threshold             */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[3];               /* Command Result from microcontroller  */

                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 3,
	 1, CAMERA_APP | GET_HUMIDITY_THRESH ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update currents        */
    wordsFromBuf(reply, 3, &cmdStatus, &warnThresh, &alarmThresh);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */
    urgentWriteDmItem( humidityAlarmDm, &alarmThresh, sizeof(alarmThresh));
    return (urgentWriteDmItem(humidityWarnDm, &warnThresh, sizeof(warnThresh)));
} /* initHumidityThreshDm() */

/****************************************************************************/
/* Function    : setHumidityThresh                                          */
/* Purpose     : Sets humidity alarm threshold values for 3x5 micro         */
/* Inputs      : Sio32 channel, humidity alarm threshold value              */
/* Outputs     : Return OK or ERROR                                         */
/****************************************************************************/
    MLocal STATUS
setHumidityThresh(sio32Chan *cameraDataChan, Int16 warnThresh, 
    Int16 alarmThresh )
{
    Word    status;                 /* Command Result from microcontroller  */

                                   /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &status, sizeof(status),
        3,  CAMERA_APP | SET_HUMIDITY_THRESH, warnThresh, alarmThresh )
        == ERROR ) return(ERROR);
                                    /* Check command result                  */
    return (wordFromBuf(&status, 0) == CMD_OK ? OK : ERROR);
} /* setHumidityThresh() */

/****************************************************************************/
/* Function    : writeHumidityThresh                                        */
/* Purpose     : Get humidity alarm thresholds from dm and send to micro    */
/* Inputs      : Sio32 channel, humidity threshold dm item handles          */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
writeHumidityThresh( sio32Chan *cameraDataChan, DM_Item humidityWarnDm,
    DM_Item humidityAlarmDm  )
{
    Int16   warnThresh;             /* Humidity warning threshold           */
    Int16   alarmThresh;            /* Humidity alarm Threshold             */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* Command Result from microcontroller  */

                                    /* Read Humidity Thresholds from dm     */
    status = dm_read( humidityWarnDm, (char *) &warnThresh,
         sizeof(warnThresh), (DM_Time *) NULL);

    status = dm_read( humidityAlarmDm, (char *) &alarmThresh,
         sizeof(alarmThresh), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
                                    /* Send command to microcontroller      */
	return (setHumidityThresh(cameraDataChan, warnThresh, alarmThresh));

    return(ERROR);
} /* writeHumidityThresh() */

/****************************************************************************/
/* Function    : updateHumidityDm                                           */
/* Purpose     : Reads micro humidity sensor value & updates dmgr item      */
/* Inputs      : Sio32 chan & humidity sensor data manager item handle      */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateHumidityDm( sio32Chan *cameraDataChan, DM_Item microHumidityDm )
{
    Int16   humidity;               /* Micro Humidity Sensor Value          */
                                    /* Read humidity sensor value           */
    if (microCommand(cameraDataChan, CAMERA_APP | GET_HUMIDITY, &humidity)
        == ERROR) return (ERROR);
                                    /* Write humidity to Data Manager       */
    return (writeDmItem(microHumidityDm, &humidity, sizeof(humidity)));
} /* updateHumidityDm() */

/****************************************************************************/
/* Function    : updateHumidityAlarmDm                                      */
/* Purpose     : Reads humidity alarm status & update dmgr item             */
/* Inputs      : Sio32 chan & humidity alarm data manager item handle       */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateHumidityAlarmDm( sio32Chan *cameraDataChan, DM_Item humidityAlarmDm )
{
    Word alarmStatus;               /* Microcontroller Alarm Status Word    */
    microAlarm humidityAlarmStatus; /* Micro humidity alarm status          */
                                    /* Get Humidity Alarm Status from micro */
    if (microCommand(cameraDataChan, CAMERA_APP | GET_HUMIDITY_ALARM,
         &alarmStatus) == ERROR) return(ERROR);

    humidityAlarmStatus = (microAlarm) alarmStatus;

                                    /* Write humidity alarm to Dmgr         */
    return(writeDmItem(humidityAlarmDm, &humidityAlarmStatus,
        sizeof(humidityAlarmStatus)));
} /* updateHumidityAlarmDm() */

/****************************************************************************/
/* Function    : initTemperatureThreshDm                                    */
/* Purpose     : Read Temperature Thresholds and update data manager item   */
/* Inputs      : Sio32 channel, temperature alarm threshold dm item handles  */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initTemperatureThreshDm( sio32Chan *cameraDataChan, DM_Item temperatureWarnDm,
    DM_Item temperatureAlarmDm )
{
    Int16   warnThresh;             /* Humidity warning threshold           */
    Int16   alarmThresh;            /* Humidity alarm Threshold             */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[3];               /* Command Result from microcontroller  */

                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 3,
	 1, CAMERA_APP | GET_TEMP_ALARM_THRESH ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update currents        */
    wordsFromBuf(reply, 3, &cmdStatus, &warnThresh, &alarmThresh);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    urgentWriteDmItem( temperatureAlarmDm, &alarmThresh, sizeof(alarmThresh));
    return (urgentWriteDmItem(temperatureWarnDm, &warnThresh,
         sizeof(warnThresh)));
} /* initTemperatureThreshDm() */

/****************************************************************************/
/* Function    : setTempThresh                                              */
/* Purpose     : Sets Temperature alarm threshold values for 3x5 micro      */
/* Inputs      : Sio32 channel, Temp alarm threshold value                  */
/* Outputs     : Return OK or ERROR                                         */
/****************************************************************************/
    MLocal STATUS
setTempThresh(sio32Chan *cameraDataChan, Int16 warnThresh, 
    Int16 alarmThresh )
{
    Word    status;                 /* Command Result from microcontroller  */

                                   /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &status, sizeof(status),
        3,  CAMERA_APP | SET_TEMP_ALARM_THRESH, warnThresh, alarmThresh )
        == ERROR ) return(ERROR);
                                    /* Check command result                  */
    return (wordFromBuf(&status, 0) == CMD_OK ? OK : ERROR);
} /* setTempThresh() */

/****************************************************************************/
/* Function    : writeTemperatureThresh                                     */
/* Purpose     : Get temperature alarm thresholds from dm and send to micro */
/* Inputs      : Sio32 channel, temperature threshold dm item handles       */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
writeTemperatureThresh( sio32Chan *cameraDataChan, DM_Item temperatureWarnDm,
    DM_Item temperatureAlarmDm  )
{
    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* Command Result from microcontroller  */

    Int16   warnThresh;             /* Temperature warning threshold        */
    Int16   alarmThresh;            /* Temperature alarm Threshold          */

                                    /* Read Temperature Thresholds from dm  */
    status = dm_read( temperatureWarnDm, (char *) &warnThresh,
         sizeof(warnThresh), (DM_Time *) NULL);

    status = dm_read( temperatureAlarmDm, (char *) &alarmThresh,
         sizeof(alarmThresh), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
                                    /* Send command to microcontroller      */
 	return (setTempThresh(cameraDataChan, warnThresh, alarmThresh));

    return(ERROR);
} /* writeTemperatureThresh() */

/****************************************************************************/
/* Function    : updateTemperatureDm                                        */
/* Purpose     : Reads micro temperature sensor value & updates dmgr item   */
/* Inputs      : Sio32 chan & temperature sensor data manager item handle   */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateTemperatureDm( sio32Chan *cameraDataChan, DM_Item microTempDm )
{
    Int16   temperature;            /* Micro Temperature Sensor Value       */
                                    /* Read temperature sensor value        */
    if (microCommand(cameraDataChan, CAMERA_APP | GET_TEMPERATURE,
        &temperature) == ERROR)
        return (ERROR);
                                    /* Write temperature to Data Manager    */
    return (writeDmItem(microTempDm, &temperature, sizeof(temperature)));
} /* updateTemperatureDm() */

/****************************************************************************/
/* Function    : updateTempAlarmDm                                          */
/* Purpose     : Reads micro temperature alarm status & updates dmgr item   */
/* Inputs      : Sio32 chan & temperature alarm data manager item handle    */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
updateTempAlarmDm( sio32Chan *cameraDataChan, DM_Item tempAlarmDm )
{
    Word alarmStatus;               /* Microcontroller Alarm Status Word    */
    microAlarm tempAlarmStatus;     /* Micro temperature alarm status       */
                                    /* Get TempAlarm Status from micro      */
    if (microCommand(cameraDataChan, CAMERA_APP | GET_TEMP_ALARM_STATUS,
         &alarmStatus) == ERROR) return(ERROR);

    tempAlarmStatus = (microAlarm) alarmStatus;

                                    /* Write temperature alarm to Dmgr      */
    return(writeDmItem(tempAlarmDm, &tempAlarmStatus,
        sizeof(tempAlarmStatus)));
} /* updateTempAlarmDm() */

/****************************************************************************/
/* Function    : initFocusSetPointDm                                        */
/* Purpose     : Read Focus Set Point and update data manager item          */
/* Inputs      : Sio32 channel, Focus Set Point dm item handles             */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initFocusSetPointDm( sio32Chan *cameraDataChan, DM_Item focusSetPointDm )
{
    Int16   focusSetPoint;          /* focus Set Point                      */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_FOCUS_SET_POINT ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update currents        */
    wordsFromBuf(reply, 2, &cmdStatus, &focusSetPoint);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(focusSetPointDm, &focusSetPoint, 
                                                     sizeof(focusSetPoint)));
} /* initFocusSetPointDm() */

/****************************************************************************/
/* Function    : updateFocusSetPointDm                                      */
/* Purpose     : Reads Camera servo Set Point & updates dmgr item           */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateFocusSetPointDm( sio32Chan *cameraDataChan, DM_Item setPointDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */
    Int16  focusSetPoint;               /* Camera setPoint                  */

                                        /* Read Camera Set Point data       */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_FOCUS_SET_POINT ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, &focusSetPoint );
     return(writeDmItem(setPointDm, &focusSetPoint, sizeof(focusSetPoint)));
} /* updateFocusSetPointDm() */

/****************************************************************************/
/* Function    : initZoomSetPointDm                                         */
/* Purpose     : Read Zoom Set Point and update data manager item           */
/* Inputs      : Sio32 channel, Zoom Set Point dm item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initZoomSetPointDm( sio32Chan *cameraDataChan, DM_Item zoomSetPointDm )
{
    Int16   zoomSetPoint;           /* Zoom Set Point                       */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_ZOOM_SET_POINT ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update currents        */
    wordsFromBuf(reply, 2, &cmdStatus, &zoomSetPoint);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(zoomSetPointDm, &zoomSetPoint, 
                                                     sizeof(zoomSetPoint)));
} /* initZoomSetPointDm() */

/****************************************************************************/
/* Function    : updateZoomSetPointDm                                       */
/* Purpose     : Reads Camera servo Set Point & updates dmgr item           */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateZoomSetPointDm( sio32Chan *cameraDataChan, DM_Item setPointDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */
    Int16  zoomSetPoint;                /* Camera Set Point                 */

                                        /* Read Camera Set Point data       */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_ZOOM_SET_POINT ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, &zoomSetPoint );
     return(writeDmItem(setPointDm, &zoomSetPoint, sizeof(zoomSetPoint)));
} /* updateZoomSetPointDm() */

/****************************************************************************/
/* Function    : initZoomRateDm                                             */
/* Purpose     : Read Zoom Rate and update data manager item                */
/* Inputs      : Sio32 channel, Zoom Rate dm item handles                   */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initZoomRateDm( sio32Chan *cameraDataChan, DM_Item zoomRateDm )
{
    Int16   zoomRate;               /* Zoom Rate                            */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_ZOOM_RATE ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update currents        */
    wordsFromBuf(reply, 2, &cmdStatus, &zoomRate);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(zoomRateDm, &zoomRate, sizeof(zoomRate)));
} /* initZoomRateDm() */

/****************************************************************************/
/* Function    : updateZoomRateDm                                           */
/* Purpose     : Reads Camera servo Zoom Rate & updates dmgr item           */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateZoomRateDm( sio32Chan *cameraDataChan, DM_Item zoomRateDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */
    Int16  zoomRate;                    /* Camera Zoom Rate                 */

                                        /* Read Camera Zoom Rate data       */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_ZOOM_RATE ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, &zoomRate );
     return(writeDmItem(zoomRateDm, &zoomRate, sizeof(zoomRate)));
} /* updateZoomRateDm() */

/****************************************************************************/
/* Function    : initFocusPositionDm                                        */
/* Purpose     : Read Focus Position and update data manager item           */
/* Inputs      : Sio32 channel, Focus Position dm item handles             */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initFocusPositionDm( sio32Chan *cameraDataChan, DM_Item focusPositionDm )
{
    Int16   focusPosition;          /* focus Position                     */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_FOCUS_POSITION ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update currents        */
    wordsFromBuf(reply, 2, &cmdStatus, &focusPosition);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(focusPositionDm, &focusPosition, 
                                                     sizeof(focusPosition)));
} /* initFocusPositionDm() */

/****************************************************************************/
/* Function    : updateFocusPositionDm                                      */
/* Purpose     : Reads Camera servo positions & updates dmgr item           */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateFocusPositionDm( sio32Chan *cameraDataChan, DM_Item positionDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */
    Int16  focusPosition;               /* Camera analog positions          */

                                      /* Read Camera position data          */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_FOCUS_POSITION ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, &focusPosition );
     return(writeDmItem(positionDm, &focusPosition, sizeof(focusPosition)));
} /* updateFocusPositionDm() */

/****************************************************************************/
/* Function    : initZoomPositionDm                                         */
/* Purpose     : Read Zoom Position and update data manager item            */
/* Inputs      : Sio32 channel, Zoom Position dm item handles               */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initZoomPositionDm( sio32Chan *cameraDataChan, DM_Item zoomPositionDm )
{
    Int16   zoomPosition;           /* Zoom Position                        */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_ZOOM_POSITION ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update currents        */
    wordsFromBuf(reply, 2, &cmdStatus, &zoomPosition);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(zoomPositionDm, &zoomPosition, 
                                                     sizeof(zoomPosition)));
} /* initZoomPositionDm() */

/****************************************************************************/
/* Function    : updateZoomPositionDm                                       */
/* Purpose     : Reads Camera servo positions & updates dmgr item           */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateZoomPositionDm( sio32Chan *cameraDataChan, DM_Item positionDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */      Int16  zoomPosition;                /* Camera analog positions          */

                                      /* Read Camera position data          */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_ZOOM_POSITION ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, &zoomPosition );
     return(writeDmItem(positionDm, &zoomPosition, sizeof(zoomPosition)));
} /* updateZoomPositionDm() */

/****************************************************************************/
/* Function    : initFocusVelocityGainDm                                    */
/* Purpose     : Read Focus Velocty Gain and update data manager item       */
/* Inputs      : Sio32 channel, Focus Velocity Gain dm item handles         */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initFocusVelocityGainDm( sio32Chan *cameraDataChan, 
                                                 DM_Item focusVelocityGainDm )
{
    Int16   focusVelocityGain;      /* Focus Velocity Gain                  */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_FOCUS_VELOCITY_GAIN ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update currents        */
    wordsFromBuf(reply, 2, &cmdStatus, &focusVelocityGain);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(focusVelocityGainDm, &focusVelocityGain, 
                                                 sizeof(focusVelocityGain)));
} /* initFocusVelocityGainDm() */

/****************************************************************************/
/* Function    : updateFocusVelocityGainDm                                  */
/* Purpose     : Reads Camera servo Velocity Gain & updates dmgr item       */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateFocusVelocityGainDm( sio32Chan *cameraDataChan, DM_Item velocityGainDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */
    Int16  focusVelocityGain;           /* Camera Velocity Gain             */

                                        /* Read Camera Velocity Gain        */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_FOCUS_VELOCITY_GAIN ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, &focusVelocityGain );
     return(writeDmItem(velocityGainDm, &focusVelocityGain, 
                           sizeof(focusVelocityGain)));
} /* updateFocusVelocityGainDm() */

/****************************************************************************/
/* Function    : initZoomVelocityGainDm                                     */
/* Purpose     : Read Zoom Velocty Gain and update data manager item        */
/* Inputs      : Sio32 channel, Zoom Velocity Gain dm item handles          */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initZoomVelocityGainDm( sio32Chan *cameraDataChan, 
                                                 DM_Item zoomVelocityGainDm )
{
    Int16   zoomVelocityGain;       /* Zoom Velocity Gain                   */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_ZOOM_VELOCITY_GAIN ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update currents        */
    wordsFromBuf(reply, 2, &cmdStatus, &zoomVelocityGain);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(zoomVelocityGainDm, &zoomVelocityGain, 
                                                 sizeof(zoomVelocityGain)));
} /* initZoomVelocityGainDm() */

/****************************************************************************/
/* Function    : updateZoomVelocityGainDm                                   */
/* Purpose     : Reads Camera servo Velocity Gain & updates dmgr item       */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateZoomVelocityGainDm( sio32Chan *cameraDataChan, DM_Item velocityGainDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */ 
    Int16  zoomVelocityGain;            /* Camera Velocity Gain             */

                                        /* Read Camera Velocity Gain        */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_ZOOM_VELOCITY_GAIN ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, &zoomVelocityGain );
     return(writeDmItem(velocityGainDm, &zoomVelocityGain, 
                           sizeof(zoomVelocityGain)));
} /* updateZoomVelocityGainDm() */

/****************************************************************************/
/* Function    : initFocusControlModeDm                                     */
/* Purpose     : Read Focus Control Mode and update data manager item       */
/* Inputs      : Sio32 channel, Focus Control Mode dm item handles          */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initFocusControlModeDm( sio32Chan *cameraDataChan, 
                                                 DM_Item focusControlModeDm )
{
    Int16   focusControlMode;       /* Focus Control Mode                   */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_FOCUS_CONTROL_MODE ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update currents        */
    wordsFromBuf(reply, 2, &cmdStatus, &focusControlMode);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(focusControlModeDm, &focusControlMode, 
                                                 sizeof(focusControlMode)));
} /* initFocusControlModeDm() */

/****************************************************************************/
/* Function    : updateFocusControlModeDm                                   */
/* Purpose     : Reads Camera servo Control Mode & updates dmgr item        */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateFocusControlModeDm( sio32Chan *cameraDataChan, DM_Item controlModeDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */
    Int16  focusControlMode;            /* Camera Control Mode              */

                                        /* Read Camera Control Mode         */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_FOCUS_CONTROL_MODE ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, &focusControlMode );
     return(writeDmItem(controlModeDm, &focusControlMode, 
                           sizeof(focusControlMode)));
} /* updateFocusControlModeDm() */

/****************************************************************************/
/* Function    : initZoomControlModeDm                                      */
/* Purpose     : Read Zoom Control Mode and update data manager item        */
/* Inputs      : Sio32 channel, Zoom Control Mode dm item handles           */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initZoomControlModeDm( sio32Chan *cameraDataChan, 
                                                 DM_Item zoomControlModeDm )
{
    Int16   zoomControlMode;        /* Zoom Control Mode                    */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_ZOOM_CONTROL_MODE ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update currents        */
    wordsFromBuf(reply, 2, &cmdStatus, &zoomControlMode);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(zoomControlModeDm, &zoomControlMode, 
                                                 sizeof(zoomControlMode)));
} /* initZoomControlModeDm() */

/****************************************************************************/
/* Function    : updateZoomControlModeDm                                    */
/* Purpose     : Reads Camera servo Control Mode & updates dmgr item        */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateZoomControlModeDm( sio32Chan *cameraDataChan, DM_Item controlModeDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */ 
    Int16  zoomControlMode;             /* Camera Control Mode              */

                                        /* Read Camera Control Mode         */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_ZOOM_CONTROL_MODE ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, &zoomControlMode );
     return(writeDmItem(controlModeDm, &zoomControlMode, 
                           sizeof(zoomControlMode)));
} /* updateZoomControlModeDm() */

/****************************************************************************/
/* Function    : initPWMRateDm                                              */
/* Purpose     : Read PWM Rate and update data manager item                 */
/* Inputs      : Sio32 channel, PWM Rate dm item handles                    */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initPWMRateDm( sio32Chan *cameraDataChan, DM_Item PWMRateDm )
{
    Int16   PWMRate;                /* PWM Rate                             */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_PWM_RATE ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update currents        */
    wordsFromBuf(reply, 2, &cmdStatus, &PWMRate);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(PWMRateDm, &PWMRate, sizeof(PWMRate)));
} /* initPWMRateDm() */

/****************************************************************************/
/* Function    : updatePWMRateDm                                            */
/* Purpose     : Reads Camera PWM Rate & updates dmgr item                  */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updatePWMRateDm( sio32Chan *cameraDataChan, DM_Item PWMRateDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */ 
    Int16  PWMRate;                     /* Camera PWM Rate                  */

                                        /* Read Camera PWM Rate             */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_PWM_RATE ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
   if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, &PWMRate );
     return(writeDmItem(PWMRateDm, &PWMRate, 
                           sizeof(PWMRate)));
} /* updatePWMRateDm() */

/****************************************************************************/
/* Function    : initColorBarsModeDm                                        */
/* Purpose     : Read Color Bars Mode and update data manager item          */
/* Inputs      : Sio32 channel, Color Bar Mode dm item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initColorBarsModeDm( sio32Chan *cameraDataChan, DM_Item colorBarsModeDm )
{
    MBool  colorBarsMode;           /* Color Bars Mode                      */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_COLOR_BARS_MODE ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update currents        */
    wordsFromBuf(reply, 2, &cmdStatus, (Word *) &colorBarsMode);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(colorBarsModeDm, &colorBarsMode,                                                                        sizeof(colorBarsMode)));
} /* initColorBarsModeDm() */

/****************************************************************************/
/* Function    : updateColorBarsModeDm                                      */
/* Purpose     : Reads Camera Color Bars Mode & updates dmgr item           */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateColorBarsModeDm( sio32Chan *cameraDataChan, DM_Item controlModeDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */ 
    MBool  colorBarsMode;               /* Color Bars Mode                  */

                                        /* Read Color Bars Mode             */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_COLOR_BARS_MODE ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, (Word *) &colorBarsMode );
     return(writeDmItem(controlModeDm, &colorBarsMode, 
                           sizeof(colorBarsMode)));
} /* updateColorBarsModeDm() */


/****************************************************************************/
/* Function    : initMenuModeDm                                             */
/* Purpose     : Read Menu Mode and update data manager item                */
/* Inputs      : Sio32 channel, Menu Mode dm item handles                   */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initMenuModeDm( sio32Chan *cameraDataChan, DM_Item menuModeDm )
{
    MBool  menuMode;                /* Menu Mode                            */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_MENU_MODE ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update currents        */
    wordsFromBuf(reply, 2, &cmdStatus, (Word *) &menuMode);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(menuModeDm, &menuMode, sizeof(menuMode)));
} /* initMenuModeDm() */

/****************************************************************************/
/* Function    : updateMenuModeDm                                           */
/* Purpose     : Reads Camera Menu Mode & updates dmgr item                 */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateMenuModeDm( sio32Chan *cameraDataChan, DM_Item controlModeDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */ 
    MBool  menuMode;                    /* Menu Mode                        */

                                        /* Read Menu Mode                   */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_MENU_MODE ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, &menuMode );
     return(writeDmItem(controlModeDm, &menuMode, 
                           sizeof(menuMode)));
} /* updateMenuModeDm() */

/****************************************************************************/
/* Function    : initPageStateDm                                            */
/* Purpose     : Read Page state and update data manager item               */
/* Inputs      : Sio32 channel, Menu Mode dm item handles                   */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initPageStateDm( sio32Chan *cameraDataChan, DM_Item pageStateDm )
{
    MBool  pageState;               /* Page state                           */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_PAGE_STATE ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update State           */
    wordsFromBuf(reply, 2, &cmdStatus, (Word *) &pageState);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(pageStateDm, &pageState, sizeof(pageState)));
} /* initPageStateDm() */

/****************************************************************************/
/* Function    : updatePageStateDm                                          */
/* Purpose     : Reads Camera Page state & updates dmgr item                */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updatePageStateDm( sio32Chan *cameraDataChan, DM_Item controlModeDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */ 
    MBool  pageState;                   /* Page State                       */

                                        /* Read Page State                  */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_PAGE_STATE ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, &pageState );
     return(writeDmItem(controlModeDm, &pageState, 
                           sizeof(pageState)));
} /* updatePageStateDm() */

/****************************************************************************/
/* Function    : initItemStateDm                                            */
/* Purpose     : Read Item state and update data manager item               */
/* Inputs      : Sio32 channel, Menu Mode dm item handles                   */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initItemStateDm( sio32Chan *cameraDataChan, DM_Item itemStateDm )
{
    MBool  itemState;               /* Page state                           */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_ITEM_STATE ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update State           */
    wordsFromBuf(reply, 2, &cmdStatus, (Word *) &itemState);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(itemStateDm, &itemState, sizeof(itemState)));
} /* initItemStateDm() */

/****************************************************************************/
/* Function    : updateItemStateDm                                          */
/* Purpose     : Reads Camera Item state & updates dmgr item                */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateItemStateDm( sio32Chan *cameraDataChan, DM_Item controlModeDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */ 
    MBool  itemState;                   /* Item State                       */

                                        /* Read item State                  */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_ITEM_STATE ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, &itemState );
     return(writeDmItem(controlModeDm, &itemState, 
                           sizeof(itemState)));
} /* updateItemStateDm() */

/****************************************************************************/
/* Function    : initUpStateDm                                              */
/* Purpose     : Read up state and update data manager item                 */
/* Inputs      : Sio32 channel, Up Mode dm item handles                     */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initUpStateDm( sio32Chan *cameraDataChan, DM_Item upStateDm )
{
    MBool  upState;                 /* Up state                             */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_UP_STATE ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update State           */
    wordsFromBuf(reply, 2, &cmdStatus, (Word *) &upState);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(upStateDm, &upState, sizeof(upState)));
} /* initUpStateDm() */

/****************************************************************************/
/* Function    : updateUpStateDm                                            */
/* Purpose     : Reads Camera Up state & updates dmgr item                  */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateUpStateDm( sio32Chan *cameraDataChan, DM_Item controlModeDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */ 
    MBool  upState;                     /* Up State                         */

                                        /* Read item State                  */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_UP_STATE ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, &upState );
     return(writeDmItem(controlModeDm, &upState, 
                           sizeof(upState)));
} /* updateUpStateDm() */

/****************************************************************************/
/* Function    : initDownStateDm                                            */
/* Purpose     : Read down state and update data manager item               */
/* Inputs      : Sio32 channel, Up Mode dm item handles                     */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initDownStateDm( sio32Chan *cameraDataChan, DM_Item downStateDm )
{
    MBool  downState;               /* Down state                           */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_DOWN_STATE ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update State           */
    wordsFromBuf(reply, 2, &cmdStatus, (Word *) &downState);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(downStateDm, &downState, sizeof(downState)));
} /* initDownStateDm() */

/****************************************************************************/
/* Function    : updateDownStateDm                                          */
/* Purpose     : Reads Camera Down state & updates dmgr item                */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateDownStateDm( sio32Chan *cameraDataChan, DM_Item controlModeDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */ 
    MBool  downState;                   /* Down State                       */

                                        /* Read item State                  */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_DOWN_STATE ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, &downState );
     return(writeDmItem(controlModeDm, &downState, 
                           sizeof(downState)));
} /* updateDownStateDm() */

/****************************************************************************/
/* Function    : initIrisModeDm                                             */
/* Purpose     : Read Iris Mode and update data manager item                */
/* Inputs      : Sio32 channel, Iris Mode dm item handles                   */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initIrisModeDm( sio32Chan *cameraDataChan, DM_Item irisModeDm )
{
    MBool   irisMode;               /* Iris Mode                            */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_IRIS_MODE ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update currents        */
    wordsFromBuf(reply, 2, &cmdStatus, (Word *) &irisMode);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(irisModeDm, &irisMode, sizeof(irisMode)));
} /* initIrisModeDm() */

/****************************************************************************/
/* Function    : updateIrisModeDm                                           */
/* Purpose     : Reads Camera Iris Mode & updates dmgr item                 */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateIrisModeDm( sio32Chan *cameraDataChan, DM_Item controlModeDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */ 
    MBool  irisMode;                    /* Iris Mode                        */

                                        /* Read Iris  Mode                  */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_IRIS_MODE ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, &irisMode );
     return(writeDmItem(controlModeDm, &irisMode, 
                           sizeof(irisMode)));
} /* updateIrisModeDm() */

/****************************************************************************/
/* Function    : initIrisValueDm                                            */
/* Purpose     : Read Iris Value and update data manager item               */
/* Inputs      : Sio32 channel, Iris Value dm item handles                  */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initIrisValueDm( sio32Chan *cameraDataChan, DM_Item irisValueDm )
{
    Int16   irisValue;              /* Iris Value                           */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_IRIS_VALUE ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update currents        */
    wordsFromBuf(reply, 2, &cmdStatus, (Word *) &irisValue);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(irisValueDm, &irisValue, sizeof(irisValue)));
} /* initIrisValueDm() */

/****************************************************************************/
/* Function    : updateIrisValueDm                                          */
/* Purpose     : Reads Camera Iris Value & updates dmgr item                */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateIrisValueDm( sio32Chan *cameraDataChan, DM_Item irisValueDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */ 
    Int16  irisValue;                   /* Iris Value                       */

                                        /* Read Iris Value                  */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_IRIS_VALUE ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, (Word *) &irisValue );
     return(writeDmItem(irisValueDm, &irisValue, 
                           sizeof(irisValue)));

} /* updateIrisValueDm() */

/****************************************************************************/
/* Function    : initGainModeDm                                             */
/* Purpose     : Read Gain Mode and update data manager item                */
/* Inputs      : Sio32 channel, Gain Mode dm item handles                   */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initGainModeDm( sio32Chan *cameraDataChan, DM_Item gainModeDm )
{
    gainModeType gainMode;          /* Gain Mode                            */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_GAIN_MODE ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update currents        */
    wordsFromBuf(reply, 2, &cmdStatus, (Word *) &gainMode);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(gainModeDm, &gainMode, sizeof(gainMode)));
} /* initGainModeDm() */

/****************************************************************************/
/* Function    : updateGainModeDm                                           */
/* Purpose     : Reads Camera Gain Mode & updates dmgr item                 */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateGainModeDm( sio32Chan *cameraDataChan, DM_Item gainModeDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */ 
    gainModeType gainMode;              /* gain Mode                        */

                                        /* Read Gain  Mode                  */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_GAIN_MODE ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, (Word *) &gainMode );
     return(writeDmItem(gainModeDm, &gainMode, 
                           sizeof(gainMode)));
} /* updateGainModeDm() */

/****************************************************************************/
/* Function    : initGainValueDm                                            */
/* Purpose     : Read Gain Value and update data manager item               */
/* Inputs      : Sio32 channel, Gain Value dm item handles                  */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initGainValueDm( sio32Chan *cameraDataChan, DM_Item gainValueDm )
{
    gainValueType gainValue;        /* Gain Value                           */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_GAIN_VALUE ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update currents        */
    wordsFromBuf(reply, 2, &cmdStatus, (Word *) &gainValue);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(gainValueDm, &gainValue, sizeof(gainValue)));
} /* initGainValueDm() */

/****************************************************************************/
/* Function    : updateGainValueDm                                          */
/* Purpose     : Reads Camera Gain Value & updates dmgr item                */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateGainValueDm( sio32Chan *cameraDataChan, DM_Item gainValueDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */ 
    gainValueType gainValue;            /* Gain Value                       */

                                        /* Read Gain Value                  */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_GAIN_VALUE ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, (Word *) &gainValue );
     return(writeDmItem(gainValueDm, &gainValue, 
                           sizeof(gainValue)));
} /* updateGainValueDm() */

/****************************************************************************/
/* Function    : initDetailModeDm                                           */
/* Purpose     : Read Detail Mode and update data manager item              */
/* Inputs      : Sio32 channel, Detail Mode dm item handles                 */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initDetailModeDm( sio32Chan *cameraDataChan, DM_Item detailModeDm )
{
    detailModeType detailMode;      /* Detail Mode                          */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_DETAIL_MODE ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update currents        */
    wordsFromBuf(reply, 2, &cmdStatus, (Word *) &detailMode);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(detailModeDm, &detailMode, sizeof(detailMode)));
} /* initDetailModeDm() */

/****************************************************************************/
/* Function    : updateDetailModeDm                                         */
/* Purpose     : Reads Camera Detail Mode & updates dmgr item               */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateDetailModeDm( sio32Chan *cameraDataChan, DM_Item detailModeDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */ 
    detailModeType detailMode;          /* Detail Mode                    */

                                        /* Read Detail Mode                 */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_DETAIL_MODE ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, (Word *) &detailMode );
     return(writeDmItem(detailModeDm, &detailMode, 
                           sizeof(detailMode)));
} /* updateDetailModeDm() */

/****************************************************************************/
/* Function    : initShutterSpeedDm                                         */
/* Purpose     : Read Shutter Speed and update data manager item            */
/* Inputs      : Sio32 channel, Shutter Speed dm item handles               */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initShutterSpeedDm( sio32Chan *cameraDataChan, DM_Item shutterSpeedDm )
{
    shutterSpeedType shutterSpeed;  /* Shutter Speed                        */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_SHUTTER_SPEED ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update currents        */
    wordsFromBuf(reply, 2, &cmdStatus, (Word *) &shutterSpeed);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(shutterSpeedDm, &shutterSpeed, 
                                                     sizeof(shutterSpeed)));
} /* initShutterSpeedDm() */

/****************************************************************************/
/* Function    : updateShutterSpeedDm                                       */
/* Purpose     : Reads Shutter Speed & updates dmgr item                    */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateShutterSpeedDm( sio32Chan *cameraDataChan, DM_Item shutterSpeedDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */ 
    shutterSpeedType shutterSpeed;      /* Shutter Speed                    */

                                        /* Read Shutter Speed               */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_SHUTTER_SPEED ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, (Word *) &shutterSpeed );
     return(writeDmItem(shutterSpeedDm, &shutterSpeed, 
                           sizeof(shutterSpeed)));
} /* updateShutterSpeedDm() */

/****************************************************************************/
/* Function    : initSceneFileDm                                            */
/* Purpose     : Read Scene File and update data manager item               */
/* Inputs      : Sio32 channel, Scene File dm item handles                  */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initSceneFileDm( sio32Chan *cameraDataChan, DM_Item sceneFileDm )
{
    sceneFileType sceneFile;        /* Scene File                           */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_SCENE_FILE ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update currents        */
    wordsFromBuf(reply, 2, &cmdStatus, (Word *) &sceneFile);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(sceneFileDm, &sceneFile, sizeof(sceneFile)));
} /* initSceneFileDm() */

/****************************************************************************/
/* Function    : updateSceneFileDm                                          */
/* Purpose     : Reads Camera Scene File & updates dmgr item                */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateSceneFileDm( sio32Chan *cameraDataChan, DM_Item sceneFileDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */ 
    sceneFileType sceneFile;            /* Scene File                       */

                                        /* Read Scene Mode                  */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_SCENE_FILE ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, (Word *) &sceneFile );
     return(writeDmItem(sceneFileDm, &sceneFile, 
                           sizeof(sceneFile)));
} /* updateSceneFileDm() */


/****************************************************************************/
/* Function    : initWhiteBalModeDm                                         */
/* Purpose     : Read White Balance Mode and update data manager item       */
/* Inputs      : Sio32 channel, White Balance Mode dm item handles          */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initWhiteBalModeDm( sio32Chan *cameraDataChan, DM_Item whiteBalModeDm )
{
    whiteBalModeType whiteBalMode;  /* White Balance Mode                   */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_AWC_MODE ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update                 */
    wordsFromBuf(reply, 2, &cmdStatus, (Word *) &whiteBalMode);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(whiteBalModeDm, &whiteBalMode, 
                                                      sizeof(whiteBalMode)));
} /* initWhiteBalModeDm() */

/****************************************************************************/
/* Function    : updateWhiteBalModeDm                                       */
/* Purpose     : Reads Camera White Balance Mode & updates dmgr item        */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateWhiteBalModeDm( sio32Chan *cameraDataChan, DM_Item whiteBalModeDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */ 
    whiteBalModeType whiteBalMode;      /* White Balance Mode               */

                                        /* Read White Balance Mode          */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_AWC_MODE ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, (Word *) &whiteBalMode);
     return(writeDmItem(whiteBalModeDm, &whiteBalMode, 
                           sizeof(whiteBalMode)));
} /* updateWhiteBalModeDm() */


/****************************************************************************/
/* Function    : initAutoWhiteBalModeDm                                     */
/* Purpose     : Read Auto White Balance Mode and update data manager item  */
/* Inputs      : Sio32 channel, Auto White Balance Mode dm item handles     */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initAutoWhiteBalModeDm( sio32Chan *cameraDataChan, DM_Item autoWhiteBalModeDm )
{
    autoWhiteBalModeType autoWhiteBalMode; /* Auto White Balance Mode       */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_ATW_MODE ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update                 */
    wordsFromBuf(reply, 2, &cmdStatus, (Word *) &autoWhiteBalMode);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(autoWhiteBalModeDm, &autoWhiteBalMode, 
                                                  sizeof(autoWhiteBalMode)));
} /* initAutoWhiteBalModeDm() */

/****************************************************************************/
/* Function    : updateAutoWhiteBalModeDm                                   */
/* Purpose     : Reads Camera Auto White Balance Mode & updates dmgr item   */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateAutoWhiteBalModeDm(sio32Chan *cameraDataChan, DM_Item autoWhiteBalModeDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */ 
    autoWhiteBalModeType autoWhiteBalMode;  /* Auto White Balance Mode      */

                                        /* Read Auto White Balance Mode     */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_ATW_MODE ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, (Word *) &autoWhiteBalMode);
     return(writeDmItem(autoWhiteBalModeDm, &autoWhiteBalMode, 
                           sizeof(autoWhiteBalMode)));
} /* updateAutoWhiteBalModeDm() */

/****************************************************************************/
/* Function    : initTotalPedstalDm                                         */
/* Purpose     : Read Total Pedstal and update data manager item            */
/* Inputs      : Sio32 channel, Total Pedstal dm item handles               */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initTotalPedstalDm( sio32Chan *cameraDataChan, DM_Item totalPedstalDm )
{
    Int16   totalPedstal;           /* Total Pedstal                        */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_TOTAL_PEDSTAL ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update                 */
    wordsFromBuf(reply, 2, &cmdStatus, (Word *) &totalPedstal);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(totalPedstalDm, &totalPedstal, 
                                                  sizeof(totalPedstal)));
} /* initTotalPedstalDm() */


/****************************************************************************/
/* Function    : updateTotalPedstalDm                                       */
/* Purpose     : Reads Camera Total Pedstal & updates dmgr item             */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateTotalPedstalDm(sio32Chan *cameraDataChan, DM_Item totalPedstalDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */ 
    Int16  totalPedstal;                /* Total Pedstal                    */

                                        /* Read Total Pedstal               */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_TOTAL_PEDSTAL ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, (Word *) &totalPedstal);
     return(writeDmItem(totalPedstalDm, &totalPedstal, 
                           sizeof(totalPedstal)));
} /* updateTotalPedstalDm() */

/****************************************************************************/
/* Function    : initRedPedstalDm                                           */
/* Purpose     : Read Red Pedstal and update data manager item              */
/* Inputs      : Sio32 channel, Red Pedstal dm item handles                 */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initRedPedstalDm( sio32Chan *cameraDataChan, DM_Item redPedstalDm )
{
    Int16   redPedstal;             /* Red Pedstal                          */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_RED_PEDSTAL ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update                 */
    wordsFromBuf(reply, 2, &cmdStatus, (Word *) &redPedstal);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(redPedstalDm, &redPedstal, 
                                                  sizeof(redPedstal)));
} /* initRedPedstalDm() */


/****************************************************************************/
/* Function    : updateRedPedstalDm                                         */
/* Purpose     : Reads Camera Red Pedstal & updates dmgr item               */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateRedPedstalDm(sio32Chan *cameraDataChan, DM_Item redPedstalDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */ 
    Int16  redPedstal;                  /* Red Pedstal                      */

                                        /* Read Red Pedstal                 */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_RED_PEDSTAL ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, (Word *) &redPedstal);
     return(writeDmItem(redPedstalDm, &redPedstal, 
                           sizeof(redPedstal)));
} /* updateRedPedstalDm() */

/****************************************************************************/
/* Function    : initBluePedstalDm                                          */
/* Purpose     : Read Blue Pedstal and update data manager item             */
/* Inputs      : Sio32 channel, Blue Pedstal dm item handles                */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initBluePedstalDm( sio32Chan *cameraDataChan, DM_Item bluePedstalDm )
{
    Int16   bluePedstal;            /* Blue Pedstal                         */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_BLUE_PEDSTAL ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update                 */
    wordsFromBuf(reply, 2, &cmdStatus, (Word *) &bluePedstal);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(bluePedstalDm, &bluePedstal, 
                                                  sizeof(bluePedstal)));
} /* initBluePedstalDm() */


/****************************************************************************/
/* Function    : updateBluePedstalDm                                        */
/* Purpose     : Reads Camera Blue Pedstal & updates dmgr item              */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateBluePedstalDm(sio32Chan *cameraDataChan, DM_Item bluePedstalDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */ 
    Int16  bluePedstal;                 /* Blue Pedstal                     */

                                        /* Read Blue Pedstal                */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_BLUE_PEDSTAL ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, (Word *) &bluePedstal);
     return(writeDmItem(bluePedstalDm, &bluePedstal, 
                           sizeof(bluePedstal)));
} /* updateBluePedstalDm() */


/****************************************************************************/
/* Function    : initRedGainDm                                              */
/* Purpose     : Read Red Gain and update data manager item                 */
/* Inputs      : Sio32 channel, Red Gain dm item handles                    */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initRedGainDm( sio32Chan *cameraDataChan, DM_Item redGainDm )
{
    Int16   redGain;                /* Red Gain                             */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_RED_GAIN ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update                 */
    wordsFromBuf(reply, 2, &cmdStatus, (Word *) &redGain);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(redGainDm, &redGain, 
                                                  sizeof(redGain)));
} /* initRedGainDm() */


/****************************************************************************/
/* Function    : updateRedGainDm                                            */
/* Purpose     : Reads Camera Red Gain & updates dmgr item                  */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateRedGainDm(sio32Chan *cameraDataChan, DM_Item redGainDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */ 
    Int16  redGain;                     /* Red Gain                         */

                                        /* Read Red Gain                    */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_RED_GAIN ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, (Word *) &redGain);
     return(writeDmItem(redGainDm, &redGain, 
                           sizeof(redGain)));
} /* updateRedGainDm() */

/****************************************************************************/
/* Function    : initBlueGainDm                                             */
/* Purpose     : Read Blue Gain and update data manager item                */
/* Inputs      : Sio32 channel, Blue Gain dm item handles                   */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
initBlueGainDm( sio32Chan *cameraDataChan, DM_Item blueGainDm )
{
    Int16   blueGain;               /* Blue Gain                         */

    Int16   cmdStatus;		    /* Command Status                       */
    Word    reply[2];               /* Command Result from microcontroller  */
                                    /* Send command to microcontroller      */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
	 1, CAMERA_APP | GET_BLUE_GAIN ) == ERROR )
        return(ERROR);

                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK) 
	return(ERROR);		    /* Command failed so return ERROR       */

				    /* Command OK so update                 */
    wordsFromBuf(reply, 2, &cmdStatus, (Word *) &blueGain);

                                    /* We MUST use urgent open here as      */
                                    /* another task is normal provider      */

    return (urgentWriteDmItem(blueGainDm, &blueGain, 
                                                  sizeof(blueGain)));
} /* initBlueGainDm() */


/****************************************************************************/
/* Function    : updateBlueGainDm                                           */
/* Purpose     : Reads Camera Blue Gain & updates dmgr item                 */
/* Inputs      : Sio32 chan & Camera data manager item handles              */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
updateBlueGainDm(sio32Chan *cameraDataChan, DM_Item blueGainDm )
{
    Word   cmdStatus;                   /* Command Result from micro        */
    Word   reply[2];                    /* Reply to command                 */ 
    Int16  blueGain;                    /* Blue Gain                        */

                                        /* Read Blue Gain                   */
    if ( sendMicroCommand( cameraDataChan, &reply, sizeof(Word) * 2,
            1, CAMERA_APP | GET_BLUE_GAIN ) == ERROR )
        return(ERROR);
                                    /* Check if command result is CMD OK    */
    if (wordFromBuf(&reply, 0) != CMD_OK)
        return(ERROR);              /* Command failed so return ERROR       */

     wordsFromBuf(reply, 2, &cmdStatus, (Word *) &blueGain);
     return(writeDmItem(blueGainDm, &blueGain, 
                           sizeof(blueGain)));
} /* updateBlueGainDm() */

/****************************************************************************/
/* Function    : createCameraAppDmItems                                     */
/* Purpose     : Create Data Mgr Items specific to Camera Application       */
/* Inputs      : Pointer to structure of DM item handles, Camera DM         */
/*               prefix, Camera Microcontroller Name                        */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
createCameraAppDmItems( cameraDmItems *dmItems,
     const char* cameraAppPrefix, const char* cameraName )
{
    Int32   item;                   /* Counter for DM Item Initialization   */
    Errno   status;                 /* Result of dm_create function call    */
    Nat16   camera;                 /* Camera  index                        */

    struct                          /* Data Manager Item Table for table    */
    {                               /* driven item initialization           */
        DM_Item *dmItem;            /* pointer to actual dm item handle     */
        char    *errorMsg;          /* Message to display of dmCreate fails */
        char    *name;              /* Data Manager Item Name               */
        DM_Type type;               /* Data Manager Item Type               */
        DM_Num  len;                /* Data Manager Item Element Count      */
    } cameraDmInit[] =

      { { &dmItems->microDm.resetEvent,      "Reset Event",
                MICRO_RESET_EVENT_DM,           DM_EMPTY, 1 },

        { &dmItems->microDm.resetCmd,        "Reset Command",
                MICRO_RESET_CMD_DM,             DM_EMPTY, 1 },

        { &dmItems->microDm.idString,        "Identification",
                MICRO_IDENT_DM,                 DM_CHAR, MICRO_ID_LEN  },

        { &dmItems->microDm.serialNo,        "Micro Serial Number",
                MICRO_SERIAL_NO_DM,             DM_CHAR, MICRO_SERNO_LEN },

        { &dmItems->microDm.softwareRev,     "Software Revision",
                SOFTWARE_REV_DM,                DM_CHAR, SOFTWARE_REV_LEN },

        { &dmItems->microDm.ramTest,         "Micro RAM Test",
                RAM_TEST_STATUS_DM,             DM_MBOOL, 1 },

	{ &dmItems->microTemperature,        "Micro Temperature",
		TEMPERATURE_DM, 		DM_INT16, 1 },

     	{ &dmItems->temperatureAlarm,  	     "Temperature Alarm",
		TEMPERATURE_ALARM_DM, 	    	DM_ENUM,  1 },

     	{ &dmItems->tempWarnThresh,  	     "Temperature Warn Threshold",
		TEMP_WARN_THRESH_DM, 	    	DM_INT16, 1 },

     	{ &dmItems->tempAlarmThresh,  	     "Temperature Alarm Threshold",
		TEMP_ALARM_THRESH_DM, 	    	DM_INT16, 1 },

        { &dmItems->microHumidity,           "Humidity Value",
                HUMIDITY_DM,                    DM_NAT16, 1 },

        { &dmItems->humidityAlarm,           "Humidity Alarm",
                HUMIDITY_ALARM_DM,              DM_ENUM, 1 },

        { &dmItems->humidityWarnThresh,      "Humidity Warn Threshold",
                HUMIDITY_WARN_THRESH_DM,        DM_NAT16, 1 },

        { &dmItems->humidityAlarmThresh,     "Humidity Alarm Threshold",
                HUMIDITY_ALARM_THRESH_DM,       DM_NAT16, 1 },

        { &dmItems->canWaterAlarm,           "Housing Water Alarm",
                HOUSING_WATER_ALARM_DM,         DM_MBOOL, 1 },
	
	
	{ NO_ITEM, NULL, NULL, DM_ENDT, 0 } };

                                  /* Initialize Camera Data Manager Items*/
    for (item = 0; cameraDmInit[item].dmItem != NO_ITEM; item++)
    {
        if ((*cameraDmInit[item].dmItem =
             initMicroDmItem(cameraAppPrefix, cameraDmInit[item].name,
             cameraDmInit[item].type, cameraDmInit[item].len)) == ERROR)
        {                         /* Error occurred so print message & exit*/
            logMsg("%s: Error Initializing %s DM Item\n",
                cameraName, cameraDmInit[item].errorMsg);
            return(ERROR);
        } /* if */
    } /* for */
#if 0
 if ((dmItems->joystickItems.stbdTiltAxis = initMicroDmItem("", 
         STBD_TILT_JOYSTICK_DM, DM_INT16, 1)) == ERROR)
    {
                           /* Error occurred so print message & exit*/
	logMsg("%s: Error Initializing %s DM Item\n", cameraName, "Joystick");
	return(ERROR);
    } 
/* if */

 if ((dmItems->joystickItems.portTiltAxis = initMicroDmItem("", 
         PORT_TILT_JOYSTICK_DM, DM_INT16, 1)) == ERROR)
    {
                           /* Error occurred so print message & exit*/
	logMsg("%s: Error Initializing %s DM Item\n", cameraName, "Joystick");
	return(ERROR);
    } 
/* if */

#endif

    createCameraDmItems(camera, &dmItems->camItems,
            cameraAppPrefix, cameraAppPrefix );

    return(OK);
} /* createCameraAppDmItems() */

/****************************************************************************/
/* Function    : createCameraDmItems                                        */
/* Purpose     : Create Data Mgr Items for a Camera                         */
/* Inputs      : Pointer to structure of DM item handles, CAMERA     DM     */
/*               prefix, Camera Microcontroller Name                    */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    LOCAL STATUS
createCameraDmItems( Nat16 camera, cameraItems *dmItems,
    const char* cameraAppPrefix, const char* cameraName )
{
    Int32   item;                   /* Counter for DM Item Initialization   */
    Errno   status;                 /* Result of dm_create function call    */

    struct                          /* Data Manager Item Table for table    */
    {                               /* driven item initialization           */
        DM_Item *dmItem;            /* pointer to actual dm item handle     */
        char    *errorMsg;          /* Message to display of dmCreate fails */
        char    *name;              /* Data Manager Item Name               */
        DM_Type type;               /* Data Manager Item Type               */
        DM_Num  len;                /* Data Manager Item Element Count      */
    } cameraDmInit[] =

/* change source of set point provider to iview task */
#ifdef MBM_CAMERA_MODS
      { { &dmItems->focusSetPoint,	     "Integrated Focus Set Point",
	        INTEGRATED_FOCUS_SET_POINT_DM,	DM_INT16, 1 },
#else
      { { &dmItems->focusSetPoint,	     "Focus Set Point",
	        FOCUS_SET_POINT_DM,		DM_INT16, 1 },
#endif

	{ &dmItems->focusVelocityGain,       "Focus Velocity Gain",
                FOCUS_VELOCITY_GAIN_DM,		DM_INT16, 1 },

	{ &dmItems->focusPosition,	     "Focus Position",
	        FOCUS_POSITION_DM,		DM_INT16, 1 },

        { &dmItems->focusControlMode,	     "Focus Control Mode",
                FOCUS_CONTROL_MODE_DM,	   	DM_INT16, 1 },
	
	
        { &dmItems->zoomSetPoint,	     "Zoom Set Point",
	        ZOOM_SET_POINT_DM,		DM_INT16, 1 },

	{ &dmItems->zoomVelocityGain,        "Zoom Velocity Gain",
                ZOOM_VELOCITY_GAIN_DM,		DM_INT16, 1 },

	{ &dmItems->zoomPosition,	     "Zoom Position",
	        ZOOM_POSITION_DM,		DM_INT16, 1 },

        { &dmItems->zoomControlMode,	     "Zoom Control Mode",
                ZOOM_CONTROL_MODE_DM,	   	DM_INT16, 1 },

        { &dmItems->zoomRate,	             "Zoom Rate",
                ZOOM_RATE_DM,	   	        DM_INT16, 1 },

        { &dmItems->PWMRate,                 "PWM Rate",
                PWM_RATE_DM,		   	DM_INT16, 1 },
	
        { &dmItems->colorBarsMode,           "Color Bars Mode",
                COLOR_BARS_MODE_DM,             DM_MBOOL, 1 },
        
        { &dmItems->menuMode,                "Menu Mode",
                MENU_MODE_DM,             	DM_MBOOL, 1 },

        { &dmItems->pageState,               "Page State",
                PAGE_STATE_DM,             	DM_MBOOL, 1 },

        { &dmItems->itemState,               "Item State",
                ITEM_STATE_DM,             	DM_MBOOL, 1 },

        { &dmItems->upState,                 "Up State",
                UP_STATE_DM,             	DM_MBOOL, 1 },

        { &dmItems->downState,               "Down State",
                DOWN_STATE_DM,             	DM_MBOOL, 1 },

        { &dmItems->irisMode,                "Iris Mode",
                IRIS_MODE_DM,             	DM_MBOOL, 1 },

        { &dmItems->irisValue,                "Iris Value",
                IRIS_VALUE_DM,                   DM_INT16, 1 },

        { &dmItems->gainMode,                "Gain Mode",
                GAIN_MODE_DM,             	 DM_ENUM, 1 },

        { &dmItems->gainValue,               "Gain Value",
                GAIN_VALUE_DM,                   DM_ENUM, 1 },

        { &dmItems->detailMode,               "Detail Mode",
                DETAIL_MODE_DM,             	 DM_ENUM, 1 },

        { &dmItems->shutterSpeed,             "Shutter Speed",
                SHUTTER_SPEED_DM,             	 DM_ENUM, 1 },

        { &dmItems->sceneFile,                "Scene File",
                SCENE_FILE_DM,             	 DM_ENUM, 1 },

        { &dmItems->whiteBalMode,             "White Balance Mode",
                AWC_MODE_DM,             	 DM_ENUM, 1 },

        { &dmItems->autoWhiteBalMode,         "Auto White Balance Mode",
                ATW_MODE_DM,             	 DM_ENUM, 1 },

        { &dmItems->totalPedstal,             "Total Pedstal",
                TOTAL_PEDSTAL_DM,             	 DM_INT16, 1 },

        { &dmItems->redPedstal,               "Red Pedstal",
                RED_PEDSTAL_DM,             	 DM_INT16, 1 },

        { &dmItems->bluePedstal,              "Blue Pedstal",
                BLUE_PEDSTAL_DM,             	 DM_INT16, 1 },

        { &dmItems->redGain,                  "Red Gain",
                RED_GAIN_DM,             	 DM_INT16, 1 },

        { &dmItems->blueGain,                 "Blue Gain",
                BLUE_GAIN_DM,             	 DM_INT16, 1 },

 	{ NO_ITEM, NULL, NULL, DM_ENDT, 0 } };

   /* char *camJoystickDmNames[] =
        { PORT_CAM_JOYSTICK_DM, STBD_CAM_JOYSTICK_DM };*/
  
                                 /* Initialize Camera Data Manager Items*/
    for (item = 0; cameraDmInit[item].dmItem != NO_ITEM; item++)
    {
        if ((*cameraDmInit[item].dmItem =
             initMicroDmItem(cameraAppPrefix, cameraDmInit[item].name,
             cameraDmInit[item].type, cameraDmInit[item].len)) == ERROR)
        {                         /* Error occurred so print message & exit  */
            logMsg("%s: Error Initializing %s DM Item\n",
                cameraName, cameraDmInit[item].errorMsg);
            return(ERROR);
        } /* if */
    } /* for */

 /*   if ((dmItems->joystickCmd = initMicroDmItem("", 
         camJoystickDmNames[camera], DM_INT16, 1)) == ERROR)*/
 /*   {*/
                           /* Error occurred so print message & exit*/
/*	logMsg("%s: Error Initializing %s DM Item\n", cameraName, "Joystick");*/
/*	return(ERROR);*/
/*    }*/ 
/* if */

    return(OK);
} /* createCameraDmItems() */
/****************************************************************************/
/* Function    : cameraDmItemInit                                           */
/* Purpose     : Read parameters from camera microcontroller and update DMgr*/
/* Inputs      : Pointer to DM item handles, camera micro serial channel    */
/* Outputs     : None, but data manager items change                        */
/****************************************************************************/
    LOCAL STATUS
cameraDmItemInit(cameraDmItems* dmItems, sio32Chan* cameraDataChan)
{
    Int16 trys;
    Nat16 camera;             
                                 /* Send Command Enable Command to IBC Micro*/
    for (trys = 0; ((microCmdEnable(cameraDataChan) == ERROR) &&
         trys < CAMERA_ENABLE_TRYS); trys++)
         taskDelay(sysClkRateGet() / 5);

    if (trys == CAMERA_ENABLE_TRYS)
    {	
        logMsg("Camera: Error Enabling Camera Microcontroller\n");
        return(ERROR);
    }/* if */

                                /* Set Micro Identification initial value   */
    if (updateMicroIdentDm(cameraDataChan, dmItems->microDm.idString)
        == ERROR)
        logMsg("Camera: Error reading Identification String\n");

                                /* Set Micro Serial Number initial value    */
    if (updateSerialNoDm(cameraDataChan, dmItems->microDm.serialNo) == ERROR)
        logMsg("Camera: Error reading Micro Serial Number\n");

                                /* Set Software Revision initial value      */
    if (updateSoftwareRevDm(cameraDataChan, dmItems->microDm.softwareRev)
        == ERROR)
        logMsg("Camera: Error reading Software Revision\n");

                                /* Set Micro Ram Test Result value          */
    if (updateMicroRamTestDm(cameraDataChan, dmItems->microDm.ramTest)
        == ERROR)
        logMsg("Camera: Error checking micro RAM Test\n");

    if (setTempThresh(cameraDataChan, CAMERA_TEMP_WARN_THRESH,
        CAMERA_TEMP_ALARM_THRESH ) == ERROR) 
        logMsg("Camara: Error setting Temperature alarm thresholds\n");

                                /* Set Micro Temperature Alarm initial value*/
    if (updateTempAlarmDm(cameraDataChan, dmItems->temperatureAlarm) == ERROR)
        logMsg("Camera: Error checking temperature alarm status\n");

    if (setHumidityThresh(cameraDataChan, CAMERA_HUMIDITY_WARN_THRESH,
        CAMERA_HUMIDITY_ALARM_THRESH ) == ERROR) 
        logMsg("Camara: Error setting humidity alarm thresholds\n");

                                /* Set Humidity Alarm initial value         */
    if (updateHumidityAlarmDm(cameraDataChan, dmItems->humidityAlarm)
         == ERROR)
        logMsg("Camera: Error checking humidity alarm status\n");

                                /* Set Micro Water Alarm initial value      */
    if (updateWaterAlarmDm(cameraDataChan, dmItems->canWaterAlarm) == ERROR)
        logMsg("Camera: Error checking water alarm status\n");

    return(OK);
} /* cameraDmItemInit() */

/****************************************************************************/
/* Function    : stbdCameraTask                                             */
/* Purpose     : Initializes communication with Camera Microcontroller      */
/*               Provides interface between Camera and Data Manager         */
/* Inputs      : SIO32 serial channel number for Camera  Microcontrller     */
/*               Physically maps the Camera to a serial channel             */
/* Outputs     : Normally runs forever, but returns ERROR on fatal error    */
/****************************************************************************/
    STATUS
stbdCameraTask( Nat16 cameraSerialChan )
{
    microIOControl microIOCtrl;   /* Microcontroller IO Task control        */
    cameraDmItems camDmItems;     /* Camera Application Data Mgr items      */ 
    
                                  /* Initialize serial channel and task     */
                                  /* synchronization resources              */
    if (initMicroTaskIO( &microIOCtrl, NUM_TASKS, cameraSerialChan,
        cameraAppPrefix, "/sio32/stbdCamera", 
        STBD_COLOR_CAMERA_SWITCH_STATUS_DM) == ERROR)
    {
	logMsg("Error initializing IO for Stbd camera\n");
	return(ERROR);
    } /* if */
                                   /* Clear Camera Data Manager handles     */
    bzero(&camDmItems, sizeof(camDmItems));

                                   /* Create Camera Application Items   */
    if (createCameraAppDmItems( &camDmItems, cameraAppPrefix, 
              cameraMicroName) == ERROR)
    {                              /* Error occurred so print message & exit */
        sio32ChanDestroy( cameraSerialChan, &microIOCtrl.sio32DataChan );
        return(ERROR);
    } /* if */

                                   /* Start Provider for Static Data & Alarms*/
    dm_start_provider(camDmItems.microDm.resetEvent,  DM_STATIC);
    dm_start_provider(camDmItems.microDm.idString,    DM_STATIC);
    dm_start_provider(camDmItems.microDm.serialNo,    DM_STATIC);
    dm_start_provider(camDmItems.microDm.softwareRev, DM_STATIC);
    dm_start_provider(camDmItems.microDm.ramTest,     DM_STATIC);

    dm_start_provider(camDmItems.canWaterAlarm,       DM_STATIC);
    dm_start_provider(camDmItems.humidityAlarm,       DM_STATIC);
    dm_start_provider(camDmItems.temperatureAlarm,    DM_STATIC);
  
    if ((microIOCtrl.childTasks[OUT_TASK].taskId =
	 taskSpawn( "stbdCameraOut", CAMERA_OUT_PRIORITY, 0,
         CAMERA_OUT_STACKSIZE, (FUNCPTR) stbdCameraOutTask, (int) &camDmItems,
         (int) &microIOCtrl, 0, 0, 0, 0, 0, 0, 0, 0)) == ERROR) 
    {
        sio32ChanDestroy( cameraSerialChan, &microIOCtrl.sio32DataChan );
        logMsg("Camera: Error spawning stbd data output task\n");
        return(ERROR);
    } /* if */   

    if ((microIOCtrl.childTasks[IN_TASK].taskId =
	 taskSpawn( "stbdCameraIn", CAMERA_IN_PRIORITY, 0,
         CAMERA_IN_STACKSIZE, (FUNCPTR) stbdCameraInTask, (int) &camDmItems,
          (int) &microIOCtrl, 0, 0, 0, 0, 0, 0, 0, 0))
           == ERROR) 
    {
	taskDelete(microIOCtrl.childTasks[OUT_TASK].taskId);
        sio32ChanDestroy( cameraSerialChan, &microIOCtrl.sio32DataChan );
        logMsg("Camera: Error spawning stbd data input task\n");
        return(ERROR);
    } /* if */

    FOREVER
    {                              /* Check if Camera is switched on        */
	if ((microDevPowerSwitchState(&microIOCtrl) != SWITCH_ON) ||
           ((microDevPowerSwitchState(&microIOCtrl) == SWITCH_ON) &&
	    (microIOCtrl.resetEventCount != 0)))

           while(processCameraSRQ(&camDmItems, &microIOCtrl) 
                 != MICRO_RESET_SRQ);
 	   
	microIOCtrl.resetEventCount++;/* Count reset events from micro      */

                                    /* Reset event received from Micro so   */
        	                    /* Mark serial coms link as up          */
	setSerialLinkState(&microIOCtrl, LINK_UP);
                                    /* Initialize Camera DM Item values     */
        if( cameraDmItemInit( &camDmItems, &microIOCtrl.sio32DataChan ) == OK)
                                  /* Wake up output task to configure micro*/
	    semGive(microIOCtrl.childTasks[OUT_TASK].taskSyncSem);
	else
	    setSerialLinkState(&microIOCtrl, LINK_DOWN);
            
    } /* FOREVER */
                                     /* Delete Child Tasks                   */
    taskDelete(microIOCtrl.childTasks[IN_TASK].taskId);
    taskDelete(microIOCtrl.childTasks[OUT_TASK].taskId);
                                     /* Close serial communication channel   */
    sio32ChanDestroy( cameraSerialChan, &microIOCtrl.sio32DataChan );

                        /* dm_stop_provider, dm_stop_consumer, etc are NOT   */
                        /* required when the task exits as the Data Manager  */
                        /* does this automatically when the task is deleted  */
                        /* via taskDeleteHookAdd() and dm_task_exit functions*/

    return(OK);         /* That's all folks                                  */
} /* stbdCameraTask() */

/*****************************************************************************/
/* Function    : stbdCameraOutTask                                           */
/* Purpose     : Camera Out Task. Read DM items & write to Camera            */
/* Inputs      : Array of Data Manager Item handles & serial chan structure  */
/* Outputs     : Normally runs forever, but exits if error occurs            */
/*****************************************************************************/
     Void
stbdCameraOutTask(Reg cameraDmItems *dmItems, microIOControl *microIOCtrl )
{
    DM_Group dmGroup;               /* Camera Data Manager Group             */
    SEM_ID   dmUpdateSem;           /* Data Manager wakes up task when an    */

    DWord   changedBits;            /* Holds dm_group_changes bit vector     */
    DWord   cameraBits;             /* Holds camera changes bit vector       */
    DWord   cameraSwitchBit;        /* Camera Power Switch Bit               */
    DWord   resetEventBit;          /* Microcontroller reset event  bit      */
    DWord   resetCmdBit;            /* Microcontroller reset item changed bit*/
    DWord   humidityWarnBit;        /* Humidity Warning item changed bit     */
    DWord   humidityAlarmBit;       /* Humidity Alarm item changed bit       */
    DWord   tempWarnBit;            /* Temperature Warning item changed bit  */
    DWord   tempAlarmBit;           /* Temperature Alarm item changed bit    */
    
    DM_Group camGroup;              /* Camera specific DM Group              */
                                    
    struct
    {
	DWord focusSetPointBit;
        DWord zoomSetPointBit;
        DWord zoomRateBit;
        DWord PWMRateBit;
        DWord focusVelocityGainBit;
        DWord zoomVelocityGainBit;
        DWord focusControlModeBit;
        DWord zoomControlModeBit;
        DWord colorBarsModeBit;
        DWord menuModeBit;
        DWord pageStateBit;
        DWord itemStateBit;
        DWord upStateBit;
        DWord downStateBit;
        DWord irisModeBit;
        DWord irisValueBit;     
        DWord gainModeBit;
        DWord gainValueBit;
        DWord detailModeBit;     
        DWord shutterSpeedBit;
        DWord sceneFileBit;
        DWord whiteBalModeBit;
        DWord autoWhiteBalModeBit;
        DWord totalPedstalBit;
        DWord redPedstalBit;  
        DWord bluePedstalBit;
        DWord redGainBit;  
        DWord blueGainBit;
        
      /*DWord joystickCmdBit;*/
    } camGroupBits;

                                    /* Create switch & power sync semaphores */
    if ((dmUpdateSem = semBCreate(SEM_Q_FIFO, SEM_EMPTY)) == NULL)
    {
        logMsg("Camera: Error initializing Stbd Output Task Resources\n");
        return;
    } /* if */
                                    /* This task consumes camera power switch*/
    dm_start_consumer(microIOCtrl->powerSwitchDm,     DM_STATIC, dmUpdateSem);

                                    /* Declare this task a consumer of items */
                                    /* which are written to the camera       */
    dm_start_consumer(dmItems->microDm.resetEvent,     DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->microDm.resetCmd,       DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->humidityWarnThresh,     DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->humidityAlarmThresh,    DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->tempWarnThresh,         DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->tempAlarmThresh,        DM_STATIC, dmUpdateSem);
    
    dmGroup = dm_create_group();    /* Create Data Manager Group for items   */

    dm_group_add_item(dmGroup, microIOCtrl->powerSwitchDm,   &cameraSwitchBit);
    dm_group_add_item(dmGroup, dmItems->microDm.resetEvent,  &resetEventBit);
    dm_group_add_item(dmGroup, dmItems->microDm.resetCmd,    &resetCmdBit);

    dm_group_add_item(dmGroup, dmItems->humidityWarnThresh,  &humidityWarnBit);
    dm_group_add_item(dmGroup, dmItems->humidityAlarmThresh, &humidityAlarmBit);
    dm_group_add_item(dmGroup, dmItems->tempWarnThresh,      &tempWarnBit);
    dm_group_add_item(dmGroup, dmItems->tempAlarmThresh,     &tempAlarmBit);
    
    dm_start_consumer(dmItems->camItems.focusSetPoint, DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->camItems.zoomSetPoint,  DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->camItems.zoomRate,      DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->camItems.PWMRate,       DM_STATIC, dmUpdateSem);
    
    dm_start_consumer(dmItems->camItems.focusVelocityGain,
                                                       DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->camItems.zoomVelocityGain,
                                                       DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->camItems.focusControlMode,
                                                       DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->camItems.zoomControlMode,
                                                       DM_STATIC, dmUpdateSem);
    
    dm_start_consumer(dmItems->camItems.colorBarsMode, DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->camItems.menuMode,      DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->camItems.pageState,     DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->camItems.itemState,     DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->camItems.upState,       DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->camItems.downState,     DM_STATIC, dmUpdateSem);

    dm_start_consumer(dmItems->camItems.irisMode,      DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->camItems.irisValue,     DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->camItems.gainMode,      DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->camItems.gainValue,     DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->camItems.detailMode,    DM_STATIC, dmUpdateSem);

    dm_start_consumer(dmItems->camItems.shutterSpeed,  DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->camItems.sceneFile,     DM_STATIC, dmUpdateSem);

    dm_start_consumer(dmItems->camItems.whiteBalMode,  DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->camItems.autoWhiteBalMode,
                                                       DM_STATIC, dmUpdateSem);

    dm_start_consumer(dmItems->camItems.totalPedstal,  DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->camItems.redPedstal,    DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->camItems.bluePedstal,   DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->camItems.redGain,       DM_STATIC, dmUpdateSem);
    dm_start_consumer(dmItems->camItems.blueGain,      DM_STATIC, dmUpdateSem);
#if 0    
    dm_connect(dmItems->joystickItems.stbdTiltAxis, dmItems->camItems.focusSetPoint);
    dm_connect(dmItems->joystickItems.portTiltAxis, dmItems->camItems.zoomSetPoint);
#endif

    camGroup = dm_create_group();

    dm_group_add_item(camGroup, dmItems->camItems.focusSetPoint,
                      &camGroupBits.focusSetPointBit);
    dm_group_add_item(camGroup, dmItems->camItems.zoomSetPoint,
                      &camGroupBits.zoomSetPointBit);

    dm_group_add_item(camGroup, dmItems->camItems.zoomRate,
                      &camGroupBits.zoomRateBit);

    dm_group_add_item(camGroup, dmItems->camItems.PWMRate,
                      &camGroupBits.PWMRateBit);
    
    dm_group_add_item(camGroup, dmItems->camItems.focusVelocityGain,
                      &camGroupBits.focusVelocityGainBit);
    dm_group_add_item(camGroup, dmItems->camItems.zoomVelocityGain,
                      &camGroupBits.zoomVelocityGainBit);

    dm_group_add_item(camGroup, dmItems->camItems.focusControlMode,
                      &camGroupBits.focusControlModeBit);
    dm_group_add_item(camGroup, dmItems->camItems.zoomControlMode,
                      &camGroupBits.zoomControlModeBit);
   
    dm_group_add_item(camGroup, dmItems->camItems.colorBarsMode,
                      &camGroupBits.colorBarsModeBit);
 
    dm_group_add_item(camGroup, dmItems->camItems.menuMode,
                      &camGroupBits.menuModeBit);

    dm_group_add_item(camGroup, dmItems->camItems.pageState,
                      &camGroupBits.pageStateBit);

    dm_group_add_item(camGroup, dmItems->camItems.itemState,
                      &camGroupBits.itemStateBit);

    dm_group_add_item(camGroup, dmItems->camItems.upState,
                      &camGroupBits.upStateBit);

    dm_group_add_item(camGroup, dmItems->camItems.downState,
                      &camGroupBits.downStateBit);

    dm_group_add_item(camGroup, dmItems->camItems.irisMode,
                      &camGroupBits.irisModeBit);

    dm_group_add_item(camGroup, dmItems->camItems.irisValue,
                      &camGroupBits.irisValueBit);

    dm_group_add_item(camGroup, dmItems->camItems.gainMode,
                      &camGroupBits.gainModeBit);

    dm_group_add_item(camGroup, dmItems->camItems.gainValue,
                      &camGroupBits.gainValueBit);

    dm_group_add_item(camGroup, dmItems->camItems.detailMode,
                      &camGroupBits.detailModeBit);

    dm_group_add_item(camGroup, dmItems->camItems.shutterSpeed,
                      &camGroupBits.shutterSpeedBit);

    dm_group_add_item(camGroup, dmItems->camItems.sceneFile,
                      &camGroupBits.sceneFileBit);

    dm_group_add_item(camGroup, dmItems->camItems.whiteBalMode,
                      &camGroupBits.whiteBalModeBit);

    dm_group_add_item(camGroup, dmItems->camItems.autoWhiteBalMode,
                      &camGroupBits.autoWhiteBalModeBit);

    dm_group_add_item(camGroup, dmItems->camItems.totalPedstal,
                      &camGroupBits.totalPedstalBit);

    dm_group_add_item(camGroup, dmItems->camItems.redPedstal,
                      &camGroupBits.redPedstalBit);

    dm_group_add_item(camGroup, dmItems->camItems.bluePedstal,
                      &camGroupBits.bluePedstalBit);

    dm_group_add_item(camGroup, dmItems->camItems.redGain,
                      &camGroupBits.redGainBit);

    dm_group_add_item(camGroup, dmItems->camItems.blueGain,
                      &camGroupBits.blueGainBit);
     

    FOREVER
    {                              /* Mark micro configuration as invalid    */
	microIOCtrl->microConfigured = FALSE;

                                   /* Wait for micro reset via SRQ Task      */
 	semTake(microIOCtrl->childTasks[OUT_TASK].taskSyncSem, WAIT_FOREVER);

        /* We need to initialize default state of Data manager Items here    */

        initHumidityThreshDm(SERIAL_CHAN, dmItems->humidityWarnThresh,
                             dmItems->humidityAlarmThresh);

        initTemperatureThreshDm(SERIAL_CHAN, dmItems->tempWarnThresh,
                             dmItems->tempAlarmThresh);
         
        initFocusSetPointDm(SERIAL_CHAN, dmItems->camItems.focusSetPoint);

        initZoomSetPointDm(SERIAL_CHAN, dmItems->camItems.zoomSetPoint);

        initZoomRateDm(SERIAL_CHAN, dmItems->camItems.zoomRate);
                
        initPWMRateDm(SERIAL_CHAN, dmItems->camItems.PWMRate);
        
        initFocusVelocityGainDm(SERIAL_CHAN, 
                                        dmItems->camItems.focusVelocityGain);
        
        initZoomVelocityGainDm(SERIAL_CHAN, 
                                        dmItems->camItems.zoomVelocityGain);

        initFocusControlModeDm(SERIAL_CHAN, 
                                        dmItems->camItems.focusControlMode);
        
        initZoomControlModeDm(SERIAL_CHAN, 
                                        dmItems->camItems.zoomControlMode);

        initColorBarsModeDm(SERIAL_CHAN, dmItems->camItems.colorBarsMode);

        initMenuModeDm(SERIAL_CHAN, dmItems->camItems.menuMode);

        initPageStateDm(SERIAL_CHAN, dmItems->camItems.pageState);

        initItemStateDm(SERIAL_CHAN, dmItems->camItems.itemState);

        initUpStateDm(SERIAL_CHAN, dmItems->camItems.upState);

        initDownStateDm(SERIAL_CHAN, dmItems->camItems.downState);

        initIrisModeDm(SERIAL_CHAN, dmItems->camItems.irisMode);

        initIrisValueDm(SERIAL_CHAN, dmItems->camItems.irisValue);

        initGainModeDm(SERIAL_CHAN, dmItems->camItems.gainMode);

        initGainValueDm(SERIAL_CHAN, dmItems->camItems.gainValue);

        initDetailModeDm(SERIAL_CHAN, dmItems->camItems.detailMode);

        initShutterSpeedDm(SERIAL_CHAN, dmItems->camItems.shutterSpeed);

        initSceneFileDm(SERIAL_CHAN, dmItems->camItems.sceneFile);

        initWhiteBalModeDm(SERIAL_CHAN, dmItems->camItems.whiteBalMode);

        initAutoWhiteBalModeDm(SERIAL_CHAN,
                                          dmItems->camItems.autoWhiteBalMode);

        initTotalPedstalDm(SERIAL_CHAN, dmItems->camItems.totalPedstal);

        initRedPedstalDm(SERIAL_CHAN, dmItems->camItems.redPedstal);            
        initBluePedstalDm(SERIAL_CHAN, dmItems->camItems.bluePedstal);

        initRedGainDm(SERIAL_CHAN, dmItems->camItems.redGain); 
           
        initBlueGainDm(SERIAL_CHAN, dmItems->camItems.blueGain);

                             /* Clear item changed bits after reset   */
        changedBits = dm_get_group_changes(dmGroup);
        
	cameraBits = dm_get_group_changes(camGroup);

	microIOCtrl->microConfigured = TRUE;
                                   /* Wake up input task to read from micro  */
	semGive(microIOCtrl->childTasks[IN_TASK].taskSyncSem);

        while (microIOCtrl->serialLinkState == LINK_UP)
        {                           /* Wait for any data items to change     */
            semTake(dmUpdateSem, WAIT_FOREVER);

                                    /* Ask Data Manager which items changed  */
            changedBits = dm_get_group_changes(dmGroup);
	    cameraBits = dm_get_group_changes(camGroup);
                                    /* Check if micro Reset Event occurred   */
            if (changedBits & resetEventBit)
                break;              /* Exit loop and re-initialize DM items  */

				    /* Check if pan/tilt power was switch off*/
	    if ( (changedBits & cameraSwitchBit) && 
	 	 (microDevPowerSwitchState(microIOCtrl) != SWITCH_ON) )
	    {
		                    /* Camera switched off so link is down   */
		setSerialLinkState(microIOCtrl, LINK_DOWN);
	        break;		    /* Exit loop and wait for power up       */
	    } /* if */

            taskSafe();             /* Prevent task from being deleted during*/
                                    /* serial IO and Data Manager updates    */

            if ( (changedBits & humidityWarnBit) ||
                 (changedBits & humidityAlarmBit) )
                writeHumidityThresh(SERIAL_CHAN,
                    dmItems->humidityWarnThresh, dmItems->humidityAlarmThresh);

            if ( (changedBits & tempWarnBit) ||
                 (changedBits & tempAlarmBit) )
                writeTemperatureThresh(SERIAL_CHAN,
                     dmItems->tempWarnThresh, dmItems->tempAlarmThresh);

            if (cameraBits & camGroupBits.focusSetPointBit) 
		writeFocusSetPoint(SERIAL_CHAN,
				   dmItems->camItems.focusSetPoint);
	    if (cameraBits & camGroupBits.zoomSetPointBit) 
		writeZoomSetPoint(SERIAL_CHAN,
				   dmItems->camItems.zoomSetPoint);

            if (cameraBits & camGroupBits.zoomRateBit) 
		writeZoomRate(SERIAL_CHAN,
				   dmItems->camItems.zoomRate);

            if (cameraBits & camGroupBits.PWMRateBit) 
		writePWMRate(SERIAL_CHAN,
				   dmItems->camItems.PWMRate);
	              
            if (cameraBits & camGroupBits.focusVelocityGainBit) 
		writeFocusVelocityGain(SERIAL_CHAN,
				   dmItems->camItems.focusVelocityGain);
	    if (cameraBits & camGroupBits.zoomVelocityGainBit) 
		writeZoomVelocityGain(SERIAL_CHAN,
				   dmItems->camItems.zoomVelocityGain);

            if (cameraBits & camGroupBits.focusControlModeBit) 
		writeFocusControlMode(SERIAL_CHAN,
				   dmItems->camItems.focusControlMode);
	    if (cameraBits & camGroupBits.zoomControlModeBit) 
		writeZoomControlMode(SERIAL_CHAN,
				   dmItems->camItems.zoomControlMode);
            
            if (cameraBits & camGroupBits.colorBarsModeBit)
                writeColorBarsMode(SERIAL_CHAN,
                                   dmItems->camItems.colorBarsMode); 
 
            if (cameraBits & camGroupBits.menuModeBit)
                writeMenuMode(SERIAL_CHAN,
                                   dmItems->camItems.menuMode); 

            if (cameraBits & camGroupBits.pageStateBit)
                writePageState(SERIAL_CHAN,
                                   dmItems->camItems.pageState); 

            if (cameraBits & camGroupBits.itemStateBit)
                writeItemState(SERIAL_CHAN,
                                   dmItems->camItems.itemState); 

            if (cameraBits & camGroupBits.upStateBit)
                writeUpState(SERIAL_CHAN,
                                   dmItems->camItems.upState); 

            if (cameraBits & camGroupBits.downStateBit)
                writeDownState(SERIAL_CHAN,
                                   dmItems->camItems.downState); 


            if (cameraBits & camGroupBits.irisModeBit)
                writeIrisMode(SERIAL_CHAN,
                                   dmItems->camItems.irisMode); 

            if (cameraBits & camGroupBits.irisValueBit)
                writeIrisValue(SERIAL_CHAN,
                                   dmItems->camItems.irisValue); 

            if (cameraBits & camGroupBits.gainModeBit)
                writeGainMode(SERIAL_CHAN,
                                   dmItems->camItems.gainMode); 

            if (cameraBits & camGroupBits.gainValueBit)
                writeGainValue(SERIAL_CHAN,
                                   dmItems->camItems.gainValue); 
 	               
            if (cameraBits & camGroupBits.detailModeBit)
                writeDetailMode(SERIAL_CHAN,
                                   dmItems->camItems.detailMode); 
                               
            if (cameraBits & camGroupBits.shutterSpeedBit)
                writeShutterSpeed(SERIAL_CHAN,
                                   dmItems->camItems.shutterSpeed); 
                               
            if (cameraBits & camGroupBits.sceneFileBit)
                writeSceneFile(SERIAL_CHAN,
                                   dmItems->camItems.sceneFile); 

            if (cameraBits & camGroupBits.whiteBalModeBit)
                writeWhiteBalMode(SERIAL_CHAN,
                                   dmItems->camItems.whiteBalMode); 

            if (cameraBits & camGroupBits.autoWhiteBalModeBit)
                writeAutoWhiteBalMode(SERIAL_CHAN,
                                   dmItems->camItems.autoWhiteBalMode); 

            if (cameraBits & camGroupBits.totalPedstalBit)
                writeTotalPedstal(SERIAL_CHAN,
                                   dmItems->camItems.totalPedstal); 
                                  
            if (cameraBits & camGroupBits.redPedstalBit)
                writeRedPedstal(SERIAL_CHAN,
                                   dmItems->camItems.redPedstal); 

            if (cameraBits & camGroupBits.bluePedstalBit)
                writeBluePedstal(SERIAL_CHAN,
                                   dmItems->camItems.bluePedstal); 

            if (cameraBits & camGroupBits.redGainBit)
                writeRedGain(SERIAL_CHAN,
                                   dmItems->camItems.redGain); 

            if (cameraBits & camGroupBits.blueGainBit)
                writeBlueGain(SERIAL_CHAN,
                                   dmItems->camItems.blueGain); 
                                   /* Check if Reset Command request occurred*/
            
            if (changedBits & resetCmdBit)
	    {                       /* Mark serial link as down              */
		setSerialLinkState(microIOCtrl, LINK_DOWN);
            
		                    /* Manual reset so ammounce it           */
		microIOCtrl->announceResets = TRUE;
      			            /* Send Reset Command to Microcontroller */
		microResetCmd(SERIAL_CHAN);             
		break;   	    /* Exit loop and wait for RESET          */
	    }
            taskUnsafe();          /* Task may now be safely deleted         */
	    
        } /* while (LINK_UP) */
    } /* FOREVER */

                       /* dm_stop_provider, dm_stop_consumer, dm_delete_group*/
                       /* etc are NOT required when the task exits as the    */
                       /* Data Manager does this automatically when the task */
                       /* is deleted via the taskDeleteHookAdd() and         */
                       /* dm_task_exit functions.                            */

                       /* That's all folks !                                 */
} /* stbdCameraOutTask() */


/*****************************************************************************/
/* Function    : stbdCameraInTask                                            */
/* Purpose     : Camera Input Task. Wakes up periodically, read data         */
/*               from the Camera and write Data Manager Items                */
/* Inputs      : Array of Data Manager Item handles & serial chan structure  */
/* Outputs     : Normally runs forever, but exits if error occurs            */
/*****************************************************************************/
    Void
stbdCameraInTask(Reg cameraDmItems* dmItems,  microIOControl *microIOCtrl)
{
    SEM_ID  wakeupSem;              /* Used by watch dog to wake up this task*/
    Int32   updates = 0;            /* Counts dm updates for rate calculation*/
                                    /* Create wakeup semaphore and watch dog */
                                    /* timer for provider rate control       */
    if ((wakeupSem = semBCreate(SEM_Q_FIFO, SEM_EMPTY)) == NULL )
    {
        logMsg("Camera : Error initializing stbd Input Task Resources\n");
        return;
    } /* if */
                                   /* Provider Task for non-static data items*/
    dm_start_provider(dmItems->microHumidity,    HUMIDITY_DM_PERIOD);
    dm_start_provider(dmItems->microTemperature, HUMIDITY_DM_PERIOD);

    
    dm_start_provider(dmItems->camItems.focusPosition,
            CAMERA_DM_PERIOD);
    dm_start_provider(dmItems->camItems.zoomPosition,
            CAMERA_DM_PERIOD);

    FOREVER
    {                              /* Wait for Motor Coms to be initialized  */
	semTake(microIOCtrl->childTasks[IN_TASK].taskSyncSem, WAIT_FOREVER);

	while (microIOCtrl->serialLinkState == LINK_UP)
	{ 
	
	    taskSafe();             /* Prevent task from being deleted during*/
                                    /* serial IO and Data Manager updates    */

	    updateFocusPositionDm( SERIAL_CHAN, dmItems->camItems.focusPosition);
	    updateZoomPositionDm( SERIAL_CHAN, dmItems->camItems.zoomPosition);

	    if ((updates % (HUMIDITY_DM_PERIOD / CAMERA_DM_PERIOD)) == 0)
	    {
		updateHumidityDm   ( SERIAL_CHAN, dmItems->microHumidity );
		updateTemperatureDm( SERIAL_CHAN, dmItems->microTemperature );
	    } /* if */

	    taskUnsafe();           /* task may now be deleted safely        */
                                    /* increment & range check update counter*/
	    if (++updates == 10000) updates  = 0;

                                 /* pend until watch dog timer wakes us up*/
	   semTake(wakeupSem, sysClkRateGet() /
               (USECS_PER_SEC / CAMERA_DM_PERIOD));
        } /* while */
    } /* FOREVER */

    semDelete(wakeupSem);           /* semaphore resources                   */

                       /* dm_stop_provider, dm_stop_consumer, dm_delete_group*/
                       /* etc are not required when the task exits as the    */
                       /* data manager does this automatically when the task */
                       /* is deleted via the taskDeleteHookAdd() and         */
                       /* dm_task_exit functions.                            */

                       /* that's all folks !                                 */
} /* stbdCameraInTask() */

/*****************************************************************************/
/* Function    : processCameraSRQ                                           */
/* Purpose     : Decode Service Request and take appropriate action          */
/* Inputs      : SRQ code, array of DM items, serial channel                 */
/* Outputs     : Returns Reset Status & many DM items are changed            */
/*****************************************************************************/
    LOCAL Word
processCameraSRQ( Reg cameraDmItems* dmItems,  microIOControl *microIOCtrl)
{
    Byte buffer[SRQ_PACKET_LEN];    /* Buffer for micro communications data  */
    Word srqRequest;                /* Service Request Value                 */
    Word alarmStatus;               /* Microcontroller Alarm Status Word     */
    microAlarm alarm;               /* Alarm Status                          */

                                    /* Block on Reading Service Request      */
				    /* Block on Reading Service Request      */
    if (readSRQPacket(SERIAL_CHAN, buffer, SRQ_PACKET_LEN, WAIT_FOREVER)
        == ERROR) return (ERROR);
                                    /* Service Request received so process it*/
        srqRequest = wordFromBuf(buffer, 0);

        switch (srqRequest)             /* Decode Service Request from micro */
        {
	  case MICRO_RESET_SRQ:       /* Microcontroller Reset Occurred     */
	                                /* Post Reset Event DM Item           */
	    if (microIOCtrl->announceResets)
		microResetEventDm(dmItems->microDm.resetEvent);
	    break;

	  case INITIALIZED_SRQ:       /* Pan/tilt micro re-initialized     */
	    break;

	  case WATER_ALARM_ON_SRQ:    /* Housing Water Alarm Active        */
	    writeBooleanDmItem(dmItems->canWaterAlarm, TRUE);
	    break;

	  case WATER_ALARM_OFF_SRQ:   /* Housing Water Alarm Inactive      */
	    writeBooleanDmItem(dmItems->canWaterAlarm, FALSE);
	    break;

	  case HUMIDITY_ALARM_SRQ:
	    wordsFromBuf(buffer, 2, &srqRequest, &alarmStatus);
	    alarm = (microAlarm) alarmStatus;
	    writeDmItem(dmItems->humidityAlarm, &alarm, sizeof(alarm));
	    break;

	  case TEMP_ALARM_ON:
	    wordsFromBuf(buffer, 2, &srqRequest, &alarmStatus);
	    alarm = (microAlarm) alarmStatus;
	    writeDmItem(dmItems->temperatureAlarm, &alarm, sizeof(alarm));
	    break;

	  default:
	    printf("Camera: Unrecognized SRQ 0x%x\n", srqRequest);

            break;
        } /* switch */
    return (srqRequest);            /* Return SRQ Received to Caller        */
} /* processCameraSRQ() */

    MLocal STATUS
writeCamCtrlString(sio32Chan *cameraDataChan, Nat16 camera, 
          DM_Item ctrlStringDm)
{
    Errno   status;                 /* Result of dm_read                    */
    Nat16   nBytes;
    char    ctrlString[ CTRL_STRING_LEN];
    Byte    packet[MAX_PACKET_LEN]; /* Command Result from microcontroller  */

                                    /* Read Position from dm                */
    status = dm_read( ctrlStringDm, ctrlString, CTRL_STRING_LEN,
        (DM_Time *) NULL);
                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {
	printf("Ctrl String: %s\n", ctrlString);

	nBytes = strlen(ctrlString);
	ctrlString[nBytes++] = LINE_FEED;

	wordsToBuf(packet, 3, CAMERA_APP | CONTROLLER_STRING, camera, nBytes);
	bcopy( ctrlString, packet + sizeof(Word) * 3, nBytes);
	return (microWriteBufReply( cameraDataChan, nBytes + sizeof(Word) * 3,
	    packet));
    } /* if */	

    return (ERROR);
} /* writeCamCtrlString()  */

    LOCAL STATUS
sendCameraCommand( sio32Chan *sio32DataChan, Nat16 camera, char *camCommand )
{
    char   command[30];                 /* Buffer for micro command data    */
    Word   cmdStatus;                   /* Result of microcontroller command*/
    STATUS status;                      /* Return status of read call       */
    Int16 len;

                                        /* put micro command into buffer    */
    wordToBuf(command, CAMERA_APP | SEND_CAMERA_COMMAND);
                                        /* Append camera address            */
    wordToBuf(command + sizeof(Word), camera);
                                        /* Append Camera Command String   */
    strcpy(command + sizeof(Word) * 2 , camCommand);
    len = strlen(camCommand) + sizeof(Word) * 2;
    command[len++] = LINE_FEED;
    command[len++] = '\0';

    return (microWriteBufReply(sio32DataChan, len, command));
} /* sendCameraCommand() */

/****************************************************************************/
/* Function    : writeFocusSetPoint                                         */
/* Purpose     : Get Focus Set Point from dm and send to micro              */
/* Inputs      : Sio32 channel, set point dm item handles                   */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeFocusSetPoint( sio32Chan *cameraDataChan, DM_Item setPointDm )
{
    Int16   setPoint;               /* Set Point                            */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Humidity Thresholds from dm     */
    status = dm_read( setPointDm, (char *) &setPoint,
         sizeof(setPoint), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_FOCUS_SET_POINT, setPoint )
             == ERROR ) return(ERROR);

                                    /* Check command result                  */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeFocusSetPoint() */

/****************************************************************************/
/* Function    : writeZoomSetPoint                                          */
/* Purpose     : Get Zoom Set Point from dm and send to micro               */
/* Inputs      : Sio32 channel, set point dm item handles                   */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeZoomSetPoint( sio32Chan *cameraDataChan, DM_Item setPointDm )
{
    Int16   setPoint;               /* Set Point                            */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Humidity Thresholds from dm     */
    status = dm_read( setPointDm, (char *) &setPoint,
         sizeof(setPoint), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_ZOOM_SET_POINT, setPoint )
             == ERROR ) return(ERROR);

                                    /* Check command result                  */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeZoomSetPoint() */

/****************************************************************************/
/* Function    : writeZoomRate                                              */
/* Purpose     : Get Zoom Rate from dm and send to micro                    */
/* Inputs      : Sio32 channel, set point dm item handles                   */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeZoomRate( sio32Chan *cameraDataChan, DM_Item zoomRateDm )
{
    Int16   zoomRate;               /* Rate                                 */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Zoom Rate from dm               */
    status = dm_read( zoomRateDm, (char *) &zoomRate,
         sizeof(zoomRate), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_ZOOM_RATE, zoomRate )
             == ERROR ) return(ERROR);

                                    /* Check command result                  */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeZoomRate() */

/****************************************************************************/
/* Function    : writePWMRate                                               */
/* Purpose     : Get PWM Rate from dm and send to micro                     */
/* Inputs      : Sio32 channel, PWM Rate dm item handles                    */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writePWMRate( sio32Chan *cameraDataChan, DM_Item PWMRateDm )
{
    Int16   PWMRate;                /* PWM Rate                             */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Humidity Thresholds from dm     */
    status = dm_read( PWMRateDm, (char *) &PWMRate,
         sizeof(PWMRate), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_PWM_RATE, PWMRate )
             == ERROR ) return(ERROR);

                                    /* Check command result                  */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writePWMRate() */

/****************************************************************************/
/* Function    : writeFocusVelocityGain                                     */
/* Purpose     : Get Focus Velocity Gain from dm and send to micro          */
/* Inputs      : Sio32 channel, Velocity Gain dm item handle                */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeFocusVelocityGain( sio32Chan *cameraDataChan, DM_Item velocityGainDm )
{
    Int16   velocityGain;           /* Velocity Gain                        */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Velocity Gain from dm           */
    status = dm_read( velocityGainDm, (char *) &velocityGain,
         sizeof(velocityGain), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_FOCUS_VELOCITY_GAIN, velocityGain )
             == ERROR ) return(ERROR);

                                    /* Check command result                  */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeFocusVelocityGain() */

/****************************************************************************/
/* Function    : writeZoomVelocityGain                                      */
/* Purpose     : Get Zoom Velocity Gain from dm and send to micro           */
/* Inputs      : Sio32 channel, Velocity Gain dm item handle                */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeZoomVelocityGain( sio32Chan *cameraDataChan, DM_Item velocityGainDm )
{
    Int16   velocityGain;           /* Velocity Gain                        */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Velocity Gain from dm           */
    status = dm_read( velocityGainDm, (char *) &velocityGain,
         sizeof(velocityGain), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_ZOOM_VELOCITY_GAIN, velocityGain )
             == ERROR ) return(ERROR);

                                    /* Check command result                  */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeZoomVelocityGain() */

/****************************************************************************/
/* Function    : writeFocusControlMode                                      */
/* Purpose     : Get Focus Control Mode from dm and send to micro           */
/* Inputs      : Sio32 channel, Control Mode dm item handle                 */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeFocusControlMode( sio32Chan *cameraDataChan, DM_Item controlModeDm )
{
    Int16   controlMode;            /* Control Mode                         */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Control Mode from dm     */
    status = dm_read( controlModeDm, (char *) &controlMode,
         sizeof(controlMode), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_FOCUS_CONTROL_MODE, controlMode )
             == ERROR ) return(ERROR);

                                    /* Check command result                  */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeFocusControlMode() */

/****************************************************************************/
/* Function    : writeZoomControlMode                                       */
/* Purpose     : Get Zoom Control Mode from dm and send to micro            */
/* Inputs      : Sio32 channel, Control Mode dm item handle                 */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeZoomControlMode( sio32Chan *cameraDataChan, DM_Item controlModeDm )
{
    Int16   controlMode;            /* Control Mode                         */
    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Control Mode from dm            */
    status = dm_read( controlModeDm, (char *) &controlMode,
         sizeof(controlMode), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_ZOOM_CONTROL_MODE, controlMode )
             == ERROR ) return(ERROR);

                                    /* Check command result                  */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeZoomControlMode() */

/****************************************************************************/
/* Function    : writeColorBarsMode                                         */
/* Purpose     : Get Color Bars Mode from dm and send to micro              */
/* Inputs      : Sio32 channel, Control Mode dm item handle                 */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeColorBarsMode( sio32Chan *cameraDataChan, DM_Item controlModeDm )
{
    MBool   controlMode;            /* Control Mode                         */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Control Mode from dm     */
    status = dm_read( controlModeDm, (char *) &controlMode,
         sizeof(controlMode), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_COLOR_BARS_MODE, controlMode )
             == ERROR ) return(ERROR);

                                    /* Check command result                  */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeColorBarsMode() */

/****************************************************************************/
/* Function    : writeMenuMode                                              */
/* Purpose     : Get Menu Mode from dm and send to micro                    */
/* Inputs      : Sio32 channel, Control Mode dm item handle                 */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeMenuMode( sio32Chan *cameraDataChan, DM_Item controlModeDm )
{
    MBool   controlMode;            /* Control Mode                         */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Control Mode from dm     */
    status = dm_read( controlModeDm, (char *) &controlMode,
         sizeof(controlMode), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_MENU_MODE, controlMode )
             == ERROR ) return(ERROR);

                                    /* Check command result                  */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeMenuMode() */

/****************************************************************************/
/* Function    : writePageState                                             */
/* Purpose     : Get Page State from dm and send to micro                   */
/* Inputs      : Sio32 channel, Control Mode dm item handle                 */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writePageState( sio32Chan *cameraDataChan, DM_Item controlModeDm )
{
    MBool   controlMode;            /* Control Mode                         */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Control Mode from dm     */
    status = dm_read( controlModeDm, (char *) &controlMode,
         sizeof(controlMode), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_PAGE_STATE, controlMode )
             == ERROR ) return(ERROR);

                                    /* Check command result                  */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writePageState() */

/****************************************************************************/
/* Function    : writeItemState                                             */
/* Purpose     : Get Item State from dm and send to micro                   */
/* Inputs      : Sio32 channel, Control Mode dm item handle                 */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeItemState( sio32Chan *cameraDataChan, DM_Item controlModeDm )
{
    MBool   controlMode;            /* Control Mode                         */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Control Mode from dm     */
    status = dm_read( controlModeDm, (char *) &controlMode,
         sizeof(controlMode), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_ITEM_STATE, controlMode )
             == ERROR ) return(ERROR);

                                    /* Check command result                  */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeItemState() */

/****************************************************************************/
/* Function    : writeUpState                                               */
/* Purpose     : Get Up State from dm and send to micro                     */
/* Inputs      : Sio32 channel, Control Mode dm item handle                 */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeUpState( sio32Chan *cameraDataChan, DM_Item controlModeDm )
{
    MBool   controlMode;            /* Control Mode                         */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Control Mode from dm     */
    status = dm_read( controlModeDm, (char *) &controlMode,
         sizeof(controlMode), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_UP_STATE, controlMode )
             == ERROR ) return(ERROR);

                                    /* Check command result                  */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeUpState() */

/****************************************************************************/
/* Function    : writeDownState                                             */
/* Purpose     : Get Down State from dm and send to micro                   */
/* Inputs      : Sio32 channel, Control Mode dm item handle                 */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeDownState( sio32Chan *cameraDataChan, DM_Item controlModeDm )
{
    MBool   controlMode;            /* Control Mode                         */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Control Mode from dm     */
    status = dm_read( controlModeDm, (char *) &controlMode,
         sizeof(controlMode), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_DOWN_STATE, controlMode )
             == ERROR ) return(ERROR);

                                    /* Check command result                  */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeDownState() */


/****************************************************************************/
/* Function    : writeIrisMode                                              */
/* Purpose     : Get Iris Mode from dm and send to micro                    */
/* Inputs      : Sio32 channel, Control Mode dm item handle                 */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeIrisMode( sio32Chan *cameraDataChan, DM_Item controlModeDm )
{
    MBool   controlMode;            /* Control Mode                         */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Control Mode from dm     */
    status = dm_read( controlModeDm, (char *) &controlMode,
         sizeof(controlMode), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_IRIS_MODE, controlMode )
             == ERROR ) return(ERROR);

                                    /* Check command result                  */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeIrisMode() */

/****************************************************************************/
/* Function    : writeIrisValue                                             */
/* Purpose     : Get Iris Value from dm and send to micro                   */
/* Inputs      : Sio32 channel, Iris Value dm item handle                   */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeIrisValue( sio32Chan *cameraDataChan, DM_Item irisValueDm )
{
    Int16   irisValue;              /* Iris Value                           */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Iris Value from dm     */
    status = dm_read( irisValueDm, (char *) &irisValue,
         sizeof(irisValue), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_IRIS_VALUE, irisValue )
             == ERROR ) return(ERROR);

                                    /* Check command result                  */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeIrisValue() */

/****************************************************************************/
/* Function    : writeGainMode                                              */
/* Purpose     : Get Gain Mode from dm and send to micro                    */
/* Inputs      : Sio32 channel, Gain Mode dm item handle                    */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeGainMode( sio32Chan *cameraDataChan, DM_Item gainModeDm )
{
    gainModeType gainMode;          /* Gain  Mode                           */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Gain Mode from dm     */
    status = dm_read( gainModeDm, (char *) &gainMode,
         sizeof(gainMode), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_GAIN_MODE, gainMode )
             == ERROR ) return(ERROR);

                                    /* Check command result                  */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeGainMode() */

/****************************************************************************/
/* Function    : writeGainValue                                             */
/* Purpose     : Get Gain Value from dm and send to micro                   */
/* Inputs      : Sio32 channel, Gain Value dm item handle                   */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeGainValue( sio32Chan *cameraDataChan, DM_Item gainValueDm )
{
    gainValueType gainValue;        /* Gain Value                           */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Gain Value from dm              */
    status = dm_read( gainValueDm, (char *) &gainValue,
         sizeof(gainValue), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_GAIN_VALUE, gainValue )
             == ERROR ) return(ERROR);

                                    /* Check command result                  */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeGainValue() */


/****************************************************************************/
/* Function    : writeDetailMode                                            */
/* Purpose     : Get Detail Mode from dm and send to micro                  */
/* Inputs      : Sio32 channel, Detail Mode dm item handle                  */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeDetailMode( sio32Chan *cameraDataChan, DM_Item detailModeDm )
{
    detailModeType detailMode;      /* Detail Mode                          */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Detail Mode from dm             */
    status = dm_read( detailModeDm, (char *) &detailMode,
         sizeof(detailMode), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_DETAIL_MODE, detailMode )
             == ERROR ) return(ERROR);

                                    /* Check command result                  */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeDetailMode() */

/****************************************************************************/
/* Function    : writeShutterSpeed                                          */
/* Purpose     : Get Shutter Speed from dm and send to micro                */
/* Inputs      : Sio32 channel, Shutter Speed dm item handle                */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeShutterSpeed( sio32Chan *cameraDataChan, DM_Item shutterSpeedDm )
{
    shutterSpeedType shutterSpeed;  /* Shutter Speed                        */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Shutter Speed from dm           */
    status = dm_read( shutterSpeedDm, (char *) &shutterSpeed,
         sizeof(shutterSpeed), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_SHUTTER_SPEED, shutterSpeed )
             == ERROR ) return(ERROR);

                                    /* Check command result                  */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeShutterSpeed() */

/****************************************************************************/
/* Function    : writeSceneFile                                             */
/* Purpose     : Get Scene File From dm and send to micro                   */
/* Inputs      : Sio32 channel, Scene File dm item handle                   */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeSceneFile( sio32Chan *cameraDataChan, DM_Item sceneFileDm )
{
    sceneFileType sceneFile;        /* Scene File                           */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Scene File from dm              */
    status = dm_read( sceneFileDm, (char *) &sceneFile,
         sizeof(sceneFile), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_SCENE_FILE, sceneFile )
             == ERROR ) return(ERROR);

                                    /* Check command result                  */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeSceneFile() */

/***************************************************************************/
/* Function    : writeWhiteBalMode                                          */
/* Purpose     : Get White Balance Mode From dm and send to micro           */
/* Inputs      : Sio32 channel, White Balance Mode dm item handle           */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeWhiteBalMode( sio32Chan *cameraDataChan, DM_Item whiteBalModeDm )
{
    whiteBalModeType whiteBalMode;    /* White Balance Mode                   */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read White Balance Mode from dm      */
    status = dm_read( whiteBalModeDm, (char *) &whiteBalMode,
         sizeof(whiteBalMode), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_AWC_MODE, whiteBalMode )
             == ERROR ) return(ERROR);

                                    /* Check command result                  */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeWhiteBalMode() */

/****************************************************************************/
/* Function    : writeAutoWhiteBalMode                                      */
/* Purpose     : Get Auto White Balance Mode From dm and send to micro      */
/* Inputs      : Sio32 channel, Auto White Balance Mode dm item handle      */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeAutoWhiteBalMode( sio32Chan *cameraDataChan, DM_Item autoWhiteBalModeDm )
{
    autoWhiteBalModeType autoWhiteBalMode; /* Auto White Balance Mode       */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Auto White Balance Mode from dm */
    status = dm_read( autoWhiteBalModeDm, (char *) &autoWhiteBalMode,
         sizeof(autoWhiteBalMode), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_ATW_MODE, autoWhiteBalMode )
             == ERROR ) return(ERROR);

                                    /* Check command result                  */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeAutoWhiteBalMode() */

/***************************************************************************/
/* Function    : writeTotalPedstal                                          */
/* Purpose     : Get Total Pedstal From dm and send to micro                */
/* Inputs      : Sio32 channel, Total Pedstal dm item handle                */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeTotalPedstal( sio32Chan *cameraDataChan, DM_Item totalPedstalDm )
{
    Int16   totalPedstal;           /* Total Pedstal                        */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Total Pedstal from dm           */
    status = dm_read( totalPedstalDm, (char *) &totalPedstal,
         sizeof(totalPedstal), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_TOTAL_PEDSTAL, totalPedstal )
             == ERROR ) return(ERROR);

                                    /* Check command result                  */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeTotalPedstal() */

/****************************************************************************/
/* Function    : writeRedPedstal                                            */
/* Purpose     : Get Red Pedstal From dm and send to micro                  */
/* Inputs      : Sio32 channel, Red Pedstal dm item handle                  */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeRedPedstal( sio32Chan *cameraDataChan, DM_Item redPedstalDm )
{
    Int16   redPedstal;             /* Red Pedstal                          */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Red Pedstal from dm             */
    status = dm_read( redPedstalDm, (char *) &redPedstal,
         sizeof(redPedstal), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_RED_PEDSTAL, redPedstal )
             == ERROR ) return(ERROR);

                                    /* Check command result                 */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeRedPedstal() */
/****************************************************************************/
/* Function    : writeBluePedstal                                           */
/* Purpose     : Get Blue Pedstal From dm and send to micro                 */
/* Inputs      : Sio32 channel, Blue Pedstal dm item handle                 */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeBluePedstal( sio32Chan *cameraDataChan, DM_Item bluePedstalDm )
{
    Int16   bluePedstal;            /* Blue Pedstal                         */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Blue Pedstal from dm            */
    status = dm_read( bluePedstalDm, (char *) &bluePedstal,
         sizeof(bluePedstal), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_BLUE_PEDSTAL, bluePedstal )
             == ERROR ) return(ERROR);

                                    /* Check command result                 */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeBluePedstal() */

/****************************************************************************/
/* Function    : writeRedGain                                            */
/* Purpose     : Get Red Gain From dm and send to micro                  */
/* Inputs      : Sio32 channel, Red Gain dm item handle                  */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeRedGain( sio32Chan *cameraDataChan, DM_Item redGainDm )
{
    Int16   redGain;             /* Red Gain                          */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Red Gain from dm             */
    status = dm_read( redGainDm, (char *) &redGain,
         sizeof(redGain), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_RED_GAIN, redGain )
             == ERROR ) return(ERROR);

                                    /* Check command result                 */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeRedGain() */
/****************************************************************************/
/* Function    : writeBlueGain                                           */
/* Purpose     : Get Blue Gain From dm and send to micro                 */
/* Inputs      : Sio32 channel, Blue Gain dm item handle                 */
/* Outputs     : Returns OK or ERROR                                        */
/****************************************************************************/
    MLocal STATUS
writeBlueGain( sio32Chan *cameraDataChan, DM_Item blueGainDm )
{
    Int16   blueGain;            /* Blue Gain                         */

    Errno   status;                 /* Result of dm_read                    */
    Word    cmdStatus;              /* command Result from microcontroller  */

                                    /* Read Blue Gain from dm            */
    status = dm_read( blueGainDm, (char *) &blueGain,
         sizeof(blueGain), (DM_Time *) NULL);

                                    /* Check for successful dm_read         */
    if ((status == SUCCESS) || (status == EDM_NOPROVIDER))
    {                               /* Send command to microcontroller      */
        if ( sendMicroCommand( cameraDataChan, &cmdStatus, sizeof(cmdStatus),
            2,  CAMERA_APP | SET_BLUE_GAIN, blueGain )
             == ERROR ) return(ERROR);

                                    /* Check command result                 */
        return (wordFromBuf(&cmdStatus, 0) == CMD_OK ? OK : ERROR);
    } /* if */

    return(ERROR);
} /* writeBlueGain() */









