コード例 #1
0
 /// <summary>
 /// Start measurement in CANoe
 /// </summary>
 public void StartMeasurement()
 {
     if (!mMeasurement.Running)
     {
         mMeasurement.Start();
     }
 }
コード例 #2
0
 /// <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();
         }
     }
 }
コード例 #3
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;
                    }
                }
            }
        }