Ejemplo n.º 1
0
        // Disconnects from the Pololu Maestro servo controller.
        // Based on the 'TryToDisconnect' method from MaestroAdvancedExample in the pololu-usb-sdk.
        public void DisconnectFromHardware()
        {
            lock (uscLock)
            {
                if (uscDevice == null)
                {
                    // Already disconnected
                    return;
                }

                try
                {
                    uscDevice.Dispose();  // Disconnect
                }
                catch (Exception ex)
                {
                    ErrorLogging.AddMessage(ErrorLogging.LoggingLevel.Error, "DisconnectFromHardware failed to cleaning disconnect the servo hardware: " + ex.Message);
                }
                finally
                {
                    // do this no matter what
                    uscDevice = null;
                }
            }
        }
        /// <summary>
        /// Attempts to disconnect
        /// </summary>
        public void TryToDisconnect()
        {
            if (usc == null)
            {
                //Log("Connecting stopped.");
                return;
            }

            try
            {
                //Log("Disconnecting...");
                usc.Dispose();  // Disconnect
            }
            catch (Exception e)
            {
                //Log(e);
                //Log("Failed to disconnect cleanly.");
            }
            finally
            {
                // do this no matter what
                usc = null;
                //Log("Disconnected from #" + SerialNumberTextBox.Text + ".");
            }
        }