Beispiel #1
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());
            }
        }
Beispiel #2
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)
            {
                throw ex;
                //MessageBox.Show(ex.ToString(), "Error initialising the Observing Conditions Simulator", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #3
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;
                    }
                }
            }
        }