private void tmrSignals_Tick(object sender, System.EventArgs e)
        {
            // get all the signal values and actualize controls
            if (Measurement.Running)
            {
                CANoe.Configuration   configuration      = null;
                CANoe.SimulationSetup simulationSetup    = null;
                CANoe.Nodes           nodes              = null;
                CANoe.Node            node               = null;
                CANoe.Signals         motorInputs        = null;
                CANoe.Signals         motorControlInputs = null;
                try
                {
                    configuration   = (CANoe.Configuration)App.Configuration;
                    simulationSetup = (CANoe.SimulationSetup)configuration.SimulationSetup;
                    nodes           = (CANoe.Nodes)simulationSetup.Nodes;
                    node            = (CANoe.Node)nodes["Motor"];
                    motorInputs     = (CANoe.Signals)node.Inputs;

                    if (motorInputs["OnOff"].Value == 0)
                    {
                        lblRunning.Text = "Not Running";
                    }
                    else
                    {
                        lblRunning.Text = "Running";
                    }

                    lblEngine.Text = motorInputs["EngineSpeed"].Value.ToString();

                    motorInputs = null;

                    node = (CANoe.Node)nodes["MotorControl"];
                    motorControlInputs = (CANoe.Signals)node.Inputs;

                    if (motorControlInputs["OnOff"].Value == 0)
                    {
                        lblDrivingState.Text = "Off";
                    }
                    else
                    {
                        lblDrivingState.Text = "On";
                    }

                    if (motorControlInputs["TurnSignal"].Value == 0)
                    {
                        lblTurnState.Text = "Off";
                    }
                    else
                    {
                        lblTurnState.Text = "On";
                    }
                }
                catch
                {
                }
                finally
                {
                    motorControlInputs = null;
                    node            = null;
                    nodes           = null;
                    simulationSetup = null;
                    configuration   = null;
                }
            }
        }
Exemple #2
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;
                    }
                }
            }
        }