felHR85 / UsbSerial

Usb serial controller for Android
MIT License
1.8k stars 585 forks source link

Write for async write function finishes #238

Open efreibe opened 5 years ago

efreibe commented 5 years ago

Hello,

I'm trying to open the usb port, send data and close it. But I realized that not all the data is transferred to destination.

I suspect that I send a close command while the driver is writing and my data is truncated.

How can I listen to know when all buffer was totally written to the port?

Thank you

felHR85 commented 5 years ago

Hi @efreibe I would use the synchronous api in your case

efreibe commented 5 years ago

Yes, I'm doing that, I've created a thread and I'm making calls to syncWrite

I simply created the issue because it will be helpful for other people making async requests to get a notification when the write operation is done.

I'm using flutter and the easy way to send a success message back to the channel is waiting for a notification from write async method. But I managed to do it in other way.

You can close it, it's not a blocking issue.

felHR85 commented 5 years ago

@efreibe Like a JS promise with "then" added at the end to handle the result of the operation? I guess it could be added because it is a nice idea.

efreibe commented 5 years ago

Good to hear that. It will give more control to the write process.