unsafe public static List <DeviceInfo> GetDeviceList() { int deviceCount = -1; OniDeviceInfo *deviceList = (OniDeviceInfo *)IntPtr.Zero; OniStatus status = oniGetDeviceList(&deviceList, ref deviceCount); HandleError(status); List <DeviceInfo> list = new List <DeviceInfo>(); for (int i = 0; i < deviceCount; i++) { DeviceInfo tmpInfo = new DeviceInfo(); OniDeviceInfo deviceInfo = deviceList[i]; tmpInfo.uri = Marshal.PtrToStringAnsi((IntPtr)deviceInfo.uri); tmpInfo.name = Marshal.PtrToStringAnsi((IntPtr)deviceInfo.name); tmpInfo.vendor = Marshal.PtrToStringAnsi((IntPtr)deviceInfo.vendor); tmpInfo.usbProductId = deviceInfo.usbProductId; tmpInfo.usbVendorId = deviceInfo.usbVendorId; list.Add(tmpInfo); } oniReleaseDeviceList((IntPtr)deviceList); return(list); }
public static void ThrowExectionIfStatusIsNotOk(this OniStatus status) { switch (status) { case OniStatus.ONI_STATUS_OK: return; case OniStatus.ONI_STATUS_NOT_IMPLEMENTED: throw new NotImplementedException(); case OniStatus.ONI_STATUS_NOT_SUPPORTED: throw new NotSupportedException(); case OniStatus.ONI_STATUS_ERROR: case OniStatus.ONI_STATUS_BAD_PARAMETER: case OniStatus.ONI_STATUS_OUT_OF_FLOW: case OniStatus.ONI_STATUS_NO_DEVICE: var message = OpenNI.GetExtendedError(); throw new OpenNIException(message); case OniStatus.ONI_STATUS_TIME_OUT: throw new TimeoutException(); default: throw new ArgumentOutOfRangeException("status", string.Format("Unkown status :{0}.", status)); } }
unsafe public static Frame ReadFrame(Stream stream) { OniFrame *frameHandle = (OniFrame *)IntPtr.Zero; OniStatus status = oniStreamReadFrame(stream.Handle, &frameHandle); HandleError(status); return(new Frame((IntPtr)frameHandle)); }
unsafe public static Stream CreateStream(Device dev, OniSensorType type) { IntPtr streamHandle = IntPtr.Zero; OniStatus status = oniDeviceCreateStream(dev.Handle, type, &streamHandle); HandleError(status); return(new Stream(streamHandle)); }
unsafe public static Device OpenDevice(string URI) { IntPtr deviceHandle = IntPtr.Zero; OniStatus status = oniDeviceOpen(URI, &deviceHandle); HandleError(status); return(new Device(deviceHandle)); }
unsafe private static void HandleError(OniStatus status) { if (status == OniStatus.OK) { return; } char * msg = oniGetExtendedError(); string errorMsg = Marshal.PtrToStringAnsi((IntPtr)msg); throw new Exception(errorMsg); }
unsafe public static void StartStream(Stream stream) { OniStatus status = oniStreamStart(stream.Handle); HandleError(status); }
public static void Init() { OniStatus status = oniInitialize(ONI_API_VERSION); HandleError(status); }