public VideoState GetCurrentState(CameraStateQuery query)
        {
            var rv = new VideoState();

            if (m_Driver != null && m_Driver.IsConnected)
            {
                rv.MinGainIndex = m_Driver.MinGainIndex;
                rv.MaxGainIndex = m_Driver.MaxGainIndex;
                rv.MinGammaIndex = m_Driver.MinGammaIndex;
                rv.MaxGammaIndex = m_Driver.MaxGammaIndex;
                rv.MinExposureIndex = m_Driver.MinExposureIndex;
                rv.MaxExposureIndex = m_Driver.MaxExposureIndex;

                if (m_CurrentState == null)
                {
                    m_CurrentState = new WAT910BDCameraState();
                    query = CameraStateQuery.All;
                }

                WAT910BDCameraState camState = m_Driver.ReadCurrentCameraState(query);
                if ((query & CameraStateQuery.Gamma) == CameraStateQuery.Gamma)
                {
                    m_CurrentState.GammaIndex = camState.GammaIndex;
                    m_CurrentState.Gamma = camState.Gamma;
                    m_CurrentState.GammaSuccess = camState.GammaSuccess;
                }
                if ((query & CameraStateQuery.Gain) == CameraStateQuery.Gain)
                {
                    m_CurrentState.GainIndex = camState.GainIndex;
                    m_CurrentState.Gain = camState.Gain;
                    m_CurrentState.GainSuccess = camState.GainSuccess;
                }
                if ((query & CameraStateQuery.Shutter) == CameraStateQuery.Shutter)
                {
                    m_CurrentState.ExposureIndex = camState.ExposureIndex;
                    m_CurrentState.Exposure = camState.Exposure;
                    m_CurrentState.ExposureSuccess = camState.ExposureSuccess;
                }

                rv.GainIndex = m_CurrentState.GainIndex;
                rv.GammaIndex = m_CurrentState.GammaIndex;
                rv.ExposureIndex = m_CurrentState.ExposureIndex;

                rv.Gain = m_CurrentState.Gain;
                rv.Gamma = m_CurrentState.Gamma;
                rv.Exposure = m_CurrentState.Exposure;
            }

            return rv;
        }
Example #2
0
        public WAT910BDCameraState ReadCurrentCameraState(CameraStateQuery query)
        {
            var rv = new WAT910BDCameraState();

            List<WAT910BDCommandWithResponse> executedCommands = new List<WAT910BDCommandWithResponse>();

            WAT910BDCommandWithResponse cmd;

            if (query == CameraStateQuery.All)
                executedCommands = SendCameraCommandSeries(MultipleCommandSeries.ReadCameraState, true);
            else if ((query & CameraStateQuery.Gamma) == CameraStateQuery.Gamma)
            {
                cmd = new WAT910BDCommandWithResponse()
                {
                    Command = WAT910BDCommand.ReadGamma,
                    CommandBytes = m_StateMachine.BuildReadCommand(WAT910BDCommand.ReadGamma)
                };
                if (SendReadCommand(cmd.CommandBytes, cmd.Command.ToString()))
                {
                    cmd.Response = m_StateMachine.LastReceivedMessage();
                    executedCommands.Add(cmd);
                }
            }
            else if ((query & CameraStateQuery.Gain) == CameraStateQuery.Gain)
            {
                cmd = new WAT910BDCommandWithResponse()
                {
                    Command = WAT910BDCommand.ReadGain,
                    CommandBytes = m_StateMachine.BuildReadCommand(WAT910BDCommand.ReadGain)
                };
                if (SendReadCommand(cmd.CommandBytes, cmd.Command.ToString()))
                {
                    cmd.Response = m_StateMachine.LastReceivedMessage();
                    executedCommands.Add(cmd);
                }
            }
            else if ((query & CameraStateQuery.Shutter) == CameraStateQuery.Shutter)
            {
                cmd = new WAT910BDCommandWithResponse()
                {
                    Command = WAT910BDCommand.ReadShutter,
                    CommandBytes = m_StateMachine.BuildReadCommand(WAT910BDCommand.ReadShutter)
                };
                if (SendReadCommand(cmd.CommandBytes, cmd.Command.ToString()))
                {
                    cmd.Response = m_StateMachine.LastReceivedMessage();
                    executedCommands.Add(cmd);
                }
            }

            byte gammaByte = 0;
            byte gainByte = 0;
            byte shuterByte = 0;

            if ((query & CameraStateQuery.Gamma) == CameraStateQuery.Gamma)
            {
                cmd = executedCommands.SingleOrDefault(x => x.Command == WAT910BDCommand.ReadGamma);
                if (cmd != null && cmd.Response != null)
                {
                    rv.GammaSuccess = cmd.Response != null && cmd.Response.Length == 3;
                    gammaByte = rv.GammaSuccess ? cmd.Response[2] : (byte)0;

                    rv.GammaIndex = m_StateMachine.GammaByteToIndex(gammaByte);
                    rv.Gamma = rv.GammaSuccess ? m_StateMachine.GammaByteToString(gammaByte) : string.Empty;
                    m_StateMachine.SetGammaIndex(rv.GammaIndex);
                }
            }
            if ((query & CameraStateQuery.Gain) == CameraStateQuery.Gain)
            {
                cmd = executedCommands.SingleOrDefault(x => x.Command == WAT910BDCommand.ReadGain);
                if (cmd != null && cmd.Response != null)
                {
                    rv.GainSuccess = cmd.Response != null && cmd.Response.Length == 3;
                    gainByte = rv.GainSuccess ? cmd.Response[2] : (byte)0;

                    rv.GainIndex = m_StateMachine.GainByteToIndex(gainByte);
                    rv.Gain = rv.GainSuccess ? m_StateMachine.GainByteToString(gainByte) : string.Empty;
                    m_StateMachine.SetGainIndex(rv.GainIndex);
                }
            }
            if ((query & CameraStateQuery.Shutter) == CameraStateQuery.Shutter)
            {
                cmd = executedCommands.SingleOrDefault(x => x.Command == WAT910BDCommand.ReadShutter);
                if (cmd != null && cmd.Response != null)
                {
                    rv.ExposureSuccess = cmd.Response != null && cmd.Response.Length == 3;
                    shuterByte = rv.ExposureSuccess ? cmd.Response[2] : (byte)0;

                    rv.ExposureIndex = m_StateMachine.ExposureByteToIndex(shuterByte);
                    rv.Exposure = rv.ExposureSuccess ? m_StateMachine.ExposureByteToString(shuterByte) : string.Empty;
                    m_StateMachine.SetExposureIndex(rv.ExposureIndex);
                }
            }

            #if DEBUG
            Trace.WriteLine(string.Format("gainByte = {0} gammaByte = {1} shuterByte = {2}", gainByte, gammaByte, shuterByte));
            #endif

            return rv;
        }