Exemplo n.º 1
0
 public EncoderDevice(WrappedSerialPort port)
 {
     _devicePort = port;
     _devicePort.Open();
     _devicePort.NewLine = "\r";
     if (orientateLaser)
     {
         Orientate();
         orientateLaser = false;
     }
 }
Exemplo n.º 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());
     }
 }
Exemplo n.º 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();
        }
Exemplo n.º 4
0
 public double GetTicks()
 {
     try
     {
         _devicePort.WriteLine(REQUEST_DEGREES);
         System.Threading.Thread.Sleep(100);
         string result = _devicePort.ReadExisting();
         if (result.Split(':').Length == 3)
         {
             //Success
             string ticks = result.Split(':')[0];
             double numberOfTicks = int.Parse(ticks, NumberStyles.AllowHexSpecifier);
             numberOfTicks += _tickOffset;
             return numberOfTicks;
         }
     }
     catch (System.IO.IOException exc)
     {
         try
         {
             //Location connection to the device
             if (_devicePort != null)
             {
                 _devicePort.Dispose();
                 _devicePort = null;
             }
         }
         catch (Exception e)
         {
             Console.Out.WriteLine("exc = {0}", e.ToString());
         }
     }
     catch (UnauthorizedAccessException exc)
     {
         try
         {
             //Location connection to the device
             if (_devicePort != null)
             {
                 _devicePort.Dispose();
                 _devicePort = null;
             }
         }
         catch (Exception e)
         {
             Console.Out.WriteLine("exc = {0}", e);
         }
     }
     catch (Exception exc)
     {
         try
         {
             //Location connection to the device
             if (_devicePort != null)
             {
                 _devicePort.Dispose();
                 _devicePort = null;
             }
         }
         catch (Exception e)
         {
             Console.Out.WriteLine("exc = {0}", e);
         }
     }
     return double.NegativeInfinity;
 }