示例#1
0
        //
        // PUBLIC COM INTERFACE ISafetyMonitor IMPLEMENTATION
        //

        /// <summary>
        /// Initializes a new instance of the <see cref="SafetyMonitor"/> class.
        /// Must be public for COM registration.
        /// </summary>
        public SafetyMonitor(int deviceNumber, ILogger logger, IProfile profile)
        {
            Profile = profile;
            Logger  = logger;

            DeviceNumber = deviceNumber;

            if (CheckSafetyMonitorKeyValue())
            {
                GetProfileSetting();
            }

            //This should be replaced by the next bit of code but is semi-unique as a default.
            UniqueID = Name + 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)
            {
                logger.LogError($"SafetyMonitor {deviceNumber} - {ex.Message}");
            }

            logger.LogInformation($"SafetyMonitor {deviceNumber} - UUID of {UniqueID}");
        }
        //
        // Constructor - Must be public for COM registration!
        //
        public Rotator(int deviceNumber, ILogger logger, IProfile profile)
        {
            try
            {
                RotatorHardware.Initialize(profile);

                DeviceNumber = deviceNumber;

                //This should be replaced by the next bit of code but is semi-unique as a default.
                UniqueID = Name + 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)
                {
                    logger.LogError($"Rotator {deviceNumber} - {ex.Message}");
                }

                logger.LogInformation($"Rotator {deviceNumber} - UUID of {UniqueID}");
            }

            catch (Exception ex)
            {
                logger.LogError(ex.Message.ToString());
                throw ex;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Simulator"/> class.
        /// Must be public for COM registration.
        /// </summary>
        public Switch(int deviceNumber, ILogger logger, IProfile profile)
        {
            tl      = logger;
            Profile = profile;

            ReadProfile(); // Read device configuration from the ASCOM Profile store

            LogMessage($"New Switch {deviceNumber}", "Starting initialisation");

            DeviceNumber = deviceNumber;

            connectedState = false; // Initialise connected to false
                                    //TODO: Implement your additional construction here

            //This should be replaced by the next bit of code but is semi-unique as a default.
            UniqueID = Name + 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)
            {
                logger.LogError($"Switch {deviceNumber} - {ex.Message}");
            }

            logger.LogInformation($"Switch {deviceNumber} - UUID of {UniqueID}");

            LogMessage("Switch", "Completed initialisation");
        }
        public Dome(int deviceNumber, ILogger logger, IProfile profile)
        {
            Logger  = logger;
            Profile = profile;

            LogMessage($"New dome {deviceNumber}", "Log started");

            DeviceNumber = deviceNumber;

            //This should be replaced by the next bit of code but is semi-unique as a default.
            UniqueID = Name + 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)
            {
                logger.LogError($"Dome {deviceNumber} - {ex.Message}");
            }

            logger.LogInformation($"Dome {deviceNumber} - UUID of {UniqueID}");

            LoadConfig();

            LogMessage("New", "Starting thread");

            LogMessage("New", "New completed OK");
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Focuser"/> class.
        /// Must be public for COM registration.
        /// </summary>
        public Focuser(int deviceNumber, ILogger logger, IProfile profile)
        {
            try
            {
                TL      = logger;
                Profile = profile;
                LogMessage($"New Focuser {deviceNumber}", "Started");

                DeviceNumber = deviceNumber;

                //check to see if the profile is ok

                LogMessage("New", "Validated OK");
                KeepMoving      = false;
                LastOffset      = 0;
                RateOfChange    = 1;
                MouseDownTime   = DateTime.MaxValue; //Initialise to "don't accelerate" value
                RandomGenerator = new Random();      //Temperature fluctuation random generator
                LoadFocuserKeyValues();
                LogMessage("New", "Loaded Key Values");
                LogMessage("FocusSettingsForm", "Created Handbox");

                // start a timer that monitors and moves the focuser
                _moveTimer          = new System.Timers.Timer();
                _moveTimer.Elapsed += new System.Timers.ElapsedEventHandler(MoveTimer_Tick);
                _moveTimer.Interval = 100;
                _moveTimer.Enabled  = true;
                _lastTemp           = Temperature;
                Target = _position;

                LogMessage("New", "Started Simulation");

                //This should be replaced by the next bit of code but is semi-unique as a default.
                UniqueID = Name + 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)
                {
                    logger.LogError($"Focuser {deviceNumber} - {ex.Message}");
                }

                logger.LogInformation($"Focuser {deviceNumber} - UUID of {UniqueID}");

                LogMessage("New", "Completed");
            }
            catch (Exception ex)
            {
                TL.LogError(ex.Message.ToString());
                throw ex;
            }
        }
示例#6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OCSimulator"/> class.
        /// Must be public for COM registration.
        /// </summary>
        public ObservingConditions(int deviceNumber, ILogger logger, IProfile profile)
        {
            try
            {
                OCSimulator.driverProfile = profile;
                OCSimulator.TL            = logger;
                OCSimulator.Init();
                TL = logger;

                DeviceNumber = deviceNumber;

                OCSimulator.LogMessage($"New ObservingConditions {deviceNumber}", "Starting initialisation");

                // This should be replaced by the next bit of code but is semi - unique as a default.
                UniqueID = Name + 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)
                {
                    logger.LogError($"ObservingConditions {deviceNumber} - {ex.Message}");
                }

                logger.LogInformation($"ObservingConditions {deviceNumber} - UUID of {UniqueID}");

                OCSimulator.LogMessage("ObservingConditions", "Completed initialisation");
            }
            catch (Exception ex)
            {
                OCSimulator.LogMessage("ObservingConditions", ex.ToString());
            }
        }
        /// <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
            }
        }