Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix several issue with connect/disconnect workflow #71

Merged
merged 1 commit into from
Oct 30, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ private async void AddDeviceToList(DeviceInformation deviceInformation, String d
newNanoFrameworkDevice.DebugEngine = new Engine(this, newNanoFrameworkDevice);
newNanoFrameworkDevice.Transport = TransportType.Serial;

tentativeNanoFrameworkDevices.Add(newNanoFrameworkDevice as NanoDeviceBase);

// perform check for valid nanoFramework device is this is not the initial enumeration
if (IsDevicesEnumerationComplete)
{
Expand All @@ -262,19 +264,20 @@ private async void AddDeviceToList(DeviceInformation deviceInformation, String d
NanoFrameworkDevices.Add(newNanoFrameworkDevice as NanoDeviceBase);
Debug.WriteLine($"New Serial device: {newNanoFrameworkDevice.Description} {(((NanoDevice<NanoSerialDevice>)newNanoFrameworkDevice).Device.DeviceInformation.DeviceInformation.Id)}");

// clear tentative list
tentativeNanoFrameworkDevices.Clear();

// done here
return;
}
}

Debug.WriteLine($"Removing { deviceInformation.Id } from collection...");
// clear tentative list
tentativeNanoFrameworkDevices.Clear();

// can't do anything with this one, better dispose it
newNanoFrameworkDevice.Dispose();
}
else
{
tentativeNanoFrameworkDevices.Add(newNanoFrameworkDevice as NanoDeviceBase);
}
}
}
}
Expand All @@ -288,9 +291,10 @@ private void RemoveDeviceFromList(string deviceId)

SerialDevices.Remove(deviceEntry);

// get device
// get device...
var device = FindNanoFrameworkDevice(deviceId);
// yes, remove it from collection

// ... and remove it from collection
NanoFrameworkDevices.Remove(device);

device = null;
Expand Down Expand Up @@ -335,6 +339,10 @@ private NanoDeviceBase FindNanoFrameworkDevice(string deviceId)
// try now in tentative list
return tentativeNanoFrameworkDevices.FirstOrDefault(d => ((d as NanoDevice<NanoSerialDevice>).Device.DeviceInformation as SerialDeviceInformation).DeviceInformation.Id == deviceId);
}
else
{
return device;
}
}

return null;
Expand Down Expand Up @@ -403,6 +411,9 @@ private void OnDeviceEnumerationComplete(DeviceWatcher sender, object args)
// all watchers have completed enumeration
IsDevicesEnumerationComplete = true;

// clean list of tentative nanoFramework Devices
tentativeNanoFrameworkDevices.Clear();

Debug.WriteLine($"Serial device enumeration completed. Found {NanoFrameworkDevices.Count} devices");

// fire event that Serial enumeration is complete
Expand Down Expand Up @@ -455,10 +466,14 @@ private async Task<bool> CheckValidNanoFrameworkSerialDeviceAsync()
if (serialNumber.Contains("NANO_"))
{
var device = FindNanoFrameworkDevice(EventHandlerForSerialDevice.Current.DeviceInformation.Id);
device.Description = serialNumber + " @ " + EventHandlerForSerialDevice.Current.Device.PortName;

// should be a valid nanoFramework device, done here
return true;
if (device != null)
{
device.Description = serialNumber + " @ " + EventHandlerForSerialDevice.Current.Device.PortName;

// should be a valid nanoFramework device, done here
return true;
}
}
}

Expand Down