/// <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(); } } }
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); } } } } } }
//creates a request from a given request string private Diagnostic.DiagnosticRequest GetRequest(string aQualPath, string aEcuQual, string aBusName) { try { if (mCANoe == null) { mCANoe = new CANoe.Application(); } //get Measurement instance if (mMeasurement == null) { mMeasurement = (CANoe.Measurement)mCANoe.Measurement; //create on event handles mMeasurement.OnInit += new CANoe._IMeasurementEvents_OnInitEventHandler(Measurement_OnInit); } //is measurement running? if (mMeasurement.Running == false) { lCOMStatus.Text = "Measurement not running!"; lCOMStatus.BackColor = System.Drawing.Color.Yellow; return(null); } //get the diagnostics interface if (gDiagnostic == null || gLastEcuQual != aEcuQual) { gLastEcuQual = aEcuQual; //Diagnostic.Diagnostic diag; CANoe.Network network; CANoe.Device device; CANoe.Devices devices; gDiagnostic = null; network = (CANoe.Network)mCANoe.get_Networks(aBusName); if (network != null) { devices = (CANoe.Devices)network.Devices; device = (CANoe.Device)devices[mECUName]; if (device != null) { gDiagnostic = (Diagnostic.Diagnostic)device.Diagnostic; } } } return((Diagnostic.DiagnosticRequest)gDiagnostic.CreateRequest(aQualPath)); } catch (Exception ex) { ShowError(ex); return(null); } }
public CSharpDisplay() { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); // Initialize types App = new CANoe.Application(); Measurement = (CANoe.Measurement)App.Measurement; }
/// <summary> /// Unregister from COM events and release referenced COM interfaces /// </summary> public void DisconnectFromCANoe() { //---------------------------------------- // Unregister from events of MostNetworkInterface //---------------------------------------- if (mMostNetworkInterface != null) { mMostNetworkInterface.OnAMSRx -= new CANoe._IMostNetworkInterfaceEvents_OnAMSRxEventHandler(mostNetworkInterface_OnAMSRx); } //---------------------------------------- // Release referenced COM interfaces //---------------------------------------- mMostApplicationFilter = null; mMostNetworkInterface = null; mMostDisassembler = null; mMeasurement = null; mApplication = null; }
/// <summary> /// Get CANoe COM Interfaces and do some initializing steps /// </summary> public void ConnectToCANoe() { //---------------------------------------- // Get CANoe COM interfaces //---------------------------------------- // general CANoe Interfaces mApplication = new CANoe.Application(); mMeasurement = (CANoe.Measurement)mApplication.Measurement; // MOST specific CANoe Interfaces CANoe.Network network = (CANoe.Network)mApplication.get_Networks("MOST Ring"); // The one and only MOST network of any CANoe configuration CANoe.Devices devices = (CANoe.Devices)network.Devices; CANoe.Device device = (CANoe.Device)devices["MOST 1"]; // The device of the CANoe configuration that has channel MOST1 assigned to mMostNetworkInterface = (CANoe.MostNetworkInterface)device.NetworkInterface; mMostApplicationFilter = (CANoe.MostApplicationFilter)mMostNetworkInterface.ApplicationFilter; mMostDisassembler = (CANoe.MostDisassembler)device.Disassembler; //---------------------------------------- // Initialize MOST Filters //---------------------------------------- // Prohibit MostNetworkInterface to fire any events mMostNetworkInterface.EventSources = 0; // Set filter-type of MostApplicationFilter to: pass filter mMostApplicationFilter.FilterType = 0; // Enable MostApplicationFilter mMostApplicationFilter.Enabled = true; //---------------------------------------- // Register for events of MostNetworkInterface //---------------------------------------- mMostNetworkInterface.OnAMSRx += new CANoe._IMostNetworkInterfaceEvents_OnAMSRxEventHandler(mostNetworkInterface_OnAMSRx); }
/// <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(); } } } }
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; } } } }