示例#1
0
        protected HVSTATUS SetExposureTime(int nWindWidth, int nUpper, int nLower, int nHBlanking,
                                           HV_SNAP_SPEED SnapSpeed, HV_RESOLUTION Resolution)
        {
            double clockFreq = 0.0;
            int    tB        = nHBlanking;
            int    outPut    = nWindWidth;
            double exposure  = 0.0;

            Debug.Assert(nLower != 0);
            double temp = (double)nUpper / (double)nLower;
            double tInt = (temp > m_kZeorInDouble) ? temp : m_kZeorInDouble;

            if (IsGV400())
            {
                tB       += 0x5e;
                clockFreq = (SnapSpeed == HV_SNAP_SPEED.HIGH_SPEED) ? 26600000.0 : 13300000.0;
                int rate = 0;
                switch (Resolution)
                {
                case HV_RESOLUTION.RES_MODE0:
                    rate = 1;
                    break;

                case HV_RESOLUTION.RES_MODE1:
                    rate = 2;
                    break;

                default:
                    return(HVSTATUS.STATUS_PARAMETER_OUT_OF_BOUND);
                }

                outPut = outPut * rate;

                if ((tInt * clockFreq) <= (outPut + tB - 255))
                {
                    exposure = 1;
                }
                else
                {
                    Debug.Assert((outPut + tB) != 0);
                    exposure = ((tInt * clockFreq) - (outPut + tB - 255)) / (outPut + tB);
                }

                if (exposure < 3)
                {
                    exposure = 3;
                }
                else if (exposure > 32766)
                {
                    exposure = 32766;
                }
            }
            else if (IsHV300())
            {
                clockFreq = (SnapSpeed == HV_SNAP_SPEED.HIGH_SPEED) ? 24000000 : 12000000;
                tB       += 142;
                if (tB < 21)
                {
                    tB = 21;
                }
                int param1 = 331;
                int param2 = 38;
                int param3 = 316;
                if (Resolution == HV_RESOLUTION.RES_MODE1)
                {
                    param1 = 673;
                    param2 = 22;
                    param3 = 316 * 2;
                }
                int AQ   = outPut + param1 + param2 + tB;
                int tmp  = param1 + param3;
                int trow = (AQ > tmp) ? AQ : tmp;

                Debug.Assert(trow != 0);
                exposure = ((tInt * clockFreq) + param1 - 132.0) / trow;

                if ((exposure - (int)exposure) > 0.5)
                {
                    exposure += 1.0;
                }
                if (exposure <= 0)
                {
                    exposure = 1;
                }
                else if (exposure > 1048575)
                {
                    exposure = 1048575;
                }
            }
            else if (IsHV200())
            {
                clockFreq = (SnapSpeed == HV_SNAP_SPEED.HIGH_SPEED) ? 24000000 : 12000000;
                tB       += 53;
                if (tB < 19)
                {
                    tB = 19;
                }
                int AQ   = outPut + 305 + tB;
                int trow = (617 > AQ) ? 617 : AQ;
                Debug.Assert((trow + 1) != 0);
                exposure = (tInt * clockFreq + 180.0) / trow + 1;
                if ((exposure - (int)exposure) > 0.5)
                {
                    exposure += 1.0;
                }
                if (exposure <= 0)
                {
                    exposure = 1;
                }
                else if (exposure > 16383)
                {
                    exposure = 16383;
                }
            }
            else if (IsHV5051())
            {
                SHUTTER_UNIT_VALUE unit = SHUTTER_UNIT_VALUE.SHUTTER_MS;
                if (nLower == 1000000)
                {
                    unit = SHUTTER_UNIT_VALUE.SHUTTER_US;
                }
                //设置曝光时间单位
                HVSTATUS status = USBCameraAPI.HVAECControl(m_pHandle, (byte)HV_AEC_CONTROL.AEC_SHUTTER_UNIT, (int)unit);
                if (!USBCameraAPI.HV_SUCCESS(status))
                {
                    return(status);
                }
                //设置曝光时间
                return(USBCameraAPI.HVAECControl(m_pHandle, (byte)HV_AEC_CONTROL.AEC_SHUTTER_SPEED, nUpper));
            }
            else
            {
                clockFreq = (SnapSpeed == HV_SNAP_SPEED.HIGH_SPEED) ? 24000000 : 12000000;
                tB       += 9;
                tB       -= 19;
                if (tB <= 0)
                {
                    tB = 0;
                }
                if ((outPut + 244.0 + tB) > 552)
                {
                    exposure = (tInt * clockFreq + 180.0) / ((double)outPut + 244.0 + tB);
                }
                else
                {
                    exposure = ((tInt * clockFreq) + 180.0) / 552;
                }

                if ((exposure - (int)exposure) > 0.5)
                {
                    exposure += 1.0;
                }
                if (exposure <= 0)
                {
                    exposure = 1;
                }
                else if (exposure > 16383)
                {
                    exposure = 16383;
                }
            }
            return(USBCameraAPI.HVAECControl(m_pHandle, (byte)HV_AEC_CONTROL.AEC_EXPOSURE_TIME, (int)exposure));
        }