Beispiel #1
0
        public CSharpControl()
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            // Initialize timer to get Signal changes
            tmrSignals = new System.Windows.Forms.Timer(components);
            if (tmrSignals != null)
            {
                tmrSignals.Enabled = true;
                tmrSignals.Tick   += new System.EventHandler(tmrSignals_Tick);
            }

            // Initialize types
            App         = new CANoe.Application();
            Measurement = (CANoe.Measurement)App.Measurement;
            CANoe.System system = (CANoe.System)App.System;

            if (system != null)
            {
                CANoe.Namespaces namespaces = (CANoe.Namespaces)system.Namespaces;
                if (namespaces != null)
                {
                    CANoe.Namespace nsEngine = (CANoe.Namespace)namespaces["Engine"];
                    if (nsEngine != null)
                    {
                        CANoe.Variables engineVars = (CANoe.Variables)nsEngine.Variables;
                        if (engineVars != null)
                        {
                            svMotorSwitch      = (CANoe.Variable)engineVars["MotorSwitch"];
                            svEngineSpeedEntry = (CANoe.Variable)engineVars["EngineSpeedEntry"];

                            if (svMotorSwitch != null)
                            {
                                svMotorSwitch.OnChange += new CANoe._IVariableEvents_OnChangeEventHandler(svMotorSwitch_OnChange);
                            }
                            if (svEngineSpeedEntry != null)
                            {
                                svEngineSpeedEntry.OnChange += new CANoe._IVariableEvents_OnChangeEventHandler(svEngineSpeedEntry_OnChange);
                            }
                        }
                    }
                    CANoe.Namespace nsLights = (CANoe.Namespace)namespaces["Lights"];
                    if (nsLights != null)
                    {
                        CANoe.Variables lightsVars = (CANoe.Variables)nsLights.Variables;
                        if (lightsVars != null)
                        {
                            svTurnSignal = (CANoe.Variable)lightsVars["TurnSignal"];

                            if (svTurnSignal != null)
                            {
                                svTurnSignal.OnChange += new CANoe._IVariableEvents_OnChangeEventHandler(svTurnSignal_OnChange);
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Occurs when a configuration was successfully opened.
        /// </summary>
        private void ConfigurationOpened()
        {
            try
            {
                // Assign system variables from namespaces.
                CANoe.System     CANoeSystem           = (CANoe.System)mCANoeApp.System;
                CANoe.Namespaces CANoeNamespaces       = (CANoe.Namespaces)CANoeSystem.Namespaces;
                CANoe.Namespace  CANoeNamespaceGeneral = (CANoe.Namespace)CANoeNamespaces["General"];
                CANoe.Variables  CANoeVariablesGeneral = (CANoe.Variables)CANoeNamespaceGeneral.Variables;
                mCANoeSysVar1 = (CANoe.Variable)CANoeVariablesGeneral["SysVar1"];
                mCANoeSysVar2 = (CANoe.Variable)CANoeVariablesGeneral["SysVar2"];

                // Assign signals.
                CANoe.Bus CANoeBus = (CANoe.Bus)mCANoeApp.get_Bus("CAN");
                mCANoeEngineStatus = (CANoe.Signal)CANoeBus.GetSignal(1, "EngineData", "EngineStatus");
                mCANoeEngineSpeed  = (CANoe.Signal)CANoeBus.GetSignal(1, "EngineData", "EngineSpeed");
                mCANoeEngineTemp   = (CANoe.Signal)CANoeBus.GetSignal(1, "EngineData", "EngineTemp");
            }
            catch (System.Exception)
            {
                MessageBox.Show("Possible cause: Wrong namespace names, bus name, system variable names or signal names in source code or configuration.",
                                "Error while assigning system variables and signals", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            // Enables the start/stop measurement button.
            mGroupboxConfigSettings.Enabled     = false;
            mGroupboxMeasurementControl.Enabled = true;

            mButtonStartStop.Focus();

            if (mCANoeApp != null)
            {
                // Wire OnQuit event handler.
                mCANoeApp.OnQuit += new CANoe._IApplicationEvents_OnQuitEventHandler(CANoeQuit);
            }

            if (mCANoeMeasurement != null)
            {
                // Create on event handlers.
                mCANoeMeasurement.OnInit += new CANoe._IMeasurementEvents_OnInitEventHandler(MeasurementInitiated);
                mCANoeMeasurement.OnExit += new CANoe._IMeasurementEvents_OnExitEventHandler(MeasurementExited);
            }

            // Indicate that an instance of CANoe is running.
            mCANoeInstanceRunning = true;
        }