hidOpenPath function

HidDevice hidOpenPath(
  1. String path
)

Open a HID device by its platform-specific path.

The path is obtained from HidDeviceInfo.path via hidEnumerate. Throws HidException on failure.

Implementation

HidDevice hidOpenPath(String path) {
  final pathPtr = path.toNativeUtf8().cast<Char>();
  try {
    final dev = ffi.hid_open_path(pathPtr);
    if (dev == nullptr) {
      final errPtr = ffi.hid_error(nullptr);
      final msg = errPtr != nullptr && errPtr != nullptr
          ? errPtr.cast<Utf16>().toDartString()
          : 'Failed to open device';
      throw HidException(msg);
    }
    return HidDevice._(dev);
  } finally {
    calloc.free(pathPtr);
  }
}