/// <summary> /// Private method for playing a cue. /// Handles when each cue item starts or ends. /// Handels when the cue is finished. /// </summary> private void TimerTick(object sender, EventArgs e) { int NumberRunning = MasterList.Count; for (int Count = 0; Count < MasterList.Count; Count++) { CueItem Item = CurrentCue.GetList()[Count]; if (!FinishedCue) { if (stopwatch.Elapsed.Seconds >= Item.DelayBefore) { if (Item.Running) { if (stopwatch.Elapsed.Seconds >= (Item.DelayBefore + Item.RunTime - (Item.CueMotor.InputData.SetpointVelocity.Get() / Item.CueMotor.InputData.Deceleration.Get()))) { if (!Item.Stopping) { Item.Stopping = true; Item.SetVelocity = 0; } else if (Item.CueMotor.OutputData.Velocity.Get() == 0) { Item.Running = false; Logger.LogInfo("Motor " + Item.CueMotor.Name + " has stopped running"); } } Item.UpdateInputFields(); MasterList[Count].ReadWriteMultipleRegister(8, 0, 4, 12, 4, CurrentCue.GetList()[Count].CueMotor.InputData.GetValues(), ref result); Item.CueMotor.OutputData.SetValues(result); } else { NumberRunning--; } } if (NumberRunning == 0) { FinishedCue = true; } } else { stopwatch.Stop(); timer.Stop(); DisconnectMotors(); Logger.LogInfo("Cue " + CurrentCue.Name + " has stopped running"); return; } } }
/// <summary> /// Create Object representations of Cues, CueItems, and Motors from the associated database /// and store the Cues into CueList /// </summary> public void InitObjects() { try { data.Connect(); DataTable CueTable = data.GetCues(); foreach (DataRow CueRow in CueTable.Rows) { Cue NewCue = new Cue(CueRow["Name"].ToString(), CueRow["Description"].ToString()); DataTable CueItemTable = data.GetAllFromCueMotor(NewCue.Name); foreach (DataRow CueItemRow in CueItemTable.Rows) { Motor CueMotor = new Motor(CueItemRow["IPAddress"].ToString(), CueItemRow["MotorName"].ToString(), CueItemRow["Description"].ToString(), (int)CueItemRow["LimitMaxVelocity"], (int)CueItemRow["LimitMaxAcceleration"], (int)CueItemRow["LimitMaxDeceleration"], (int)CueItemRow["LimitMaxNegPosition"], (int)CueItemRow["LimitMaxPosPosition"]); CueItem Item = new CueItem(Double.Parse(CueItemRow["DelayBefore"].ToString()), Double.Parse(CueItemRow["RunTime"].ToString()), CueMotor, (int)CueItemRow["SetVelocity"], (int)CueItemRow["SetAcceleration"], (int)CueItemRow["SetDeceleration"], Convert.ToBoolean(CueItemRow["CounterClockwise"]), (int)CueItemRow["SetPosition"]); NewCue.Add(Item); Console.WriteLine("Added Item"); } CueList.Add(NewCue); } data.Disconnect(); foreach (Cue c in CueList) { Console.WriteLine(c.Name); } } catch (Exception e) { MessageBox.Show(e.ToString()); } }