private Inca inca; private Experiment experiment; private IncaExperimentView experimentView;public void StartInca() { this.inca = new Inca(); }
进入试验环境或工作空间:IncaDataBase incaDataBase = inca.GetCurrentDataBase();OpenDBWrokSpace(incaDataBase);private void OpenDBWrokSpace(IncaDataBase incaDB) { HardwareConfiguration myHWC = incaDB.GetActiveHardwareConfiguration(); if (myHWC == null) { System.Windows.Forms.MessageBox.Show("获取硬件配置失败
", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ExperimentEnvironment myExpEnv = myHWC.GetAssignedExperimentEnvironment(); var success = myExpEnv.SetHardwareConfiguration(myHWC); //Opens the INCA Experiment assigned to the active workbase IncaExperimentView myExpEnvView = myExpEnv.OpenExperiment(); GetExperiment(); }private void GetExperiment() { if (inca != null && experiment == null) { experiment = inca.GetOpenedExperiment();//试验中 experimentView = this.inca.GetOpenedExperimentView(); //init params var b = this.experiment.IsIncaOnlineExperiment(); IncaOnlineExperiment onlineExperiment = this.experiment as IncaOnlineExperiment; WorkbaseDevice myDevice = experiment.GetDevice("XCP: 1") as WorkbaseDevice } }
读取所有标定变量,并添加到集合:public List<string> ReadIncaAllCalibrationElement() { CalibrationElement[] calibrationElementArray = experiment.GetAllCalibrationElements(); List<string> calist = new List<string>(); foreach (var calElement in calibrationElementArray) { calist.Add(calElement.GetName()); } return calist; }
读取所有测量变量,并添加到集合: public List<string> ReadIncaAllMeasureElement() { MeasureElement[] measureElementArray = experiment.GetAllMeasureElements(); List<string> meslist = new List<string>(); foreach (var mElement in measureElementArray) { meslist.Add(mElement.GetName()); } return meslist; }
启动读取变量值:public bool StartReadIncaMeasure() { if (this.experiment == null) return false; OnlineExperiment onlineExperiment = experiment as OnlineExperiment; return onlineExperiment.StartMeasurement(); }
添加变量到INCA:public bool AddIncaMeasureElement(string measure) { if (this.experiment == null) return false; var measureElement = this.experiment.GetMeasureElement(measure); if (experimentView.OpenViewForMeasureElementWithMaxLabels(measureElement, 1)) return StartReadIncaMeasure(); return false; }
根据标定变量名称获取标定变量值: public string GetCalibrationElementValue(string calibrationElement) { try { if (experiment == null) return ""; var calibElement = experiment.GetCalibrationElement(calibrationElement); var calibrationData = calibElement.GetValue(); CalibrationScalarData scalarData = calibrationData as CalibrationScalarData; var arra = scalarData.GetDoublePhysValue(); var type = scalarData.GetPhysType(); var tValue = ""; switch (type) { case "char": tValue = scalarData.GetCharPhysValue(); break; case "real64": tValue = scalarData.GetDoublePhysValue().ToString(); break; default: break; } return tValue; } catch (Exception ex) { return ""; } }
根据测量变量名称获取测量变量的值: public string GetMeasureElementValue(string measureElement) { try { if (experiment == null) return ""; AddIncaMeasureElement(measureElement); MeasureScalarData measureData = experiment.GetMeasureElement(measureElement).GetValue() as MeasureScalarData; var type = measureData.GetPhysType(); var tValue = ""; switch (type) { case "char": tValue = measureData.GetCharPhysValue(); break; case "real64": tValue = measureData.GetDoublePhysValue().ToString(); break; default: break; } return tValue; } catch (Exception ex) { return ""; } finally { } }
设定标定变量的值,标定前一定要切换到WD: public bool SetCalibrationElement(string calibrationElement, string setValue) { try { if (experiment == null) return false; var caliElement = experiment.GetCalibrationElement(calibrationElement); WorkbaseDevice workDev = caliElement.GetDevice() as WorkbaseDevice; workDev.SwitchToReferencePage();//切换wd CalibrationScalarData calibrationData = caliElement.GetValue() as CalibrationScalarData; var type = calibrationData.GetPhysType(); switch (type) { case "char": { return calibrationData.SetCharPhysValue(setValue); } case "real64": { double val; double.TryParse(setValue, out val); return calibrationData.SetDoublePhysValue(val); } default: break; } return false; } catch (Exception ex) { return false; } }
关闭INCA软件: public bool CloseIncaTool() { return this.inca.CloseTool(); }
INCA中还有很多其他功能,可根据自己需要进行二次开发(图片来源网络,侵删)
0 评论