private void OnFormClosing(object sender, FormClosingEventArgs formClosingEventArgs) { USB.CloseDevice(); try { saveLogToolStripMenuItem_Click(sender, null); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error while saving logfile", MessageBoxButtons.OK); } GlobalProperties.SaveProperties(); }
private void UIupdateTimer_Tick(object sender, EventArgs e) { #region UI update if (USB.IsOpen) { CheckBoxInhibit = true; //fetch data if too old if ((DateTime.Now.Subtract(USB.LastUpdate)).Milliseconds > GlobalProperties.USB_Refresh_Period) { USB.Transfer(); } if (RawUsbForm.Visible) { RawUsbForm.Update(USB.InputBuffer); } else { showRawCheckbox.Checked = false; } XMinStatusLabel.BackColor = !USB.MinXswitch ? Color.Lime : Color.Red; XMaxStatusLabel.BackColor = !USB.MaxXswitch ? Color.Lime : Color.Red; YMinStatusLabel.BackColor = !USB.MinYswitch ? Color.Lime : Color.Red; YMaxStatusLabel.BackColor = !USB.MaxYswitch ? Color.Lime : Color.Red; TopStatusLabel.BackColor = USB.TopSwitch ? Color.Lime : SystemColors.Control; BottomStatusLabel.BackColor = USB.BottomSwitch ? Color.Lime : SystemColors.Control; //reset drill cycle if (checkBoxD.Checked && !USB.TopSwitch && !USB.BottomSwitch) { checkBoxD.Checked = false; } CheckBoxInhibit = false; } #endregion #region View update XStatusLabel.Text = USB.X_Rel_Location.ToString("D5"); YStatusLabel.Text = USB.Y_Rel_Location.ToString("D5"); var curLoc = USB.CurrentLocation(); Xlabel.Text = "X: " + curLoc.X.ToString("F3"); Ylabel.Text = "Y: " + curLoc.Y.ToString("F3"); var snapLocation = GetViewCursorLocation(); cursorCrossHair.UpdatePosition(snapLocation); ViewXLabel.Text = snapLocation.X.ToString("F3"); ViewYLabel.Text = snapLocation.Y.ToString("F3"); ViewZoomLabel.Text = (int)(nodeViewer.ZoomLevel * 100) + "%"; drillCrossHair.UpdatePosition(curLoc.X, curLoc.Y); #endregion #region Refresh required elements if ((DateTime.Now.Subtract(lastUIupdate)).Milliseconds > GlobalProperties.Label_Refresh_Period) { OutputLabel.Refresh(); Xlabel.Refresh(); Ylabel.Refresh(); statusStrip1.Refresh(); logger1.Refresh(); lastUIupdate = DateTime.Now; Application.DoEvents(); } #endregion #region Backup state GlobalProperties.X_Dir = USB.X_Last_Direction; GlobalProperties.Y_Dir = USB.Y_Last_Direction; GlobalProperties.X_Pos = USB.X_Abs_Location; GlobalProperties.Y_Pos = USB.Y_Abs_Location; GlobalProperties.X_Delta = USB.X_Delta; GlobalProperties.Y_Delta = USB.Y_Delta; if ((DateTime.Now.Subtract(GlobalProperties.LastSave)).Milliseconds > GlobalProperties.GlobalProperties_Refresh_Period) { GlobalProperties.SaveProperties(); } #endregion }