/// <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; }
private void tmrSignals_Tick(object sender, System.EventArgs e) { // get all the signal values and actualize controls if (Measurement.Running) { CANoe.Bus bus = null; try { bus = (CANoe.Bus)App.get_Bus("CAN"); if (bus != null) { CANoe.Signal signal = (CANoe.Signal)bus.GetSignal(1, "LightState", "OnOff"); if (signal != null) { if (signal.Value == 0) { btnLightSwitch.Text = "Off"; } else { btnLightSwitch.Text = "On"; } } } } catch { } } }
private void btnLightSwitch_Click(object sender, System.EventArgs e) { if (Measurement.Running) { CANoe.Bus bus = null; try { bus = (CANoe.Bus)App.get_Bus("CAN"); if (bus != null) { CANoe.Signal signal = (CANoe.Signal)bus.GetSignal(1, "LightState", "OnOff"); if (signal != null) { if (btnLightSwitch.Text == "Off") { signal.Value = 1; btnLightSwitch.Text = "On"; } else { signal.Value = 0; btnLightSwitch.Text = "Off"; } } } } catch { } } }