Пример #1
0
 public string Action(string actionName, string actionParameters)
 {
     if (actionName.ToUpperInvariant() == "SETTESTMODE")
     {
         testMode = true;
         TL.LogMessage(clientNumber, "Action", "SETTESTMODE received: Test mode now active");
         return("Test mode active");
     }
     return(Hub.Action(clientNumber, actionName, actionParameters));
 }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OCSimulator"/> class.
        /// Must be public for COM registration.
        /// </summary>
        public ObservingConditions()
        {
            try
            {
                TL = OCSimulator.TL;
                TL.LogMessage("ObservingConditions", "Starting initialisation");

                clientNumber = OCSimulator.GetUniqueClientNumber();
                TL.LogMessage(clientNumber, "ObservingConditions", "This instance's unique client number: " + clientNumber);

                TL.LogMessage(clientNumber, "ObservingConditions", "Completed initialisation");
            }
            catch (Exception ex)
            {
                TL.LogMessageCrLf("ObservingConditions", ex.ToString());
            }
        }
Пример #3
0
        private void ChkEnabled_CheckedChanged(object sender, EventArgs e)
        {
            if (!DesignMode)
            {
                CheckBox chk = (CheckBox)sender;
                if (OCSimulator.setupForm != null)
                {
                    SensorView svThisSensor = (SensorView)OCSimulator.setupForm.Controls[this.Name];

                    TL.LogMessage("ChkEnabled_CheckedChanged", "Checked changed: " + chk.Name + " " + this.Name);
                    svThisSensor.NotReadyControlsEnabled = chk.Checked;
                }
                else
                {
                    TL.LogMessage("ChkEnabled_CheckedChanged", "setupForm variable is null!");
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Static initialiser to set up the objects we need at run time
        /// </summary>
        static OCSimulator()
        {
            try
            {
                // Create sensor objects ready to be populated from the Profile
                // This must be done before reading the Profile
                foreach (string Property in DriverProperties)
                {
                    Sensors.Add(Property, new Sensor(Property));
                }

                TL = new TraceLoggerPlus("", "OCSimulator"); // Trace state is set in ReadProfile, immediately after nbeing read fomr the Profile
                ReadProfile();                               // Read device configuration from the ASCOM Profile store

                TL.LogMessage("OCSimulator", "Simulator initialising");
                sensorQueryTimer            = new System.Timers.Timer();
                sensorQueryTimer.Elapsed   += RefreshTimer_Elapsed;
                averagePeriodTimer          = new System.Timers.Timer();
                averagePeriodTimer.Elapsed += AveragePeriodTimer_Elapsed;

                connectStates        = new ConcurrentDictionary <long, bool>();
                util                 = new Util(); // Create an  ASCOM Utilities object
                mostRecentUpdateTime = DateTime.Now;

                TL.LogMessage("OCSimulator", "Setting sensor initial values");
                foreach (string Property in SimulatedProperties)
                {
                    Sensors[Property].SimCurrentValue     = Sensors[Property].SimFromValue;
                    Sensors[Property].ValueCycleDirection = ValueCycleDirections.FromTowardsTo;
                    Sensors[Property].TimeOfLastUpdate    = DateTime.Now;
                }

                // Dew point is calculated from humidity so initialise that here
                Sensors[PROPERTY_DEWPOINT].IsImplemented    = Sensors[PROPERTY_HUMIDITY].IsImplemented;
                Sensors[PROPERTY_DEWPOINT].SimCurrentValue  = util.Humidity2DewPoint(Sensors[PROPERTY_HUMIDITY].SimCurrentValue, Sensors[PROPERTY_TEMPERATURE].SimCurrentValue);
                Sensors[PROPERTY_DEWPOINT].TimeOfLastUpdate = DateTime.Now;

                TL.LogMessage("OCSimulator", "Simulator initialisation complete.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error initialising the Observing Conditions Simulator", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #5
0
 public SensorView()
 {
     InitializeComponent();
     if (!DesignMode)
     {
         TL = OCSimulator.TL;
         TL.LogMessage("SensorView", "This.Name: " + this.Name);
         chkEnabled.CheckedChanged += ChkEnabled_CheckedChanged;
     }
 }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Hub"/> class.
        /// Must be public for COM registration.
        /// </summary>
        public ObservingConditions()
        {
            try
            {
                TL = Hub.TL;
                TL.LogMessage("ObservingConditions", "Starting initialisation");

                clientNumber = Hub.GetUniqueClientNumber();
                TL.LogMessage(clientNumber, "ObservingConditions", "This instance's unique client number: " + clientNumber);

                testMode      = false;
                testConnected = false;
                TL.LogMessage(clientNumber, "ObservingConditions", "Completed initialisation");
            }
            catch (Exception ex)
            {
                TL.LogMessageCrLf("ObservingConditions", ex.ToString());
            }
        }
Пример #7
0
        public static void Connect(int clientNumber)
        {
            if (DebugTraceState)
            {
                TL.LogMessage(clientNumber, "Connect", "Acquiring connection lock");
            }
            lock (connectLockObject) // Esnure that only one connection attempt can happen at a time
            {
                TL.LogMessage(clientNumber, "Connect", "Has connection lock");
                if (IsClientConnected(clientNumber)) // If we are already connected then just log this
                {
                    TL.LogMessage(clientNumber, "Connect", "Already connected, just incrementing connection count.");
                }
                else // We are not connected so connect now
                {
                    try
                    {
                        TL.LogMessage(clientNumber, "Connect", "Attempting to connect to devices");
                        bool notAlreadyPresent = connectStates.TryAdd(clientNumber, true);
                        TL.LogMessage(clientNumber, "Connect", "Successfully connected, AlreadyConnected: " + (!notAlreadyPresent).ToString() + ", number of connections: " + connectStates.Count);
                        if (ConnectionCount == 1) // This is the first successful connection
                        {
                            TL.LogMessage(clientNumber, "Connect", "This is the first connection so set the connection start time");
                            initialConnectionTime = DateTime.Now;
                            foreach (string property in SimulatedProperties)
                            {
                                Sensors[property].ValueCycleDirection = ValueCycleDirections.FromTowardsTo;
                                Sensors[property].SimCurrentValue     = Sensors[property].SimFromValue;
                                Sensors[property].TimeOfLastUpdate    = initialConnectionTime;
                            }

                            // Dew point is calculated from humidity so initialise that here
                            Sensors[PROPERTY_DEWPOINT].SimCurrentValue  = util.Humidity2DewPoint(Sensors[PROPERTY_HUMIDITY].SimCurrentValue, Sensors[PROPERTY_TEMPERATURE].SimCurrentValue);
                            Sensors[PROPERTY_DEWPOINT].TimeOfLastUpdate = initialConnectionTime;
                            mostRecentUpdateTime = initialConnectionTime;

                            sensorQueryTimer.Interval = SensorQueryInterval * 1000.0;
                            sensorQueryTimer.Enabled  = true;
                            ConfigureAveragePeriodTimer();
                        }
                    }
                    catch (Exception ex)
                    {
                        TL.LogMessageCrLf(clientNumber, "Connect", "Exception: " + ex.ToString());
                        throw;
                    }
                }
            }
        }
Пример #8
0
 private void chkConnectToDrivers_CheckedChanged(object sender, EventArgs e)
 {
     TL.LogMessage("ConnectToDrivers", "Event fired");
     ReadDeviceInformation();
 }