/// <summary> /// Start the IR Server plugin. /// </summary> public override void Start() { IntPtr handle; TYPE_RET_VAL error; int context = 1; for (DEVICE_CAT cat = DEVICE_CAT.UNKNOWN; cat <= DEVICE_CAT.USB_2_DSS; cat++) { uint enumerate = bdaapiEnumerate(cat); for (uint index = 0; index < enumerate; index++) { handle = bdaapiOpen(cat, index); if ((handle != IntPtr.Zero) && (handle.ToInt32() != -1)) { error = bdaapiOpenIR(handle, _callbackPtr, context++); if (error == TYPE_RET_VAL.RET_SUCCESS) { _handles.Add(handle); } else { bdaapiClose(handle); } } } } if (_handles.Count == 0) { throw new InvalidOperationException("No Technotrend IR devices found"); } }
/// <summary> /// Detect the presence of this device. /// </summary> public override DetectionResult Detect() { IntPtr handle; TYPE_RET_VAL error; try { for (DEVICE_CAT cat = DEVICE_CAT.UNKNOWN; cat <= DEVICE_CAT.USB_2_DSS; cat++) { if (bdaapiEnumerate(cat) > 0) { handle = bdaapiOpen(cat, 0); try { if ((handle != IntPtr.Zero) && (handle.ToInt32() != -1)) { error = bdaapiOpenIR(handle, _callbackPtr, 0); bdaapiClose(handle); if (error == TYPE_RET_VAL.RET_SUCCESS) { return(DetectionResult.DevicePresent); } } } catch { bdaapiClose(handle); } } } } catch (Exception ex) { IrssLog.Error("{0,15}: exception {1}", Name, ex.Message); return(DetectionResult.DeviceException); } return(DetectionResult.DeviceNotFound); }
private static extern IntPtr bdaapiOpen(DEVICE_CAT deviceType, uint deviceId);
private static extern UInt32 bdaapiEnumerate(DEVICE_CAT deviceType);