public String executeExperiment(Experiment experiment) { currentExpResult = new CVE_ExperimentResult(); try { XmlSerializer serializer = new XmlSerializer(typeof(CVE_Experiment)); StringReader stringReader = new StringReader(experiment.experimentSpecification); currentExperiment = (CVE_Experiment)serializer.Deserialize(stringReader); Console.WriteLine("Extracted Experimented Specification.\nApplied Load = " + currentExperiment.load); } catch(Exception ex){ Notification.writeError("Failed to deserialize lab project: " + ex.StackTrace); return this.serializeLabResult(currentExpResult); } expEngine = new CVE_experimentengine(); currentExpResult.experimentID = experiment.experimentID; if (currentExperiment.length != 0) { labSelect = 1; Console.WriteLine("Your Experiment is being simulated"); currentExpResult.spoints = this.expEngine.shearforcepoints(currentExperiment.load, currentExperiment.point, currentExperiment.length); currentExpResult.bpoints = this.expEngine.bendingmdpoints(currentExperiment.load, currentExperiment.point, currentExperiment.length); currentExpResult.deflection = this.expEngine.maximumdeflection(currentExperiment.load, currentExperiment.length, currentExperiment.modulus, currentExperiment.inertia); Console.WriteLine("Deflection = " + currentExpResult.deflection); } else { labSelect = 2; //at this point, we call the labVIEW dll to execute the experiment LabVIEWTool lv = new LabVIEWTool(); Console.WriteLine("LabVIEW dll has been successfully called"); Console.WriteLine("\tnow extending actuator"); //apply the load and read deflection /*arg 1 = 1- extend actuator to apply load and also read deflection *arg 1 = 2- retract actuator to stop applying load and prepare for next, then stop afterward *arg 1 = 3 stop! */ currentExpResult.deflection = lv.callDll(1, currentExperiment.load); Console.WriteLine("Deflection = "+currentExpResult.deflection); } return this.serializeLabResult(currentExpResult); }
void timerElapsedHandler(Object source, ElapsedEventArgs args) { //pause! thou timer this.pollingTimer.Stop(); try { if (this.experimentQueue.isExperimentWaiting()) { Experiment experiment = this.experimentQueue.loadNextExperiment(); Notification.writeMessage("\nLoaded Experiment: " + experiment.experimentID); string experimentResult = this.experimentExecutor.executeExperiment(experiment); this.experimentQueue.completeExperiment(experimentResult, experiment.experimentID); selected = experimentExecutor.labSelect; if (selected == 2) { t = new Timer(60000); lv = new LabVIEWTool(); expID = experiment.experimentID; Console.WriteLine("\tnow retracting actuator"); lv.callDll(2, 200); t.Elapsed += new ElapsedEventHandler(t_Elapsed); t.Start(); } else if (selected == 1) { Notification.writeMessage("Finished running Experiment: " + expID); } } } catch (Exception ex) { Notification.writeError("Error while trying to run Experiment: " + ex.StackTrace); } //"continue! thou timer this.pollingTimer.Start(); }