/// <summary>
 /// Occurs when the user clicks the button to start or stop a measurement.
 /// </summary>
 private void mButtonStartStop_Click(object sender, EventArgs e)
 {
     if (mCANoeMeasurement != null)
     {
         if (mCANoeMeasurement.Running)
         {
             mCANoeMeasurement.Stop();
         }
         else
         {
             mCANoeMeasurement.Start();
         }
     }
 }
 /// <summary>
 /// Stop measurement in CANoe
 /// </summary>
 public void StopMeasurement()
 {
     if (mMeasurement.Running)
     {
         mMeasurement.Stop();
     }
 }
        /// <summary>
        ///  Occurs when the user clicks the button to open the configuration.
        /// </summary>
        private void mButtonOpenConfiguration_Click(object sender, EventArgs e)
        {
            // Init new CANoe application.
            mCANoeApp = new CANoe.Application();

            // Init measurement object.
            mCANoeMeasurement = (CANoe.Measurement)mCANoeApp.Measurement;

            // Stopps a running measurement.
            if (mCANoeMeasurement.Running)
            {
                mCANoeMeasurement.Stop();
            }

            if (mCANoeApp != null)
            {
                // Open the demo configuration.
                mCANoeApp.Open(mAbsoluteConfigPath, true, true);

                // Make sure the configuration was successfully loaded.
                CANoe.OpenConfigurationResult ocresult = mCANoeApp.Configuration.OpenConfigurationResult;
                if (ocresult.result == 0)
                {
                    ConfigurationOpened();
                }
            }
        }
Пример #4
0
        /// <summary>
        /// 启动CANoe软件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuCanoeStart_Click(object sender, EventArgs e)
        {
            if (_canoeFilePath == null)
            {
                MessageBox.Show("请先导入正确的CANoe工程文件路径!","CANoe启动失败",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            }
            else
            {

                // Init new CANoe application.
                mCANoeApp = new CANoe.Application();

                // Init measurement object.
                mCANoeMeasurement = mCANoeApp.Measurement;

                // Stopps a running measurement.
                if (mCANoeMeasurement.Running)
                {
                    mCANoeMeasurement.Stop();
                }

                if (mCANoeApp != null)
                {

                    // Open the demo configuration.
                    mCANoeApp.Open(_canoeFilePath, true, true);

                    // Make sure the configuration was successfully loaded.
                    CANoe.OpenConfigurationResult ocresult = mCANoeApp.Configuration.OpenConfigurationResult;
                    if (ocresult.result == 0)
                    {
                        ConfigurationOpened();
                    }
                }
            }
        }
Пример #5
0
        void StartIdentificationRun()
        {
            if (GetTargetString() == "")
            {
                mTB_Status.Text      = "Select Targets first!";
                mTB_Status.BackColor = Color.LightSalmon;
                return;
            }

            if (PathToSourceNode() == "")
            {
                mTB_Status.Text      = "Cannot find CAPL program that performs identification!";
                mTB_Status.BackColor = Color.Red;
                return;
            }

            AddStatusText("Configuring CANoe and trying to start the variant identification ...");
            mTB_Status.BackColor = Color.LightGray;

            const string csNSDiagIdentifier = "DiagIdentifier";
            const string csVarResult        = "ResultOfIdentification";
            const string csVarTarget        = "Target";
            const string csNodeName         = "_TEMP_VarIdent_V1.0";

            // Prepare connection to application
            CANoe.Application app                = new CANoe.Application();
            CANoe.Namespaces  spaces             = (CANoe.Namespaces)((CANoe.System)app.System).Namespaces;
            CANoe.Variables   varsDiagIdentifier = null;

            // Check if namespace and/or variables have been defined already
            bool bCreateNamespace    = true;
            bool bCreateSysVarResult = true;
            bool bCreateSysVarTarget = true;

            foreach (CANoe.Namespace ns in spaces)
            {
                if (ns.Name == csNSDiagIdentifier)
                {
                    varsDiagIdentifier = (CANoe.Variables)ns.Variables;
                    bCreateNamespace   = false;
                    foreach (CANoe.Variable var in varsDiagIdentifier)
                    {
                        if (var.Name == csVarResult)
                        {
                            mSysVarResult       = var;
                            bCreateSysVarResult = false;
                        }
                        else if (var.Name == csVarTarget)
                        {
                            mSysVarTarget       = var;
                            bCreateSysVarTarget = false;
                        }
                    }
                    break;
                }
            }

            // Create namespace and variables, if necessary
            AddStatusText("Creating namespace and system variables");
            if (bCreateNamespace)
            {
                varsDiagIdentifier = (CANoe.Variables)spaces.Add(csNSDiagIdentifier).Variables;
            }

            if (bCreateSysVarResult)
            {
                mSysVarResult = (CANoe.Variable)varsDiagIdentifier.AddWriteable(csVarResult, "");
            }
            if (bCreateSysVarTarget)
            {
                mSysVarTarget = (CANoe.Variable)varsDiagIdentifier.AddWriteable(csVarTarget, "");
            }

            if (mSysVarResult == null || mSysVarTarget == null)
            {
                AddStatusText("Cannot attach to system variables needed for control!");
                mTB_Status.BackColor = Color.Red;
                return;
            }

            // Add the simulation node that communicates with this program an initiates the variant identification to the setup
            AddStatusText("Adding and configuring simulation node");
            CANoe.Configuration   config   = (CANoe.Configuration)app.Configuration;
            CANoe.SimulationSetup simSetup = (CANoe.SimulationSetup)config.SimulationSetup;
            CANoe.Buses           buses    = (CANoe.Buses)simSetup.Buses;

            if (buses.Count < 1)
            {
                AddStatusText("There is no bus configure to attach the simulation node to!");
                mTB_Status.BackColor = Color.Red;
                return;
            }

            CANoe.Bus bus = (CANoe.Bus)buses[1];
            mTB_Status.Text += " to bus " + bus.Name;

            CANoe.Nodes nodes = (CANoe.Nodes)bus.Nodes;
            CANoe.Node  node  = (CANoe.Node)nodes.Add(csNodeName, null, null);

            node.FullName = PathToSourceNode();

            // Start the measurement
            if (DialogResult.OK == MessageBox.Show("If you press OK, the CANoe measurement will be started and the variant identification is run!", "Attention: Measurement Start"
                                                   , MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
            {
                CANoe.Measurement meas = (CANoe.Measurement)app.Measurement;
                AddStatusText("Starting CANoe measurement ");
                meas.Start();
                while (!meas.Running)
                {
                    mTB_Status.Text += ".";
                    DoSleep(20);
                }

                DoVariantIdentification();

                AddStatusText("Stopping CANoe measurement ");
                meas.Stop();
                while (meas.Running)
                {
                    mTB_Status.Text += ".";
                    DoSleep(20);
                }
            }

            // Cleanup
            AddStatusText("Cleaning up ...");

            // Remove the simulation node
            int i;

            AddStatusText("Removing simulation node");
            nodes.Remove(node);

            // Remove the namespace
            if (bCreateNamespace)
            {
                for (i = 1; i <= spaces.Count; ++i)
                {
                    if (spaces[i].Name == csNSDiagIdentifier)
                    {
                        AddStatusText("Removing namespace");
                        spaces.Remove(i);
                        break;
                    }
                }
            }
        }