createFromDeviceId method

Future<UsbPort> createFromDeviceId (int deviceId, [ String type = "", int interface = -1 ])

Creates a UsbPort from deviceId optionally type and interface. throws an error on failure. This function will pop up a permission request if needed. Note deviceId is only valid for the duration of a device being plugged in. Once unplugged and replugged this id changes.

type = One of UserSerial.CDC, UsbSerial.CH34x, UsbSerial.CP210x, UsbSerial.FTDI, UsbSerial.PL2303 or empty for auto detect. interface = Interface of the Usb Interface, -1 for auto detect.

Implementation

static Future<UsbPort> createFromDeviceId(int deviceId,
    [String type = "", int interface = -1]) async {
  String methodChannelName = await _channel.invokeMethod("create", {
    "type": type,
    "vid": -1,
    "pid": -1,
    "deviceId": deviceId,
    "interface": interface
  });

  if (methodChannelName == null) {
    return null;
  }

  return new UsbPort(methodChannelName);
}