Пример #1
0
 private void CleanupDevice()
 {
     if (_encoder != null)
     {
         _encoder.Dispose();
         _encoder = null;
     }
 }
Пример #2
0
 private void ConnectPB_Click(object sender, EventArgs e)
 {
     try
     {
         var wrappedSerialPort = new WrappedSerialPort((string) SerialPortsCB.SelectedItem, 115200, "Encoder Device");
         wrappedSerialPort.Diagnostics += OnDiagnostics;
         wrappedSerialPort.WriteTimeout = 250;
         _encoder = new EncoderDevice(wrappedSerialPort);
         _encoder.Orientate();
     }
     catch (Exception exception)
     {
         WriteMessage(exception.ToString());
     }
 }
Пример #3
0
        static void Main(string[] args)
        {
            var comPort = "";
            if (args.Count() < 1)
            {
                Console.WriteLine("Please pass in the com port");
                comPort = Console.ReadLine();
                comPort = comPort.Trim();
            }
            else
            {
                comPort = args[0];
            }
            WrappedSerialPort port = new WrappedSerialPort(comPort, 115200, "Encoder Device");
            port.Diagnostics += OnDiagnostics;

            EncoderDevice device = new EncoderDevice(port);
            var startDegrees = device.GetDegrees();

            Console.WriteLine("First measurement taken please turn the encoder 180 degrees, and press enter");
            Console.ReadLine();

            var endDegrees = device.GetDegrees();

            if (endDegrees == double.NegativeInfinity || startDegrees == double.NegativeInfinity)
            {
                Console.Out.WriteLine("Bad encoder");
                Console.ReadLine();
                return;
            }

            Console.Out.WriteLine(string.Format("First measurement {0:N2} Second {1:N2}", startDegrees, endDegrees));
            Console.Out.WriteLine("Encoder is good");

            Console.ReadLine();
        }