FengChendian / serial_port_win32

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

The resulting data is divided into several segments #29

Open 7571deng opened 10 months ago

7571deng commented 10 months ago

企业微信截图_321852b0-68b3-4ad8-a949-a998f0fb17c1

FengChendian commented 10 months ago

No \0 in your string. It's possible to truncate your string due to windows API. And the API is designed that it will return the read data when win32 function returns the sending is complete (Maybe I/O just delay). So readBytesSize may be less than bytesSize.

You can increase dataPollingInterval to wait data io is complete.

Or use readBytesUntil function. The function waits flag string in endless loop;

ReadIntervalTimeout is useful for this problem. https://learn.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-commtimeouts

  void readBytesOnListen(int bytesSize, Function(Uint8List value) onData,
      {void onBefore()?,
      Duration dataPollingInterval = const Duration(microseconds: 500)})

I think I should add wait until bytesSize is ready parameter to fix this problem in readBytesOnListen. I will publish the change in next version.