private void timer2_Tick(object sender, EventArgs e) { updateActuatorPositionBar(); // check load cell for user force if (buffer != null) { //testLabel.Text = buffer.ToString(); double voltage = Convert.ToDouble(buffer.ToString()); double weight = (-22.8 * voltage * voltage) + (145.28 * voltage) - 3.0314; if (weight > WEIGHT_THRESHOLD && motormoving == false) { // Auto move motor to start/stop Position //xAxisAmp.ClearFaults(); // clear motor faults AutoMoveMotor(direction); xAxisEventObj.Start(true, -1); // start DONE movement listener // Start Timer timer1.Enabled = true; timer1.Start(); motormoving = true; } else if (weight < WEIGHT_THRESHOLD && motormoving == true) { xAxisEventObj.Stop(); xAxisAmp.HaltMove(); timer1.Stop(); motormoving = false; } } }
private void motorAutoMove_Click(object sender, EventArgs e) { try { motorAutoMove.Enabled = false; automove = true; moveStatusLabel.BackColor = Color.Green; moveStatusLabel.Text = "Motor Auto Move"; this.Refresh(); int Accel, Vel; distMotor = Convert.ToInt32(distTextBox.Text); Accel = Convert.ToInt32(accTextBox.Text); Vel = Convert.ToInt32(velTextBox.Text); // Start 1st movement moveMotor(Vel, Accel, distMotor); // Start event listener for when it finishes xAxisEventObj.Start(true, 50000); } catch (Exception ex) { automove = false; moveStatusLabel.BackColor = Color.Red; moveStatusLabel.Text = "Motor Stopped"; ready_Label.BackColor = Color.Yellow; ready_Label.Text = "ERROR"; motorAutoMove.Enabled = true; DisplayErrorPopup("Motor Comand Error", "Malfunction with motor movement."); } }