/// <summary>
        /// Determines which ports have pressure switches and which do not.
        /// For those that do, it reads current pressure state (good/bad).
        /// </summary>
        private void CheckPressureSwitches()
        {
            // Reset these member booleans to false on every call.
            for (int i = 0; i < _checkedSwitchIsPresent.Length; i++)
            {
                _checkedSwitchIsPresent[i] = _checkedIsPressureGood[i] = false;
            }

            for (int i = 0; i < _checkedSwitchIsPresent.Length; i++)
            {
                _checkedSwitchIsPresent[i] = SmartCardManager.IsPressureSwitchPresent(i + 1);

                if (_wasSwitchPresent[i] != _checkedSwitchIsPresent[i])
                {
                    Thread.Sleep(500);
                    // Try again.
                    _checkedSwitchIsPresent[i] = SmartCardManager.IsPressureSwitchPresent(i + 1);
                }
                else if (_checkedSwitchIsPresent[i])   // If pressure switch is still present since last check, we need to then re-check the pressure.
                {
                    // Check the pressure.
                    // Save the state for setting later to avoid synchronization issues.
                    _checkedIsPressureGood[i] = SmartCardManager.CheckPressureSwitch(i + 1);
                    if (_wasPressureGood[i] != _checkedIsPressureGood[i])
                    {
                        Thread.Sleep(500);
                        // Try again.
                        _checkedIsPressureGood[i] = SmartCardManager.CheckPressureSwitch(i + 1);
                    }
                }
            }
        }
        /// <summary>
        /// If pressure switch is present, then this methods reads the pressure level from it,
        /// otherwise this method returns Full.
        /// </summary>
        /// <param name="position"></param>
        /// <returns></returns>
        static private PressureLevel ReadPressureLevel(int position)
        {
            const string funcName = "ReadPressureLevel";

            if (!SmartCardManager.IsPressureSwitchPresent(position))
            {
                Log.Debug(funcName + ": Cylinder " + position + " has no pressure switch. Defaulting to Full");
                return(PressureLevel.Full);
            }

            if (SmartCardManager.CheckPressureSwitch(position))
            {
                Log.Debug(funcName + ": Cylinder " + position + " pressure is Full");
                return(PressureLevel.Full);
            }

            Log.Debug(funcName + ": Cylinder " + position + " pressure is Low");
            return(PressureLevel.Low);
        }
        /// <summary>
        /// Return the information from all smart cards, manifolds and manual cylinders that are present at start-up.
        /// </summary>
        /// <param name="installedCylinders">Information about the cylinders is placed into this passed-in list.</param>
        static private void ReadInstalledCylinders(List <GasEndPoint> gasEndPoints, PortRestrictions port1Restrictions)
        {
            const string funcName = "ReadInstalledCylinders: ";

            // Get all currently attached manifolds and manually-assigned cylinders.
            List <GasEndPoint> manGasEndPoints
                = new GasEndPointDataAccess().FindAll().FindAll(m => m.InstallationType == GasEndPoint.Type.Manifold ||
                                                                m.InstallationType == GasEndPoint.Type.Manual);

            for (int position = 1; position <= Configuration.DockingStation.NumGasPorts; position++)
            {
                Log.Debug(funcName + "POSITION " + position);

                // iGas cylinders take precendence
                if (!SmartCardManager.IsCardPresent(position))
                {
                    Log.Debug(string.Format("{0}Position {1}, No iGas card detected.", funcName, position));

                    // Does the port have a manifold or manual cylinder attached?  Then make sure we include
                    // that cylinder in the returned list. If no cylinder exists on port 1, then create a
                    // virtual fresh air cylinder.
                    GasEndPoint man = manGasEndPoints.Find(m => m.Position == position);
                    if (man != null)
                    {
                        Log.Debug(string.Format("{0}Position {1} {2} found (\"{3}\", \"{4}\", Pressure {5}).", funcName, position,
                                                man.InstallationType == GasEndPoint.Type.Manifold ? "Manifold" : "Manual Cylinder",
                                                man.Cylinder.FactoryId, man.Cylinder.PartNumber, man.Cylinder.Pressure));
                        gasEndPoints.Add(man);
                    }
                    else if (position == Controller.FRESH_AIR_GAS_PORT)
                    {
                        Log.Debug(string.Format("{0}Position {1} is assumed to be Fresh Air.", funcName, position));
                        GasEndPoint freshAirEndPoint = GasEndPoint.CreateFreshAir(position);
                        freshAirEndPoint.GasChangeType = GasEndPoint.ChangeType.Installed;
                        gasEndPoints.Add(freshAirEndPoint);
                    }
                    continue;
                }

                // IF WE MAKE IT TO HERE, THEN WE KNOW WE HAVE AN INSERTED SMART CARD WHICH MEANS iGas IS ATTACHED.

                Cylinder cylinder = SmartCardManager.ReadCard(position);
                if (cylinder == null)   // Check for a valid cylinder.
                {
                    Log.Debug(string.Format("{0}Position {1}, ReadCard returned null. SKIPPING cylinder.", funcName, position));
                    continue;
                }

                // Dates read from card will be in 'local' time, but everything we deal with is in UTC.
                cylinder.ExpirationDate = Configuration.ToUniversalTime(cylinder.ExpirationDate);
                cylinder.RefillDate     = Configuration.ToUniversalTime(cylinder.RefillDate);

                Thread.Sleep(1000);

                if (SmartCardManager.IsPressureSwitchPresent(position))
                {
                    if (SmartCardManager.CheckPressureSwitch(position))
                    {
                        cylinder.Pressure = PressureLevel.Full;
                    }
                    else
                    {
                        cylinder.Pressure = PressureLevel.Low;
                    }

                    Log.Debug(string.Format("{0}Position {1} Pressure Switch reports {2}.", funcName, position, cylinder.Pressure));
                }
                else
                {
                    Log.Debug(string.Format("{0}Position {1} Pressure Switch not detected.", funcName, position));
                }

                GasEndPoint gasEndPoint = new GasEndPoint(cylinder, position, GasEndPoint.Type.iGas);

                // Add the installed cylinder to the DockingStation (IDS).
                gasEndPoints.Add(gasEndPoint);
            }

            return;
        }