/// <summary>
        /// Turns the calibrator on at the specified brightness if the device has calibration capability
        /// </summary>
        /// <param name="Brightness"></param>
        public void CalibratorOn(int Brightness)
        {
            if (calibratorState == CalibratorStatus.NotPresent)
            {
                throw new MethodNotImplementedException("This device has no calibrator capability.");
            }

            if (!IsConnected)
            {
                throw new NotConnectedException("The simulator is not connected, the CalibratorOn method is not available.");
            }

            if ((Brightness < 0) | (Brightness > MaxBrightnessValue))
            {
                throw new InvalidValueException("CalibratorOn", Brightness.ToString(), $"0 to {MaxBrightnessValue}");
            }

            brightnessValue = Brightness;                                       // Set the assigned brightness

            if (CalibratorStablisationTimeValue <= SYNCHRONOUS_BEHAVIOUR_LIMIT) // Synchronous behaviour
            {
                calibratorState = CalibratorStatus.NotReady;
                WaitFor(CalibratorStablisationTimeValue);
                LogVerbose("CalibratorOn", $"Calibrator turned on synchronously in {CalibratorStablisationTimeValue} seconds.");
                calibratorState = CalibratorStatus.Ready;
            }
            else // Asynchronous behaviour
            {
                calibratorState        = CalibratorStatus.NotReady;
                targetCalibratorStatus = CalibratorStatus.Ready;
                calibratorTimer.Start();
                LogVerbose("CalibratorOn", $"Starting asynchronous calibrator turn on for {CalibratorStablisationTimeValue} seconds.");
            }
        }
        /// <summary>
        /// Turns the calibrator off if the device has calibration capability
        /// </summary>
        public void CalibratorOff()
        {
            if (calibratorState == CalibratorStatus.NotPresent)
            {
                throw new MethodNotImplementedException("This device has no calibrator capability.");
            }

            if (!IsConnected)
            {
                throw new NotConnectedException("The simulator is not connected, the CalibratorOff method is not available.");
            }

            brightnessValue = 0;                                                // Set the brightness to zero per the ASCOM specification

            if (CalibratorStablisationTimeValue <= SYNCHRONOUS_BEHAVIOUR_LIMIT) // Synchronous behaviour
            {
                calibratorState = CalibratorStatus.NotReady;
                WaitFor(CalibratorStablisationTimeValue);
                LogVerbose("CalibratorOff", $"Calibrator turned off synchronously in {CalibratorStablisationTimeValue} seconds.");
                calibratorState = CalibratorStatus.Off;
            }
            else // Asynchronous behaviour
            {
                calibratorState        = CalibratorStatus.NotReady;
                targetCalibratorStatus = CalibratorStatus.Off;
                calibratorTimer.Start();
                LogVerbose("CalibratorOff", $"Starting asynchronous calibrator turn off for {CalibratorStablisationTimeValue} seconds.");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Simulator"/> class.
        /// Must be public for COM registration.
        /// </summary>
        public CoverCalibrator()
        {
            try
            {
                // Initialise the driver trace logger
                TL = new TraceLogger("", "CoverCalibratorSimulator");

                // Read device configuration from the ASCOM Profile store, this also sets the trace logger enabled state
                ReadProfile();
                TL.LogMessage("CoverCalibrator", "Starting initialisation");

                // Initialise remaining components
                utilities       = new Util();
                calibratorTimer = new System.Timers.Timer();
                if (CalibratorStablisationTimeValue > 0.0)
                {
                    calibratorTimer.Interval = Convert.ToInt32(CalibratorStablisationTimeValue * 1000.0); // Set the timer interval in milliseconds from the stabilisation time in seconds
                }
                calibratorTimer.Elapsed += CalibratorTimer_Tick;
                TL.LogMessage("CoverCalibrator", $"Set calibrator timer to: {calibratorTimer.Interval}ms.");

                coverTimer = new System.Timers.Timer();
                if (CoverOpeningTimeValue > 0.0)
                {
                    coverTimer.Interval = Convert.ToInt32(CoverOpeningTimeValue * 1000.0); // Set the timer interval in milliseconds from the opening time in seconds
                }
                coverTimer.Elapsed += CoverTimer_Tick;
                TL.LogMessage("CoverCalibrator", $"Set cover timer to: {coverTimer.Interval}ms.");

                // Initialise internal start-up values
                IsConnected     = false;                              // Initialise connected to false
                brightnessValue = 0;                                  // Set calibrator brightness to 0 i.e. off
                coverState      = CoverStateInitialisationValue;      // Set the cover state as set by the user
                calibratorState = CalibratorStateInitialisationValue; // Set the calibration state as set by the user

                TL.LogMessage("CoverCalibrator", "Completed initialisation");
            }
            catch (Exception ex)
            {
                // Create a message to the user
                string message = $"Exception while creating CoverCalibrator simulator: \r\n{ex.ToString()}";

                // Attempt to log the message
                try
                {
                    TL.Enabled = true;
                    TL.LogMessageCrLf("Initialisation", message);
                }
                catch { } // Ignore any errors while attempting to log the error

                // Display the error to the user
                MessageBox.Show(message, "ASCOM CoverCalibrator Simulator Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); // Display the message top the user
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Read the device configuration from the ASCOM Profile store
        /// </summary>
        internal void ReadProfile()
        {
            var temp = Profile.GetValue(TRACE_STATE_PROFILE_NAME, TRACE_STATE_DEFAULT.ToString());

            MaxBrightnessValue = Convert.ToInt32(Profile.GetValue(MAX_BRIGHTNESS_PROFILE_NAME, MAX_BRIGHTNESS_DEFAULT));
            CalibratorStablisationTimeValue = Convert.ToDouble(Profile.GetValue(CALIBRATOR_STABILISATION_TIME_PROFILE_NAME, CALIBRATOR_STABLISATION_TIME_DEFAULT.ToString()));
            if (!Enum.TryParse <CalibratorStatus>(Profile.GetValue(CALIBRATOR_INITIALISATION_STATE_PROFILE_NAME, CALIBRATOR_INITIALISATION_STATE_DEFAULT.ToString()), out CalibratorStateInitialisationValue))
            {
                CalibratorStateInitialisationValue = CALIBRATOR_INITIALISATION_STATE_DEFAULT;
            }
            CoverOpeningTimeValue = Convert.ToDouble(Profile.GetValue(COVER_OPENING_TIME_PROFILE_NAME, COVER_OPENING_TIME_DEFAULT.ToString()));
            if (!Enum.TryParse <CoverStatus>(Profile.GetValue(COVER_INITIALISATION_STATE_PROFILE_NAME, COVER_INITIALISATION_STATE_DEFAULT.ToString()), out CoverStateInitialisationValue))
            {
                CoverStateInitialisationValue = COVER_INITIALISATION_STATE_DEFAULT;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Read the device configuration from the ASCOM Profile store
        /// </summary>
        internal void ReadProfile()
        {
            using (Profile driverProfile = new Profile())
            {
                driverProfile.DeviceType = "CoverCalibrator";

                TL.Enabled         = Convert.ToBoolean(driverProfile.GetValue(DRIVER_PROGID, TRACE_STATE_PROFILE_NAME, string.Empty, TRACE_STATE_DEFAULT.ToString()));
                MaxBrightnessValue = Convert.ToInt32(driverProfile.GetValue(DRIVER_PROGID, MAX_BRIGHTNESS_PROFILE_NAME, string.Empty, MAX_BRIGHTNESS_DEFAULT));
                CalibratorStablisationTimeValue = Convert.ToDouble(driverProfile.GetValue(DRIVER_PROGID, CALIBRATOR_STABILISATION_TIME_PROFILE_NAME, string.Empty, CALIBRATOR_STABLISATION_TIME_DEFAULT.ToString()));
                if (!Enum.TryParse <CalibratorStatus>(driverProfile.GetValue(DRIVER_PROGID, CALIBRATOR_INITIALISATION_STATE_PROFILE_NAME, string.Empty, CALIBRATOR_INITIALISATION_STATE_DEFAULT.ToString()), out CalibratorStateInitialisationValue))
                {
                    CalibratorStateInitialisationValue = CALIBRATOR_INITIALISATION_STATE_DEFAULT;
                }
                CoverOpeningTimeValue = Convert.ToDouble(driverProfile.GetValue(DRIVER_PROGID, COVER_OPENING_TIME_PROFILE_NAME, string.Empty, COVER_OPENING_TIME_DEFAULT.ToString()));
                if (!Enum.TryParse <CoverStatus>(driverProfile.GetValue(DRIVER_PROGID, COVER_INITIALISATION_STATE_PROFILE_NAME, string.Empty, COVER_INITIALISATION_STATE_DEFAULT.ToString()), out CoverStateInitialisationValue))
                {
                    CoverStateInitialisationValue = COVER_INITIALISATION_STATE_DEFAULT;
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Simulator"/> class.
        /// </summary>
        /// <param name="deviceNumber">The instance number of this driver. If there is only one this should be 0</param>
        /// <param name="logger">The logger instance to use</param>
        /// <param name="profile">A profile to store settings</param>
        public CoverCalibratorSimulator(int deviceNumber, ILogger logger, IProfile profile)
        {
            try
            {
                DeviceNumber = deviceNumber;

                // Initialise the driver trace logger
                TL      = logger;
                Profile = profile;

                // Read device configuration from the ASCOM Profile store, this also sets the trace logger enabled state
                ReadProfile();
                TL.LogInformation($"CoverCalibrator {deviceNumber} - Starting initialisation");

                //This should be replaced by the next bit of code but is semi-unique as a default.
                UniqueID = DRIVER_DESCRIPTION + deviceNumber.ToString();
                //Create a Unique ID if it does not exist
                try
                {
                    if (!profile.ContainsKey(UNIQUE_ID_PROFILE_NAME))
                    {
                        var uniqueid = Guid.NewGuid().ToString();
                        profile.WriteValue(UNIQUE_ID_PROFILE_NAME, uniqueid);
                    }
                    UniqueID = profile.GetValue(UNIQUE_ID_PROFILE_NAME);
                }
                catch (Exception ex)
                {
                    TL.LogError($"CoverCalibrator {deviceNumber} - {ex.Message}");
                }

                TL.LogInformation($"CoverCalibrator {deviceNumber} - UUID of {UniqueID}");

                // Initialise remaining components
                calibratorTimer = new System.Timers.Timer();
                if (CalibratorStablisationTimeValue > 0.0)
                {
                    calibratorTimer.Interval = Convert.ToInt32(CalibratorStablisationTimeValue * 1000.0); // Set the timer interval in milliseconds from the stabilisation time in seconds
                }
                calibratorTimer.Elapsed += CalibratorTimer_Tick;
                TL.LogInformation($"CoverCalibrator {deviceNumber} - Set calibrator timer to: {calibratorTimer.Interval}ms.");

                coverTimer = new System.Timers.Timer();
                if (CoverOpeningTimeValue > 0.0)
                {
                    coverTimer.Interval = Convert.ToInt32(CoverOpeningTimeValue * 1000.0); // Set the timer interval in milliseconds from the opening time in seconds
                }
                coverTimer.Elapsed += CoverTimer_Tick;
                TL.LogInformation($"CoverCalibrator {deviceNumber} - Set cover timer to: {coverTimer.Interval}ms.");

                // Initialise internal start-up values
                IsConnected     = false;                              // Initialise connected to false
                brightnessValue = 0;                                  // Set calibrator brightness to 0 i.e. off
                coverState      = CoverStateInitialisationValue;      // Set the cover state as set by the user
                calibratorState = CalibratorStateInitialisationValue; // Set the calibration state as set by the user

                TL.LogInformation($"CoverCalibrator {deviceNumber} - Completed initialisation");
            }
            catch (Exception ex)
            {
                // Create a message to the user
                string message = $"Exception while creating CoverCalibrator simulator: \r\n{ex.Message}";

                // Attempt to log the message
                try
                {
                    TL.LogInformation($"CoverCalibrator {deviceNumber} - {message}");
                }
                catch { } // Ignore any errors while attempting to log the error

                // Display the error to the user
            }
        }
 private void CalibratorTimer_Tick(object sender, EventArgs e)
 {
     calibratorState = targetCalibratorStatus;
     calibratorTimer.Stop();
     TL.LogVerbose($"CoverCalibrator {DeviceNumber} - End of cover asynchronous event - cover state is now: {coverState}.");
 }
Exemplo n.º 8
0
 private void CalibratorTimer_Tick(object sender, EventArgs e)
 {
     calibratorState = targetCalibratorStatus;
     calibratorTimer.Stop();
     TL.LogMessage("OpenCover", $"End of cover asynchronous event - cover state is now: {coverState}.");
 }