1

I want to create a CANoe test environment that would do the following:

  1. Run and Stop the CANoe software
  2. Parse the XML file (test module) and show list in GUI
  3. Select individual test module and execute test module

So I'm done with the first two. Script shown below is what I did with executing the CANoe program itself with its corresponding config file. The ConfigFile string was from the the selected file in an OpenFileDialog.

private void button1_Click(object sender, EventArgs e)
    {
        mApp       = new CANoe.Application();
        mMsr       = (CANoe.Measurement)mApp.Measurement;
        string ConfigFile = textBox1.Text;

            try
            {
                mApp.Open(ConfigFile,true,true);
            }
            catch (System.Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }

    }

As for the parsing, I did it with the Treeview listing. So numbers 1 and 2 are done. Now, I'm on the third part and I'm clueless where to start. I've experimented first selecting a particular node and clicking the button that is supposed to be for running the test module but instead shown a message box first.

private TreeNode selectedNode = null;
private void button3_Click(object sender, EventArgs e)
    {
        string testMod;
        testMod = treeView1.SelectedNode.Text;
        MessageBox.Show(treeView1.SelectedNode.Text);
    }

I want to replace the MessageBox method with something that would possibly run the test modules in the XML file listed in the GUI. So instead of MessageBox.Show(treeView1.SelectedNode.Text), it would be something like:

string testMod;
testMod = treeView1.SelectedNode.Text;
if (mMsr != null) mMsr.Start();
CANoe.System     sys  = null;
CANoe.Namespaces nss  = null;
CANoe.Namespace  ns   = null;
CANoe.Variables  vars = null;
if (testMod = *the name of the test module*)
    {
        *//something like this*
        sys = (CANoe.System)mApp.System;
        nss = (CANoe.Namespaces)sys.Namespaces;
        ns   = (CANoe.Namespace)nss["_01_Test_Preparation"];
        vars = (CANoe.Variables)ns.Variables;
        mSysVar_start = (CANoe.Variable)vars["_01_01_Get_Dem_ID_start"];
        mSysVar = (CANoe.Variable)vars["_01_01_Get_Dem_ID"];
        mSysVar_start.Value = 1;
        System.Threading.Thread.Sleep(1000);
        mMsr.Start();
        *//or something similar*
    }

The "01_Test_Preparation" is the test module whereas the "01_01_Get_dem_ID_start" is the test case. I have to figure out how to incorporate these with the xml file and all. I admit that the snippets regarding shown above may be confusing or just plain wrong. Bear with me I'm totally new at this and simply doing the Trial and Error method.

Thanks in advance.

Kurisuchin
  • 155
  • 1
  • 4
  • 20

1 Answers1

3

And I finally came up with an answer to this. Previously, I asked people on using the foreach statement with switch in it. I thought of comparing the string of the node.Name to the string value for the cases with which the xml would be equal to the test module. I got suggestions, good ones at that. And this is the outcome:

private void RecurseTree(TreeNode node,string ParentNode)
    {
        CANoe.System sys = null;
        CANoe.Namespaces nss = null;
        CANoe.Namespace ns = null;
        CANoe.Variables vars = null;
            sys = (CANoe.System)mApp.System;
            nss = (CANoe.Namespaces)sys.Namespaces;
        if (node.Checked == true)
        {
            ns = (CANoe.Namespace)nss[ParentNode];
            vars = (CANoe.Variables)ns.Variables;
            mSysVar_start = (CANoe.Variable)vars[node.Name + "_start"];
            mSysVar = (CANoe.Variable)vars[node.Name];
            mSysVar_start.Value = 1;
            int chk = 0;
            System.Threading.Thread.Sleep(1000);
            if ((int)mSysVar.Value != 0) while ((int)mSysVar.Value == 1 || (int)mSysVar.Value == 2) continue;
            else chk = 1;

                if ((int)mSysVar.Value==3||(int)mSysVar.Value==4 ||chk==1)
                {
                    if (mMsr!=null) mMsr.Stop();
                    System.Threading.Thread.Sleep(1000);
                    if (mMsr!=null) mMsr.Start();
                    System.Threading.Thread.Sleep(1000);
                }

        }
        foreach (TreeNode childNode in node.Nodes) RecurseTree(childNode, ParentNode);
    }

    private void msrstart_Click(object sender, EventArgs e)
    {
            if (mMsr != null) mMsr.Start();
            foreach (TreeNode node in treeView1.Nodes) RecurseTree(node, node.Name);   
    }
Kurisuchin
  • 155
  • 1
  • 4
  • 20