コード例 #1
0
        public void GetEncoderCounts()
        {
            StepperController sc = new StepperController(IP);

            sc.EnableMotor();

            //sc.ResetEncoderPosition(0);

            sc.SetFormatDecimal();
            sc.StartListening();
            sc.GetEncoderCounts();
            sc.GetEncoderPosition();
            Thread.Sleep(100);
            Debug.Print($"Encoder position= {sc.Sm.EncoderPosition}");
            Debug.Print($"Encoder counts= {sc.Sm.EncoderCounts}");

            sc.StartJog(5, 5, 5);
            Thread.Sleep(1000);
            sc.StopJog();
            sc.GetEncoderPosition();
            sc.GetEncoderCounts();
            Thread.Sleep(2000);
            double newCounts   = sc.Sm.EncoderCounts;
            double newPosition = sc.Sm.EncoderPosition;

            Debug.Print($"Encoder position= {sc.Sm.EncoderPosition}");
            Debug.Print($"Encoder counts= {sc.Sm.EncoderCounts}");
            Thread.Sleep(1000);
            Assert.AreEqual(sc.Sm.EncoderPosition, newPosition);
            Assert.AreEqual(sc.Sm.EncoderCounts, newCounts);
            Thread.Sleep(1000);
            sc.StopListening();

            sc.Dispose();
        }