//Close button private void But_Close_Click(object sender, EventArgs e) { myPort.Close(); PBar_Connection.Value = 0; But_Stop.PerformClick(); //Enable/Disable buttons But_Connect.Enabled = true; But_Close.Enabled = false; But_Forward.Enabled = false; But_Reverse.Enabled = false; But_Start.Enabled = false; But_Stop.Enabled = false; But_CalTorque.Enabled = false; But_Start_Data.Enabled = false; But_Stop_Data.Enabled = false; But_Save_Data.Enabled = false; }
//General and graphical interface commands private void displaydata_event(object sender, EventArgs e) { //General items if (TBar_RPM.Value == 0) { I_Motor.Enabled = false; } //Turn off the motor GIF //Display data on the single readout boxes double torque_value = (Convert.ToDouble(EBox_CalTorque_S.Text)) * Convert.ToDouble(data_IN) + (Convert.ToDouble(EBox_CalTorque_O.Text)); //Convert bit to torque RBox_Bit.Text = data_IN; //Display the bits on the readout box RBox_Torque.Text = Convert.ToString(torque_value); //Display data on the central readout box datetime = DateTime.Now; //set the datetime variable to the current time string time = datetime.Hour + ":" + datetime.Minute + ":" + datetime.Second; //set time RBox_Data.AppendText(time + "\t\t" + data_IN + "\n"); //Display data and time on readout box //Display the data on the meter int integer_data_IN = Convert.ToInt32(data_IN); //Convert the data_IN to an integer if (integer_data_IN > PBar_Torque.Maximum) { PBar_Torque.Value = PBar_Torque.Maximum; } //Set max readout limit on progress bar else if (integer_data_IN < PBar_Torque.Minimum) { PBar_Torque.Value = PBar_Torque.Minimum; } //Set min readout limit on progress bar else { PBar_Torque.Value = integer_data_IN; } //Connect torque progress bar to torque readout //Chart code TimeSpan sinceStart = DateTime.Now - startTime; //Define var between current and start time //Chart graphics this.Chart_Torque.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Silver; //Grid line color this.Chart_Torque.ChartAreas[0].AxisX.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot; //Grid line style this.Chart_Torque.ChartAreas[0].AxisY.MajorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dot; //Grid line style double Chart_XValue = sinceStart.TotalMilliseconds; // datetime.Millisecond //Chart XY visual limits this.Chart_Torque.ChartAreas[0].AxisY.Minimum = 0; //set the Y axis min values this.Chart_Torque.ChartAreas[0].AxisY.Maximum = 6; //set the Y axis max values this.Chart_Torque.ChartAreas[0].AxisX.Minimum = Math.Round(sinceStart.TotalMilliseconds - 5000); //set the X axis min values this.Chart_Torque.ChartAreas[0].AxisX.Maximum = Math.Round(sinceStart.TotalMilliseconds); //set the X axis max values string test = Convert.ToString(torque_value); //double works fine this.Chart_Torque.Series["Torque Readout"].Points.AddXY(Chart_XValue, test); //Set plot this.Chart_Torque.Series["Torque Readout"].Color = Color.Green; //Change the color of the line //Torque Limit Series double C_Limit = Convert.ToDouble(EBox_Torque_Limit.Text); //Redundant callout this.Chart_Torque.Series["Torque Limit"].Points.AddXY(Chart_XValue, C_Limit); //Set plot this.Chart_Torque.Series["Torque Limit"].Color = Color.Orange; //change the color of the line //Shut down motor if the torque limit is reached***** if (TBar_Torque_Limit.Value < Convert.ToInt32(torque_value)) { But_Stop.PerformClick(); } //Turn off motor when torque limit is reached }