// 将任务信息中的单位参考信息拆出来 public void XMLToTaskRefer(XElement xele, int type, ref ReferInfo refer) { if (DLLDefine.sg_task_pointer == type) { XElement eleunit = xele.Element("unitinfo"); int min = Convert.ToInt16(eleunit.Element("rangeLow").Value); int max = Convert.ToInt16(eleunit.Element("rangeHigh").Value); string unit = eleunit.Element("unit").Value; refer.POINTER_REFER = new pointer_refer(min, max, unit); } else if (DLLDefine.sg_task_knob == type) { refer.KNOB_REFER = new knob_refer(); IEnumerable <XElement> elestalls = xele.Element("unitinfo").Elements("stall"); foreach (XElement item in elestalls) { int min = Convert.ToInt16(item.Element("rangeLow").Value); int max = Convert.ToInt16(item.Element("rangeHigh").Value); string context = item.Element("context").Value; refer.KNOB_REFER.knobs.Add(new knob_refer.knobStall(min, max, context)); } } else if (DLLDefine.sg_task_analog == type) { refer.ANALOG_REFER = new analog_refer(); } else if (DLLDefine.sg_task_led == type) { refer.LED_REFER = new led_refer(); } }
public DetectInfo(string devicename, ROIInfo roi, TaskInfo task, ReferInfo refer) { this.deviceName = devicename; this.ROIINFO = roi; this.TASKINFO = task; this.REFERINFO = refer; }
// 由XML文件生成检测任务序列 public List <DetectInfo> xmlToTaskList(string xmlPath) { // 1. 加载XML文件 XElement xe = XElement.Load(xmlPath); // 2. 获取XML Device 信息 IEnumerable <XElement> devices = xe.Elements("device"); // 3. 遍历并生成任务信息,同时添加到任务序列中 List <DetectInfo> DetectList = new List <DetectInfo>(); foreach (XElement element in devices) { XElement eleRoi = element.Element("roiinfo"); int startX = Convert.ToInt16(eleRoi.Element("startX").Value); int startY = Convert.ToInt16(eleRoi.Element("startY").Value); int disX = Convert.ToInt16(eleRoi.Element("distX").Value); int disY = Convert.ToInt16(eleRoi.Element("distY").Value); int width = Convert.ToInt16(eleRoi.Element("width").Value); int height = Convert.ToInt16(eleRoi.Element("height").Value); ROIInfo roi = new ROIInfo(startX, startY, disX, disY, width, height); XElement eleTask = element.Element("taskinfo"); int type = Convert.ToInt16(eleTask.Element("type").Value); int subtype = Convert.ToInt16(eleTask.Element("subtype").Value); int num = Convert.ToInt16(eleTask.Element("number").Value); TaskInfo task = new TaskInfo(type, subtype, num); XElement eleName = element.Element("name"); string devicename = eleName.Value; // 此处添加参考信息,用以检测结果对应语义 ReferInfo refer = new ReferInfo(); XMLToTaskRefer(element, type, ref refer); DetectInfo detect = new DetectInfo(devicename, roi, task, refer); DetectList.Add(detect); } // 4. 返回任务序列 return(DetectList); }