// Update Status Timer // currently set for 100 ms // event handler for the Dispatch timer private void dispatchTimer_Tick(object sender, EventArgs e) { int[] BoardList; int nBoards = 0; // several sections // if the board is connected then // then check certain things every cycle // check some things every second if (Connected) { if (++skip == 10) // These actions happen every second { skip = 0; // update the elapsed time tbExTime.Text = KM.CoordMotion.TimeExecuted.ToString(); } else // these actions happen every cycle { if (KM.WaitToken(100) == KMOTION_TOKEN.KMOTION_LOCKED) // KMOTION_LOCKED means the board is available { try { KM_MainStatus MainStatus = KM.GetStatus(false); // passing false does not lock to board while generating status KM.ReleaseToken(); // Set DRO Colors if ((MainStatus.Enables & 1) != 0) { DROX.Foreground = Brushes.Green; } else { DROX.Foreground = Brushes.Red; } if ((MainStatus.Enables & 2) != 0) { DROY.Foreground = Brushes.Green; } else { DROY.Foreground = Brushes.Red; } if ((MainStatus.Enables & 4) != 0) { DROZ.Foreground = Brushes.Green; } else { DROZ.Foreground = Brushes.Red; } // Get Ablosule Machine Coordinates double x = 0, y = 0, z = 0, a = 0, b = 0, c = 0; KM.CoordMotion.UpdateCurrentPositionsABS(ref x, ref y, ref z, ref a, ref b, ref c, false); DROX.Text = String.Format("{0:F4}", x); DROY.Text = String.Format("{0:F4}", y); DROZ.Text = String.Format("{0:F4}", z); } catch (DMException) // in case disconnect in the middle of reading status { KM.ReleaseToken(); // make sure the token is released } } else { Connected = false; } // Manage the Cycle Start button btnCycleStart.IsEnabled = !ExecutionInProgress; } } else { if (++skip == 10) // These actions happen every second - when not connected { skip = 0; DisCount++; // check how many boards are connected BoardList = KM.GetBoards(out nBoards); if (nBoards > 0) { Connected = true; Title = String.Format("C# WPF App - Connected = USB location {0:X} count = {1}", BoardList[0], DisCount); } else { Connected = false; Title = String.Format("C# WPF App - KFLOP Disconnected count = {0}", DisCount); } } } }
// update status private void dispatcherTimer_Tick(object sender, EventArgs e) { int[] List; int nBoards = 0; // with extra FTDI Drivers this can take a long time // so only call occasionally when not connected if (!Connected && ++skip == 10) { skip = 0; // check how many boards connected List = KM.GetBoards(out nBoards); if (nBoards > 0) { Connected = true; Title = String.Format("Dynomotion C# Forms App - Connected - USB location {0:X}", List[0]); } else { Connected = false; Title = "Dynomotion C# Forms App - Disconnected"; } } if (Connected && KM.WaitToken(100) == KMOTION_TOKEN.KMOTION_LOCKED) { try { KM_MainStatus MainStatus = KM.GetStatus(false); // we already have a lock KM.ReleaseToken(); if ((MainStatus.Enables & 1) != 0) // Set DRO colors based on enables { DROX.Foreground = Brushes.Green; } else { DROX.Foreground = Brushes.Orange; } if ((MainStatus.Enables & 2) != 0) { DROY.Foreground = Brushes.Green; } else { DROY.Foreground = Brushes.Orange; } if ((MainStatus.Enables & 4) != 0) { DROZ.Foreground = Brushes.Green; } else { DROZ.Foreground = Brushes.Orange; } // Get Absolute Machine Coordinates and display in DROs double x = 0, y = 0, z = 0, a = 0, b = 0, c = 0; KM.CoordMotion.UpdateCurrentPositionsABS(ref x, ref y, ref z, ref a, ref b, ref c, false); DROX.Text = String.Format("{0:F4}", x); DROY.Text = String.Format("{0:F4}", y); DROZ.Text = String.Format("{0:F4}", z); // Set Feedhold color bases on state if (KM.WriteLineReadLine("GetStopState") == "0") { Feedhold.Background = Brushes.Yellow; } else { Feedhold.Background = Brushes.Orange; } } catch (DMException) // in case disconnect in the middle of reading status { KM.ReleaseToken(); // make sure token is released } } else { Connected = false; } // update Run button color/enable Run.IsEnabled = !ExecutionInProgress; }