private void handleDevice(ref LEAP_DEVICE_EVENT deviceMsg) { IntPtr deviceHandle = deviceMsg.device.handle; if (deviceHandle == IntPtr.Zero) { return; } LEAP_DEVICE_INFO deviceInfo = new LEAP_DEVICE_INFO(); eLeapRS result; IntPtr device; result = LeapC.OpenDevice(deviceMsg.device, out device); if (result != eLeapRS.eLeapRS_Success) { return; } deviceInfo.serial = IntPtr.Zero; deviceInfo.size = (uint)Marshal.SizeOf(deviceInfo); result = LeapC.GetDeviceInfo(device, ref deviceInfo); //Query the serial length if (result != eLeapRS.eLeapRS_Success) { return; } deviceInfo.serial = Marshal.AllocCoTaskMem((int)deviceInfo.serial_length); result = LeapC.GetDeviceInfo(device, ref deviceInfo); //Query the serial if (result == eLeapRS.eLeapRS_Success) { Device apiDevice = new Device(deviceHandle, device, deviceInfo.h_fov, //radians deviceInfo.v_fov, //radians deviceInfo.range / 1000.0f, //to mm deviceInfo.baseline / 1000.0f, //to mm (Device.DeviceType)deviceInfo.type, deviceInfo.status, Marshal.PtrToStringAnsi(deviceInfo.serial)); Marshal.FreeCoTaskMem(deviceInfo.serial); _devices.AddOrUpdate(apiDevice); if (LeapDevice != null) { LeapDevice.DispatchOnContext(this, EventContext, new DeviceEventArgs(apiDevice)); } } }
private void handleDevice(ref LEAP_DEVICE_EVENT deviceMsg) { IntPtr deviceHandle = deviceMsg.device.handle; if (deviceHandle == IntPtr.Zero) { return; } LEAP_DEVICE_INFO deviceInfo = new LEAP_DEVICE_INFO(); eLeapRS result; IntPtr device; result = LeapC.OpenDevice(deviceMsg.device, out device); uint defaultLength = 14; deviceInfo.serial_length = defaultLength; deviceInfo.serial = Marshal.AllocCoTaskMem((int)defaultLength); deviceInfo.size = (uint)Marshal.SizeOf(deviceInfo); result = LeapC.GetDeviceInfo(device, out deviceInfo); if (result == eLeapRS.eLeapRS_InsufficientBuffer) { Marshal.FreeCoTaskMem(deviceInfo.serial); deviceInfo.serial = Marshal.AllocCoTaskMem((int)deviceInfo.serial_length); deviceInfo.size = (uint)Marshal.SizeOf(deviceInfo); result = LeapC.GetDeviceInfo(deviceHandle, out deviceInfo); } if (result == eLeapRS.eLeapRS_Success) { Device apiDevice = new Device(deviceHandle, deviceInfo.h_fov, //radians deviceInfo.v_fov, //radians deviceInfo.range / 1000, //to mm deviceInfo.baseline / 1000, //to mm (deviceInfo.caps == (UInt32)eLeapDeviceCaps.eLeapDeviceCaps_Embedded), (deviceInfo.status == (UInt32)eLeapDeviceStatus.eLeapDeviceStatus_Streaming), Marshal.PtrToStringAnsi(deviceInfo.serial)); Marshal.FreeCoTaskMem(deviceInfo.serial); _devices.AddOrUpdate(apiDevice); this.LeapDevice.Dispatch(this, new DeviceEventArgs(apiDevice)); } }