Skip to content

Commit cd19cf7

Browse files
committed
fixes issue with manually created netDevices not being started
1 parent a357001 commit cd19cf7

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

src/Acquisition.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ namespace VL.Devices.Orbbec
1717
{
1818
internal class Acquisition : IVideoPlayer
1919
{
20-
public static Acquisition? Start(VideoIn videoIn, Advanced.DeviceInfo deviceInfo, ILogger logger, Int2 resolution, int fps)//, IConfiguration? configuration)
20+
public static Acquisition? Start(VideoIn videoIn, Device device, ILogger logger, Int2 resolution, int fps)//, IConfiguration? configuration)
2121
{
22+
var deviceInfo = device.GetDeviceInfo();
2223
logger.Log(LogLevel.Information, "Starting image acquisition on {device}", deviceInfo.SerialNumber);
2324

24-
var contextHandle = ContextManager.GetHandle();
25-
26-
Device device = contextHandle.Resource.QueryDeviceList().GetDeviceBySN(deviceInfo.SerialNumber);
2725
Pipeline pipe = new Pipeline(device);
2826

2927
/*SensorList s = device.GetSensorList();
@@ -69,6 +67,7 @@ internal class Acquisition : IVideoPlayer
6967
return null;
7068
}
7169

70+
var contextHandle = ContextManager.GetHandle();
7271
return new Acquisition(contextHandle, logger, pipe, resolution, videoIn);
7372
}
7473

src/Advanced/OrbbecDevice.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,16 @@ protected override IReadOnlyDictionary<string, object> GetEntries()
137137
}
138138

139139
//Optionally trigger addedList change of your enum. This will in turn call GetEntries() again
140-
protected override IObservable<object> GetEntriesChangedObservable() => _devicesChanged;
141-
142-
//Optionally disable alphabetic sorting
140+
protected override IObservable<object> GetEntriesChangedObservable() => _devicesChanged;
141+
142+
internal Device? GetDeviceBySN(string serialNumber)
143+
{
144+
foreach (var netDevice in _netDevices)
145+
if (netDevice.Value.GetDeviceInfo().SerialNumber() == serialNumber)
146+
return netDevice.Value;
147+
return null;
148+
}
149+
150+
//Optionally disable alphabetic sorting
143151
protected override bool AutoSortAlphabetically => false; //true is the default
144152
}

src/VideoIn.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class VideoIn : IVideoSource2, IDisposable
1717
private readonly BehaviorSubject<Acquisition?> _aquicitionStarted = new BehaviorSubject<Acquisition?>(null);
1818

1919
private int _changedTicket;
20-
private Advanced.DeviceInfo? _device;
20+
private Advanced.DeviceInfo? _deviceInfo;
2121
private Int2 _resolution;
2222
private int _fps;
2323
//private IConfiguration? _configuration;
@@ -43,9 +43,9 @@ public VideoIn([Pin(Visibility = PinVisibility.Hidden)] NodeContext nodeContext)
4343
out string Info)
4444
{
4545
// By comparing the device info we can be sure that on re-connect of the device we see the change
46-
if (!Equals(device?.Tag, _device) || enabled != _enabled || resolution != _resolution || FPS != _fps)// || configuration != _configuration)
46+
if (!Equals(device?.Tag, _deviceInfo) || enabled != _enabled || resolution != _resolution || FPS != _fps)// || configuration != _configuration)
4747
{
48-
_device = device?.Tag as Advanced.DeviceInfo;
48+
_deviceInfo = device?.Tag as Advanced.DeviceInfo;
4949
_resolution = resolution;
5050
_fps = FPS;
5151
//_configuration = configuration;
@@ -64,12 +64,17 @@ public VideoIn([Pin(Visibility = PinVisibility.Hidden)] NodeContext nodeContext)
6464

6565
IVideoPlayer? IVideoSource2.Start(VideoPlaybackContext ctx)
6666
{
67-
var device = _device;
68-
if (device is null)
67+
var deviceInfo = _deviceInfo;
68+
if (deviceInfo is null)
6969
return null;
7070

7171
try
7272
{
73+
//get the device either from the list of auto-enumerated devices
74+
Device? device = ContextManager.GetHandle().Resource.QueryDeviceList().GetDeviceBySN(deviceInfo.SerialNumber);
75+
//or from the manually created list of NetDevices
76+
if (device == null)
77+
device = OrbbecDeviceDefinition.Instance.GetDeviceBySN(deviceInfo.SerialNumber);
7378
var result = Acquisition.Start(this, device, _logger, _resolution, _fps);//, _configuration
7479
//_aquicitionStarted.OnNext(result);
7580
return result;

0 commit comments

Comments
 (0)