コード例 #1
0
        //-------------------------------------------------------------------------------------------------//
        public EquipmentEngine(string rootFilePath)
            : base(rootFilePath)
        {
            const string STRLOG_MethodName = "EquipmentEngine";

            Logfile.WriteCalled(null, STRLOG_MethodName);

            int initialiseDelay = 0;
            bool hardwarePresent = true;

            try
            {
                //
                // Determine if hardware is to be used or whether this is running without hardware
                // for testing and debugging
                //
                try
                {
                    hardwarePresent = XmlUtilities.GetBoolValue(this.xmlNodeEquipmentConfig, Consts.STRXML_hardwarePresent, false);
                }
                catch
                {
                    // Key not found or invalid so assume hardware is present
                }

                //
                // Create an instance of the FlexMotion class, must be done before creating the Radiation Counter class
                //
                if (hardwarePresent == true)
                {
                    this.flexMotion = new FlexMotionCntl(this.xmlNodeEquipmentConfig);
                }
                else
                {
                    this.flexMotion = new FlexMotionNone(this.xmlNodeEquipmentConfig);
                }
                initialiseDelay += this.flexMotion.InitialiseDelay;

                //
                // Get the serial LCD communication type
                //
                XmlNode xmlNodeSerialLcd = XmlUtilities.GetXmlNode(this.xmlNodeEquipmentConfig, Consts.STRXML_serialLcd);
                string strSerialLcdCommType = XmlUtilities.GetXmlValue(xmlNodeSerialLcd, Consts.STRXML_type, false);
                this.serialLcdCommType = (CommunicationTypes)Enum.Parse(typeof(CommunicationTypes), strSerialLcdCommType);

                //
                // Create an instance of the SerialLcd class, must be done before creating the Radiation Counter class
                //
                if (hardwarePresent == true)
                {
                    if (this.serialLcdCommType == CommunicationTypes.Network)
                    {
                        this.serialLcdTcp = new SerialLcdTcp(this.xmlNodeEquipmentConfig);
                        this.serialLcd = this.serialLcdTcp;
                    }
                    else if (this.serialLcdCommType == CommunicationTypes.Serial)
                    {
                        this.serialLcdSer = new SerialLcdSer(this.xmlNodeEquipmentConfig);
                        this.serialLcd = this.serialLcdSer;
                    }
                    else if (this.serialLcdCommType == CommunicationTypes.None)
                    {
                        this.serialLcdNone = new SerialLcdNone(this.xmlNodeEquipmentConfig);
                        this.serialLcd = this.serialLcdNone;
                    }
                    else
                    {
                        throw new ArgumentException(STRERR_SerialLcdCommsTypeNotSpecified);
                    }
                }
                else
                {
                    this.serialLcdNone = new SerialLcdNone(this.xmlNodeEquipmentConfig);
                    this.serialLcd = this.serialLcdNone;
                }
                initialiseDelay += this.serialLcd.InitialiseDelay;

                //
                // Get the radiation counter type
                //
                XmlNode xmlNodeRadiationCounter = XmlUtilities.GetXmlNode(this.xmlNodeEquipmentConfig, Consts.STRXML_radiationCounter, false);
                string strCounterType = XmlUtilities.GetXmlValue(xmlNodeRadiationCounter, Consts.STRXML_type, false);
                this.radiationCounterType = (RadiationCounterTypes)Enum.Parse(typeof(RadiationCounterTypes), strCounterType);

                //
                // Create an instance of the radiation counter class
                //
                if (this.radiationCounterType == RadiationCounterTypes.ST360)
                {
                    //
                    // Get the ST360 counter communication type
                    //
                    XmlNode xmlNodeST360Counter = XmlUtilities.GetXmlNode(this.xmlNodeEquipmentConfig, Consts.STRXML_st360Counter);
                    string strST360CounterCommType = XmlUtilities.GetXmlValue(xmlNodeST360Counter, Consts.STRXML_type, false);
                    this.st360CounterCommType = (CommunicationTypes)Enum.Parse(typeof(CommunicationTypes), strST360CounterCommType);

                    //
                    // Create an instance of the ST360 counter class depending on the communication type
                    //
                    if (hardwarePresent == true)
                    {
                        if (this.st360CounterCommType == CommunicationTypes.Network)
                        {
                            this.st360CounterTcp = new ST360CounterTcp(this.xmlNodeEquipmentConfig);
                            this.st360Counter = st360CounterTcp;
                        }
                        else if (this.st360CounterCommType == CommunicationTypes.Serial)
                        {
                            this.st360CounterSer = new ST360CounterSer(this.xmlNodeEquipmentConfig);
                            this.st360Counter = st360CounterSer;
                        }
                        else
                        {
                            throw new ArgumentException(STRERR_ST360CounterCommsTypeNotSpecified);
                        }
                    }
                    else
                    {
                        this.st360CounterNone = new ST360CounterNone(this.xmlNodeEquipmentConfig);
                        this.st360Counter = st360CounterNone;
                    }
                    initialiseDelay += this.st360Counter.InitialiseDelay;
                }
                else if (this.radiationCounterType == RadiationCounterTypes.Physics)
                {
                    if (hardwarePresent == true)
                    {
                        if (this.serialLcdCommType == CommunicationTypes.Network)
                        {
                            this.physicsCounter = new PhysicsCounter(this.xmlNodeEquipmentConfig, this.serialLcdTcp, this.flexMotion);
                        }
                        else if (this.serialLcdCommType == CommunicationTypes.Serial)
                        {
                            this.physicsCounter = new PhysicsCounter(this.xmlNodeEquipmentConfig, this.serialLcdSer, this.flexMotion);
                        }
                        else
                        {
                            throw new ArgumentException(STRERR_SerialLcdCommsTypeNotSpecified);
                        }
                    }
                    else
                    {
                        this.physicsCounter = new PhysicsCounter(this.xmlNodeEquipmentConfig, this.serialLcdNone, this.flexMotion);
                    }
                    initialiseDelay += this.physicsCounter.InitialiseDelay;
                }
                else
                {
                    throw new ArgumentException(STRERR_RadiationCounterTypeNotSpecified);
                }

                //
                // Update the power initialisation delay
                //
                this.powerupInitialiseDelay = initialiseDelay;
                Logfile.Write(STRLOG_InitialiseDelay + initialiseDelay.ToString() + STRLOG_Seconds);
            }
            catch (Exception ex)
            {
                //
                // Log the message and throw the exception back to the caller
                //
                Logfile.WriteError(ex.Message);
                throw;
            }

            Logfile.WriteCompleted(null, STRLOG_MethodName);
        }
コード例 #2
0
        //---------------------------------------------------------------------------------------//
        /// <summary>
        /// Initialise the equipment after it has been powered up.
        /// </summary>
        /// <returns>True if successful.</returns>
        public override bool InitialiseEquipment()
        {
            const string STRLOG_MethodName = "InitialiseEquipment";

            Logfile.WriteCalled(STRLOG_ClassName, STRLOG_MethodName);

            bool success = false;

            try
            {
                //
                // The initialisation delay may change once the equipment has been initialised
                // for the first time, so recalculate it
                //
                int initialiseDelay = 0;

                //
                // Initialise the FlexMotion controller
                //
                if (this.flexMotion.PowerInitialise() == false)
                {
                    throw new Exception(STRERR_FailedToInitialiseFlexMotion);
                }
                initialiseDelay += this.flexMotion.InitialiseDelay;

                //
                // Initialise the SerialLcd
                //
                if (this.serialLcd.Initialise() == false)
                {
                    throw new Exception(STRERR_FailedToInitialiseSerialLcd);
                }
                initialiseDelay += this.serialLcd.InitialiseDelay;

                //
                // Display LabEquipment service title on the Serial LCD
                //
                this.serialLcd.WriteLine(1, this.Title);
                this.serialLcd.WriteLine(2, string.Empty);

                //
                // Initialise the radiation counter class being used
                //
                if (this.radiationCounterType == RadiationCounterTypes.ST360)
                {
                    this.physicsCounter = null;
                    if (this.st360Counter.Initialise(true) == false)
                    {
                        throw new Exception(STRERR_FailedToInitialiseST360Counter);
                    }
                    initialiseDelay += this.st360Counter.InitialiseDelay;
                }
                else if (this.radiationCounterType == RadiationCounterTypes.Physics)
                {
                    this.st360Counter = null;
                    if (this.physicsCounter.Initialise() == false)
                    {
                        throw new Exception(STRERR_FailedToInitialisePhysicsCounter);
                    }
                    initialiseDelay += this.physicsCounter.InitialiseDelay;
                }

                //
                // Update the power initialisation delay for TimeUntilReady()
                //
                this.powerupInitialiseDelay = initialiseDelay;
                Logfile.Write(STRLOG_InitialiseDelay + initialiseDelay.ToString() + STRLOG_Seconds);

                success = true;
            }
            catch (Exception ex)
            {
                Logfile.WriteError(ex.Message);
            }

            string logMessage = STRLOG_Success + success.ToString();

            Logfile.WriteCompleted(STRLOG_ClassName, STRLOG_MethodName, logMessage);

            return success;
        }