FengChendian / serial_port_win32

A flutter SerialPort library using win32 API.
BSD 3-Clause "New" or "Revised" License
31 stars 9 forks source link

readBytesOnListen() split received message #37

Closed bobosette closed 3 weeks ago

bobosette commented 1 month ago

Hi everybody. I don't know if I am wrong and where I am wrong, but I use readBytesOnListen() to read data from a serial port and I don't receive the whole message in one time, but splitted into several times. I don't know Cattura If it is the expected behaviour, in my thoughts I should receive the whole message in one time as an Uint8List list (as you can see in the image, I would like to receive the word hello in one time, not splitted). I'm pretty sure that is related to a port configuration problem. My code:

` //open port selectedPort!.openWithSettings( BaudRate: 115200, );

    selectedPort!.readBytesOnListen(1024, (value) {
      String data = String.fromCharCodes(value);

      setResponse(data);
    });

`

Someone can help me? Thanks

FengChendian commented 1 month ago

It is the expected behaviour. The device sends data bytes one by one. So, if some bytes are delayed or vanished by accident, you may get a part of data in async read mode.

But you are right, the API should implement a function which will read bytes until required size

FengChendian commented 3 weeks ago

In version 2.0.0, now has APIs:

It should provide flexible timeout control and read size control. image