public void Disconnect()
        {
            if (connection != null)
            {
                try
                {
                    connection.ConnectionEstablished -= OnDeviceReady;
                    connection.ConnectionFailed      -= OnConnectionFailed;
                    connection.end();
                }
                catch (SEHException)
                {
                }
            }

            if (arduino != null)
            {
                EnableAnalogCallback(false);
                EnableDigitalCallback(false);
                arduino.Dispose();
            }

            connection = null;
            arduino    = null;
        }
Exemple #2
0
 public async Task <bool> Disconnect()
 {
     if (_arduino != null)
     {
         _arduino.analogWrite(_servoPin, _servoOff);
         await Task.Delay(_pressTime);
     }
     _connection?.end();
     _arduino?.Dispose();
     _connection?.Dispose();
     return(true);
 }
Exemple #3
0
 private void MainPage_Unloaded(object sender, RoutedEventArgs e)
 {
     arduino.Dispose();
 }
Exemple #4
0
		/// <summary>
		/// Invoked when application execution is being suspended.  Application state is saved
		/// without knowing whether the application will be terminated or resumed with the contents
		/// of memory still intact.
		/// </summary>
		/// <param name="sender">The source of the suspend request.</param>
		/// <param name="e">Details about the suspend request.</param>
		private void OnSuspending(object sender, SuspendingEventArgs e)
		{
			var deferral = e.SuspendingOperation.GetDeferral();

			if (arduino != null)
			{
				arduino.digitalWrite(13, PinState.LOW);
				arduino.pinMode(13, PinMode.INPUT);    // Onboard LED.

				arduino.Dispose();
				arduino = null;
			}

			if (arduinoUsb != null)
			{
				arduinoUsb.end();
				arduinoUsb.Dispose();
				arduinoUsb = null;
			}

			if (gpioPins != null)
			{
				foreach (KeyValuePair<GpioPin, KeyValuePair<TextBlock, TextBlock>> Pin in gpioPins.Values)
					Pin.Key.Dispose();

				gpioPins = null;
			}

			if (this.sampleTimer != null)
			{
				this.sampleTimer.Dispose();
				this.sampleTimer = null;
			}

			if (this.chatServer != null)
			{
				this.chatServer.Dispose();
				this.chatServer = null;
			}

			if (this.bobClient != null)
			{
				this.bobClient.Dispose();
				this.bobClient = null;
			}

			if (this.controlServer != null)
			{
				this.controlServer.Dispose();
				this.controlServer = null;
			}

			if (this.sensorServer != null)
			{
				this.sensorServer.Dispose();
				this.sensorServer = null;
			}

			if (this.provisioningClient != null)
			{
				this.provisioningClient.Dispose();
				this.provisioningClient = null;
			}

			if (this.thingRegistryClient != null)
			{
				this.thingRegistryClient.Dispose();
				this.thingRegistryClient = null;
			}

			if (this.xmppClient != null)
			{
				this.xmppClient.Dispose();
				this.xmppClient = null;
			}

			Log.Terminate();

			deferral.Complete();
		}
Exemple #5
0
 public void Disconnect()
 {
     arduino.Dispose();
     usb.end();
 }