我想要创建一个CANoe测试环境,它将执行以下操作:
所以我受够了前两个。下面显示的脚本是我用相应的配置文件执行CANoe程序本身时所做的事情。ConfigFile字符串来自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);
}
}至于解析,我是用Treeview清单完成的。所以数字1和2就完成了。现在,我在第三部分,我不知道从哪里开始。我已经进行了实验,首先选择一个特定的节点,然后单击应该用于运行测试模块的按钮,但首先显示一个消息框。
private TreeNode selectedNode = null;
private void button3_Click(object sender, EventArgs e)
{
string testMod;
testMod = treeView1.SelectedNode.Text;
MessageBox.Show(treeView1.SelectedNode.Text);
}我希望将MessageBox方法替换为可能运行GUI中列出的XML文件中的测试模块的方法。所以,与MessageBox.Show(treeView1.SelectedNode.Text)不同,它应该是这样的:
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*
}"01_Test_Preparation“是测试模块,而"01_01_Get_dem_ID_start”是测试用例。我必须弄清楚如何将这些内容与xml文件以及所有内容结合起来。我承认,上面所示的片段可能是混乱的,或者是完全错误的。请原谅我,我在这方面是全新的,我只是做尝试和错误的方法。
提前谢谢。
发布于 2015-03-10 08:48:49
我终于想出了答案。在此之前,我问过人们如何使用包含开关的foreach语句。我考虑将node.Name的字符串与string值进行比较,用于xml将与测试模块相等的情况。我有建议,很好的建议。这就是结果:
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);
}https://stackoverflow.com/questions/28599298
复制相似问题