//First Method called every time the form is displayed public void InitiateProgram(Enumerators.ProgramSelect ProgramSelect) { this.StartPosition = FormStartPosition.CenterScreen; this.WindowState = FormWindowState.Normal; DataSample = new objDataSample(GlobalVariables.leftSerialPort); DataSample.ProgramSelector = ProgramSelect; DataSample.SelectedSpeed = 65; DataSample.SelectedTorque = 250; ThreadCallbackProcessFeedbackError = DataSample.ProcessErrorSession; ResetData(); CurrentProgram = DataSample.ReadXMLProgram(); this.Focus(); Start(); }
//Read Program public ProgramData ReadXMLProgram() { ProgramData CurrentProgram = new ProgramData(); string RootDiretory = AppDomain.CurrentDomain.BaseDirectory; string appPath = Path.GetDirectoryName(Application.ExecutablePath); XmlTextReader reader = null; switch (this.ProgramSelector) { case Enumerators.ProgramSelect.FTPTest: reader = new XmlTextReader(RootDiretory + "\\Programs\\FTPTestConcentric.xml"); break; case Enumerators.ProgramSelect.VO2MaxTest: reader = new XmlTextReader(RootDiretory + "\\Programs\\VO2MaxTest.xml"); break; default: break; } while (reader.Read()) { if (reader.ReadToFollowing("StageIndex")) { ProgramStage newFTPStage = new ProgramStage(); reader.Read(); newFTPStage.StageIndex = reader.ReadContentAsInt(); reader.ReadToFollowing("StageNumber"); reader.Read(); newFTPStage.StageNumber = reader.ReadContentAsInt(); reader.ReadToFollowing("StageName"); reader.Read(); newFTPStage.StageName = reader.ReadContentAsString(); reader.ReadToFollowing("StageDuration"); reader.Read(); newFTPStage.StageTimeRemaining = new TimeSpan(0, reader.ReadContentAsInt(), 0); reader.ReadToFollowing("Sets"); reader.Read(); while (reader.Read()) { if (reader.Name == "Set") { ProgramSet newFTPSet = new ProgramSet(); reader.ReadToFollowing("SetIndex"); reader.Read(); newFTPSet.SetIndex = reader.ReadContentAsInt(); reader.ReadToFollowing("Number"); reader.Read(); newFTPSet.SetNumber = reader.ReadContentAsInt(); reader.ReadToFollowing("Duration"); reader.Read(); newFTPSet.TimeRemaining = new TimeSpan(0, reader.ReadContentAsInt(), 0); reader.ReadToFollowing("Direction"); reader.Read(); newFTPSet.Direction = reader.ReadContentAsString(); reader.ReadToFollowing("DirectionFlag"); reader.Read(); int DirectionVariable = reader.ReadContentAsInt(); if (DirectionVariable == 1) newFTPSet.SelectedDirection = Enumerators.Direction.Forward; else if (DirectionVariable == -1) newFTPSet.SelectedDirection = Enumerators.Direction.Backward; reader.ReadToFollowing("Contraction"); reader.Read(); newFTPSet.Contraction = reader.ReadContentAsString(); reader.ReadToFollowing("Legs"); reader.Read(); newFTPSet.Legs = reader.ReadContentAsString(); reader.ReadToFollowing("Position"); reader.Read(); newFTPSet.Position = reader.ReadContentAsString(); reader.ReadToFollowing("RestDuration"); reader.Read(); newFTPSet.RestTimeRemaining = new TimeSpan(0, reader.ReadContentAsInt(), 0); reader.ReadToFollowing("Instructions"); reader.Read(); newFTPSet.Instructions = reader.ReadContentAsString(); newFTPStage.FTPSetConcentricCollection.Add(newFTPSet); reader.Read(); //Read White Space reader.Read(); //Read Set reader.Read(); //Read White Space } else { break; } } CurrentProgram.FTPStageCollection.Add(newFTPStage); } } CurrentProgram.CurrentFTPStage = CurrentProgram.FTPStageCollection[0]; CurrentProgram.CurrentFTPStage.CurrentFTPSet = CurrentProgram.CurrentFTPStage.FTPSetConcentricCollection[0]; return CurrentProgram; }