Пример #1
0
        private static void CheckReturn(ASI_ERROR_CODE errorCode, MethodBase callingMethod, params object[] parameters)
        {
            switch (errorCode)
            {
            case ASI_ERROR_CODE.ASI_SUCCESS:
                break;

            case ASI_ERROR_CODE.ASI_ERROR_INVALID_INDEX:
            case ASI_ERROR_CODE.ASI_ERROR_INVALID_ID:
            case ASI_ERROR_CODE.ASI_ERROR_INVALID_CONTROL_TYPE:
            case ASI_ERROR_CODE.ASI_ERROR_CAMERA_CLOSED:
            case ASI_ERROR_CODE.ASI_ERROR_CAMERA_REMOVED:
            case ASI_ERROR_CODE.ASI_ERROR_INVALID_PATH:
            case ASI_ERROR_CODE.ASI_ERROR_INVALID_FILEFORMAT:
            case ASI_ERROR_CODE.ASI_ERROR_INVALID_SIZE:
            case ASI_ERROR_CODE.ASI_ERROR_INVALID_IMGTYPE:
            case ASI_ERROR_CODE.ASI_ERROR_OUTOF_BOUNDARY:
            case ASI_ERROR_CODE.ASI_ERROR_TIMEOUT:
            case ASI_ERROR_CODE.ASI_ERROR_INVALID_SEQUENCE:
            case ASI_ERROR_CODE.ASI_ERROR_BUFFER_TOO_SMALL:
            case ASI_ERROR_CODE.ASI_ERROR_VIDEO_MODE_ACTIVE:
            case ASI_ERROR_CODE.ASI_ERROR_EXPOSURE_IN_PROGRESS:
            case ASI_ERROR_CODE.ASI_ERROR_GENERAL_ERROR:
            case ASI_ERROR_CODE.ASI_ERROR_END:
                throw new ASICameraException(errorCode, callingMethod, parameters);

            default:
                throw new ArgumentOutOfRangeException("errorCode");
            }
        }
Пример #2
0
        public Result SetControItemValue(CameraControlItemType type, int value)
        {
            var controlItem = _CameraControlItemList.SingleOrDefault(c => c.ControlItemType == type);

            if (controlItem == null)
            {
                return(new Result(ErrorCode.Error, "No Such Control Item"));
            }

            //TODO:if newValue = oldValue, do nothing?
            var oldValue = controlItem.Value;

            ASI_ERROR_CODE asi_error_code = ASI_ERROR_CODE.ASI_SUCCESS;
            Exception      exception      = null;

            try
            {
                asi_error_code    = ASISetControlValue(CameraID, ((ASI_CONTROL_CAPS)controlItem.NativeItem).ControlType, value);
                controlItem.Value = value; //TODO: We should get value from device
            }
            catch (Exception e)
            {
                exception = e;
            }

            //TODO: Log the description the control item include min and max value, etc.
            return(GetOperationResult(String.Format("SetControlValue, ItemName {0}, ItemType {1}, OldValue {2}, NewValue {3}",
                                                    controlItem.Description, controlItem.ControlItemType, oldValue, value),
                                      asi_error_code, exception));
        }
Пример #3
0
        public static int ASIGetControlValue(int iCameraID, ASI_CONTROL_TYPE ControlType)
        {
            ASI_BOOL       pbAuto;
            int            plValue;
            ASI_ERROR_CODE err = IntPtr.Size == 8 /* 64bit */ ? ASIGetControlValue64(iCameraID, ControlType, out plValue, out pbAuto) : ASIGetControlValue32(iCameraID, ControlType, out plValue, out pbAuto);

            return(plValue);
        }
Пример #4
0
        private Result GetOperationResult(string operationName, ASI_ERROR_CODE asi_error_code, Exception exception, bool logSuccess = true)
        {
            if (exception == null && asi_error_code == ASI_ERROR_CODE.ASI_SUCCESS && logSuccess)
            {
                Log.InfoFormat("{0} Success, CameraID {1}, CameraName {2}", operationName, CameraID, CameraInfo.DisplayName);
                return(new Result(String.Format("{0} Success, CameraID {1}, CameraName {2}", operationName, CameraID, CameraInfo.DisplayName)));
            }

            string message = String.Format("{0} Failed, CameraID {1}, CameraName {2}, ASI_ERROR_CODE {3}",
                                           operationName, CameraID, CameraInfo.DisplayName, asi_error_code.ToString());

            Log.Error(message, exception);
            Status = CameraStatus.Error;

            return(new Result(ErrorCode.OperationFailed, message, exception));
        }
Пример #5
0
        public Result StartCapture(bool isDark)
        {
            ASI_ERROR_CODE asi_error_code = ASI_ERROR_CODE.ASI_SUCCESS;
            Exception      exception      = null;

            try
            {
                asi_error_code = ASIStartExposure(CameraID, (isDark ? ASI_BOOL.ASI_TRUE : ASI_BOOL.ASI_FALSE));
                Status         = CameraStatus.Working;
            }
            catch (Exception e)
            {
                exception = e;
            }
            return(GetOperationResult("ASIStartExposure_" + (isDark ? "Dark" : "NoDark"), asi_error_code, exception));
        }
Пример #6
0
        public Result Disconnect()
        {
            ASI_ERROR_CODE asi_error_code = ASI_ERROR_CODE.ASI_SUCCESS;
            Exception      exception      = null;

            try
            {
                asi_error_code = ASICloseCamera(CameraID);
            }
            catch (Exception e)
            {
                exception = e;
            }

            Status = CameraStatus.Closed;
            return(GetOperationResult("ASICloseCamera", asi_error_code, exception));
        }
Пример #7
0
        private Result InitialControlItems()
        {
            ASI_ERROR_CODE asi_error_code = ASI_ERROR_CODE.ASI_SUCCESS;
            Exception      exception      = null;
            Result         result;

            int controlItemCount = 0;

            try
            {
                asi_error_code = ASIGetNumOfControls(CameraID, out controlItemCount);
            }
            catch (Exception e)
            {
                exception = e;
            }
            result = GetOperationResult("ASIGetNumOfControls", asi_error_code, exception);
            if (result.Code != ErrorCode.OK)
            {
                return(result);
            }


            for (int i = 0; i < controlItemCount; i++)
            {
                ASI_CONTROL_CAPS asiControlCaps;
                try
                {
                    asi_error_code = ASIGetControlCaps(CameraID, i, out asiControlCaps);
                    _CameraControlItemList.Add(ConvertToCameraControlItem(asiControlCaps));
                }
                catch (Exception e)
                {
                    exception = e;
                }
                result = GetOperationResult("ASIGetNumOfControls", asi_error_code, exception);
                if (result.Code != ErrorCode.OK)
                {
                    return(result);
                }
            }
            return(new Result());
        }
Пример #8
0
        public Result GetCaputreData(UInt16[] data)
        {
            ASI_ERROR_CODE asi_error_code = ASI_ERROR_CODE.ASI_SUCCESS;
            Exception      exception      = null;

            try
            {
                asi_error_code = ASIGetDataAfterExp(CameraID, data, data.Length);
            }
            catch (Exception e)
            {
                exception = e;
            }

            //TODO: DebugLog
            //long value = ASIGetControlValue(_CameraID, ASI_CONTROL_TYPE.ASI_EXPOSURE);
            //Log.InfoFormat("{0}", value);

            return(GetOperationResult("ASIGetDataAfterExp", asi_error_code, exception));
        }
Пример #9
0
        public Result GetCaputreStat(out CameraStatus captureStatus, bool logSuccessResult = false)
        {
            ASI_ERROR_CODE asi_error_code = ASI_ERROR_CODE.ASI_SUCCESS;
            Exception      exception      = null;
            Result         result;

            ASI_EXPOSURE_STATUS aSI_EXPOSURE_STATUS = ASI_EXPOSURE_STATUS.ASI_EXP_WORKING;

            try
            {
                asi_error_code = ASIGetExpStatus(CameraID, out aSI_EXPOSURE_STATUS);
            }
            catch (Exception e)
            {
                exception = e;
            }
            result = GetOperationResult("ASIGetExpStatus", asi_error_code, exception, logSuccessResult);

            Status        = result.Code == ErrorCode.OK ? ConvertToCameraStatus(aSI_EXPOSURE_STATUS) : CameraStatus.Unknown;
            captureStatus = Status;

            return(result);
        }
Пример #10
0
        public Result Connect()
        {
            ASI_ERROR_CODE asi_error_code = ASI_ERROR_CODE.ASI_SUCCESS;
            Exception      exception      = null;
            Result         result;

            try
            {
                asi_error_code = ASIOpenCamera(CameraID);
            }
            catch (Exception e)
            {
                exception = e;
            }
            result = GetOperationResult("ASIOpenCamera", asi_error_code, exception);
            if (result.Code != ErrorCode.OK)
            {
                return(result);
            }

            try
            {
                asi_error_code = ASIInitCamera(CameraID);
            }
            catch (Exception e)
            {
                exception = e;
            }
            result = GetOperationResult("ASIInitCamera", asi_error_code, exception);
            if (result.Code != ErrorCode.OK)
            {
                return(result);
            }

            return(InitialControlItems());
        }
Пример #11
0
        public static Result ScanASICameras(List <ICamera> cameraList)
        {
            int            camera_count   = 0;
            ASI_ERROR_CODE asi_error_code = ASI_ERROR_CODE.ASI_SUCCESS;

            try
            {
                camera_count = ASIGetNumOfConnectedCameras();
            }
            catch (Exception e)
            {
                var message = "Failed to ASIGetNumOfConnectedCameras.";
                Log.Error(message, e);
                return(new Result(ErrorCode.OperationFailed, message, e));
            }

            if (camera_count == 0)
            {
                return(new Result("No ASI Camera Found"));
            }

            for (int i = 0; i < camera_count; i++)
            {
                var       cameraID       = i;
                var       pASICameraInfo = new ASI_CAMERA_INFO();
                Exception exception      = null;

                try
                {
                    asi_error_code = ASIGetCameraProperty(out pASICameraInfo, i);
                }
                catch (Exception e)
                {
                    exception = e;
                }
                if (exception != null || asi_error_code != ASI_ERROR_CODE.ASI_SUCCESS)
                {
                    string message = string.Format("Failed to ASIGetCameraProperty for CameraID {0}, ASI_ERROR_CODE {1}", i, asi_error_code.ToString());
                    Log.Error(message, exception);
                    break;
                }

                var cameraInfo = new CameraInfo
                {
                    DisplayName          = pASICameraInfo.Name,
                    SDKType              = CameraSDKType.ASI,
                    IsColorCamera        = pASICameraInfo.IsColorCam == ASI_BOOL.ASI_TRUE,
                    BayerPattern         = GetASIBayerPattern(pASICameraInfo.BayerPattern),
                    SupportBins          = pASICameraInfo.SupportedBins,
                    CanCool              = pASICameraInfo.IsCoolerCam == ASI_BOOL.ASI_TRUE,
                    HasMechanicalShutter = pASICameraInfo.MechanicalShutter == ASI_BOOL.ASI_TRUE,
                    HasST4Port           = pASICameraInfo.ST4Port == ASI_BOOL.ASI_TRUE,
                    IsUSB3Host           = pASICameraInfo.IsUSB3Host == ASI_BOOL.ASI_TRUE,
                    IsUSB3Camera         = pASICameraInfo.IsUSB3Camera == ASI_BOOL.ASI_TRUE,
                    PixelSize            = Convert.ToInt32(pASICameraInfo.PixelSize * 1000),
                    ElecPerADU           = Convert.ToInt32(pASICameraInfo.ElecPerADU * 1000000),
                    MaxHeight            = pASICameraInfo.MaxHeight,
                    MaxWeight            = pASICameraInfo.MaxWidth
                };

                var camera = new ASICamera(cameraID, cameraInfo);
                cameraList.Add(camera);

                Log.InfoFormat("Found ASI Camera {0}, CameraID {1}", cameraInfo.DisplayName, cameraID);
            }

            return(new Result(String.Format("ASI Camera Found, Total Count: {0}", camera_count)));
        }