Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Commit

Permalink
Look up device address instead of enumerating all devices
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorMcKay committed Nov 3, 2018
1 parent 959cd3e commit 51c1787
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions HSPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,21 +315,13 @@ private async void syncDevices() {
int devRef = 0;
if (!serialToRef.TryGetValue(dev.DeviceSerialNumber, out devRef)) {
// We need to look it up in HS3, and maybe create the device
var enumerator = (clsDeviceEnumeration) hs.GetDeviceEnumerator();
do {
DeviceClass enumDev = enumerator.GetNext();
if (enumDev == null) {
break;
}

if (enumDev.get_Address(hs).Split('-')[0] == dev.DeviceSerialNumber && enumDev.get_Interface(hs) == Name) {
// found it!
devRef = enumDev.get_Ref(hs);
Program.WriteLog("Debug", "Found existing device for GDO " + dev.DeviceSerialNumber + " with ref " + devRef);
serialToRef.Add(dev.DeviceSerialNumber, devRef);
break;
}
} while (!enumerator.Finished);
devRef = hs.DeviceExistsAddress(dev.DeviceSerialNumber, false);
if (devRef == -1) {
devRef = 0;
} else {
Program.WriteLog("Debug", "Found existing device for GDO " + dev.DeviceSerialNumber + " with ref " + devRef);
serialToRef.Add(dev.DeviceSerialNumber, devRef);
}

if (devRef == 0) {
Program.WriteLog("Debug", "Creating new device in HS3 for GDO serial " + dev.DeviceSerialNumber);
Expand Down

0 comments on commit 51c1787

Please sign in to comment.