altera2015 / usbserial

Flutter Android USB Serial plugin
BSD 3-Clause "New" or "Revised" License
119 stars 83 forks source link

Write files in pendrive #99

Closed Bestfastfire closed 2 days ago

Bestfastfire commented 6 months ago

Is it possible to use this lib to save files to a pendrive?

I tried doing this:

    final bytes = <int>[];

    await yt.videos.streamsClient.get(audioStream).listen((chunk) {
      bytesReceived += chunk.length;
      bytes.addAll(chunk);

    }, onDone: () async{
      MyLog.log('Done onDone');

    }, onError: (error) async{
      MyLog.log('Done error: $error');

    }).asFuture();

    final devices = await UsbSerial.listDevices();
    final port = await devices.first.create();
    final openResult = await port?.open();

    if ( !(openResult ?? false)) {
      MyLog.log("Failed to open");
      return;

    }

    port?.inputStream?.listen((Uint8List event) {
      MyLog.log('Event close');
      port.close();
    });

    await port?.write(Uint8List.fromList(bytes));

But I get the error:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(UsbSerialPortAdapter, Not an Serial device., null, null)

rockerer commented 5 months ago

Hi, what exactly are you trying to achieve? What system are you working on (android / ios / web / linux / ...)

If the device you want to write to is mounted, the package path_provider might be a better choice.

If you really want to use this package, you would have to handle all the low level stuff, which is normally done by the operating system.

Bestfastfire commented 5 months ago

Hi, what exactly are you trying to achieve? What system are you working on (android / ios / web / linux / ...)

If the device you want to write to is mounted, the package path_provider might be a better choice.

If you really want to use this package, you would have to handle all the low level stuff, which is normally done by the operating system.

No, path provider dont returning external directories: https://stackoverflow.com/questions/77739716/write-file-in-flash-drive-android-only

rockerer commented 5 months ago

To give your users the possibility to choose the location file_picker is another idea.

Bestfastfire commented 5 months ago

To give your users the possibility to choose the location file_picker is another idea.

It's not working either lol, I explained it better on stack overflow, but in file_picker, when you select the path inside the pendrive it only returns "/"

altera2015 commented 2 days ago

This doesn't sound like a supported serial device.