Esempio n. 1
0
        private void StepperBoard_Attach(object sender, AttachEventArgs e)
        {
            for (int i = 0; i < _stepperBoard.steppers.Count; i++)
            {
                if (_motorCount == 0)
                {
                    _steppers[i].MinAcceleration = _stepperBoard.steppers[i].AccelerationMin;
                    _steppers[i].MaxAcceleration = _stepperBoard.steppers[i].AccelerationMax;
                    _steppers[i].Acceleration    = _steppers[i].MaxAcceleration;

                    _steppers[i].MinVelocity   = _stepperBoard.steppers[i].VelocityMin;
                    _steppers[i].MaxVelocity   = _stepperBoard.steppers[i].VelocityMax;
                    _steppers[i].VelocityLimit = _steppers[i].MaxVelocity;

                    RegisterBindings(i);
                }
                _stepperBoard.steppers[i].VelocityLimit = _steppers[i].VelocityLimit;
                _stepperBoard.steppers[i].Acceleration  = _steppers[i].Acceleration;
            }

            if (_motorCount == 0)
            {
                _motorCount = _stepperBoard.steppers.Count;
                ConfigManager.LogManager.LogDebug("Detaching phidget stepper board after config. (SerialNumber=\"" + _serialNumber + "\")");
                _stepperBoard.close();
                _stepperBoard = null;
            }
        }
Esempio n. 2
0
 public void close()
 {
     stepper.steppers[0].Engaged = false;
     //close the Stepper object
     stepper.close();
     //set the object to null to get it out of memory
     stepper = null;
 }
Esempio n. 3
0
        private void DoneButton_Click(object sender, RoutedEventArgs e)
        {
            // Remove event handler and close Phidget
            ifKit.InputChange -= new InputChangeEventHandler(ifKit_InputChange);
            ifKit.close();

            // Go to Return Summary Page
            ReturnSummary page = new ReturnSummary(_aaExchange);

            this.NavigationService.Navigate(page);
        }
Esempio n. 4
0
        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            stepper.Attach -= stepper_Attach;
            stepper.Detach -= stepper_Detach;
            stepper.Error  -= stepper_Error;

            stepper.CurrentChange  -= stepper_CurrentChange;
            stepper.PositionChange -= stepper_PositionChange;
            stepper.VelocityChange -= stepper_VelocityChange;

            //run any events in the message queue - otherwise close will hang if there are any outstanding events
            Application.DoEvents();

            if (stepper.Attached)
            {
                for (int i = 0; i < stepper.steppers.Count; i++)
                {
                    stepper.steppers[i].Engaged = false;
                }
            }

            stepper.close();
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            try
            {
                //Declare a Stepper object
                Stepper stepper = new Stepper();

                //Hook the basic event handlers
                stepper.Attach += new AttachEventHandler(stepper_Attach);
                stepper.Detach += new DetachEventHandler(stepper_Detach);
                stepper.Error  += new ErrorEventHandler(stepper_Error);

                //Hook the Stepper specific event handlers
                stepper.CurrentChange += new CurrentChangeEventHandler
                                             (stepper_CurrentChange);
                stepper.InputChange += new InputChangeEventHandler
                                           (stepper_InputChange);
                stepper.PositionChange += new StepperPositionChangeEventHandler
                                              (stepper_PositionChange);
                stepper.VelocityChange += new VelocityChangeEventHandler
                                              (stepper_VelocityChange);

                //Open the Stepper object for device connections
                stepper.open();

                //get the program to wait for a Stepper device to be attached
                Console.WriteLine("Waiting for a Stepper to be attached....");
                stepper.waitForAttachment();

                Console.WriteLine("Now the velocity will be set");
                Console.WriteLine("The motor will run until it reaches the set goal position");
                Console.WriteLine("Press any key to continue...");
                Console.ReadLine();

                //Set the max velocity to start the stepper motor moving until it hits
                //the goal position
                stepper.steppers[0].VelocityLimit = 100.00; //Max velocity
                Console.WriteLine("Stepper motor velocity set to: {0}",
                                  stepper.steppers[0].VelocityLimit.ToString());
                stepper.steppers[0].Acceleration = stepper.steppers[0].AccelerationMin; //ensure the value is between the AccelerationMin and AccelerationMax
                Console.WriteLine("Stepper motor acceleration set to: {0}",
                                  stepper.steppers[0].Acceleration.ToString());
                stepper.steppers[0].TargetPosition = 0;
                stepper.steppers[0].Engaged        = true;


                Console.WriteLine("Press any key to continue...");
                Console.ReadLine();
                Console.WriteLine("Will now move to position 2000.");
                Console.WriteLine("Please wait until the motor stops.");
                Console.WriteLine("Press any key to continue...");
                Console.ReadLine();

                //Set the goal position to 2000
                stepper.steppers[0].TargetPosition = 2000;

                Console.WriteLine("Press any key to end....");
                Console.ReadLine();

                stepper.steppers[0].Engaged = false;

                //close the Stepper object
                stepper.close();

                //set the object to null to get it out of memory
                stepper = null;

                //if no exceptions were thrown at this point it is safe to terminate
                Console.WriteLine("ok");
            }
            catch (PhidgetException ex)
            {
                Console.WriteLine(ex.Description);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        static void Main(string[] args)
        {
            try
            {
                //Declare a Stepper object
                Stepper stepper = new Stepper();

                //Hook the basic event handlers
                stepper.Attach += new AttachEventHandler(stepper_Attach);
                stepper.Detach += new DetachEventHandler(stepper_Detach);
                stepper.Error += new ErrorEventHandler(stepper_Error);

                //Hook the Stepper specific event handlers
                stepper.CurrentChange += new CurrentChangeEventHandler
                                                    (stepper_CurrentChange);
                stepper.InputChange += new InputChangeEventHandler
                                                    (stepper_InputChange);
                stepper.PositionChange += new StepperPositionChangeEventHandler
                                                    (stepper_PositionChange);
                stepper.VelocityChange += new VelocityChangeEventHandler
                                                    (stepper_VelocityChange);

                //Open the Stepper object for device connections
                stepper.open();

                //get the program to wait for a Stepper device to be attached
                Console.WriteLine("Waiting for a Stepper to be attached....");
                stepper.waitForAttachment();

                Console.WriteLine("Now the velocity will be set");
                Console.WriteLine("The motor will run until it reaches the set goal position");
                Console.WriteLine("Press any key to continue...");
                Console.ReadLine();

                //Set the max velocity to start the stepper motor moving until it hits
                //the goal position
                stepper.steppers[0].VelocityLimit = 100.00; //Max velocity
                Console.WriteLine("Stepper motor velocity set to: {0}",
                                        stepper.steppers[0].VelocityLimit.ToString());
                stepper.steppers[0].Acceleration = stepper.steppers[0].AccelerationMin; //ensure the value is between the AccelerationMin and AccelerationMax
                Console.WriteLine("Stepper motor acceleration set to: {0}",
                                        stepper.steppers[0].Acceleration.ToString());
                stepper.steppers[0].TargetPosition = 0;
                stepper.steppers[0].Engaged = true;

                Console.WriteLine("Press any key to continue...");
                Console.ReadLine();
                Console.WriteLine("Will now move to position 2000.");
                Console.WriteLine("Please wait until the motor stops.");
                Console.WriteLine("Press any key to continue...");
                Console.ReadLine();

                //Set the goal position to 2000
                stepper.steppers[0].TargetPosition = 2000;

                Console.WriteLine("Press any key to end....");
                Console.ReadLine();

                stepper.steppers[0].Engaged = false;

                //close the Stepper object
                stepper.close();

                //set the object to null to get it out of memory
                stepper = null;

                //if no exceptions were thrown at this point it is safe to terminate
                Console.WriteLine("ok");

            }
            catch (PhidgetException ex)
            {
                Console.WriteLine(ex.Description);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }